Home > other >  Socket programming getservbyname parameter name is fixed in the service of the or can be customized?
Socket programming getservbyname parameter name is fixed in the service of the or can be customized?

Time:10-02

Socket programming getservbyname parameter name is fixed in the service of the or can be customized? Please answer
Int main (int arg c, char * argv [])
{
Struct sockaddr_in fsin;
Char * service="daytime";//the daytime here after I change in the error getservbyname there
The SOCKET msock ssock;
Int alen.
WSADATA WSADATA;
Int QLEN;

The switch (arg c)
{
Case 1:
break;
Case 2:
Service=argv [1].
break;
Default:
Usage: TCPdaytime errexit (" [port] \ n ");
}

}//this is the main function in a

Void TCPdaytimed (SOCKET fd)
{
Char * PTS;
Time_t now;
(void) time (& amp; Now);
PTS="hello! \ n ";
(void) send (fd, PTS, strlen (PTS), 0).
(void) closesocket (fd);
}//it is after the accept services

If (pse=getservbyname (service, transport))
Sin. The sin_port=(u_short) pse - & gt; S_port;
Else if ((sin. Sin_port=htons ((u_short) atoi (service)))==0)
Errexit (" can 't get \ \ "% s" service entry \ n ", service);
//service parameters changed after prompt else if the back of the error

CodePudding user response:

Under Linux man getservbyname everything is known, speculation should be similar to Windows,
The getservbyname () function returns a servent structure for The entry from The database that matches The service name using protocol proto. If proto is NULL, any proto -
Col will be matched. A connection is the opened to the database if necessary.
S_name The official name of The service.
FILES
/etc/services
Services database file
  • Related