HP Rp7410 BSD Sockets Interface Programmer's Guide - Page 33
Getting the Port Address for the Desired, Service
View all HP Rp7410 manuals
Add to My Manuals
Save this manual to your list of manuals |
Page 33 highlights
Using Internet Stream Sockets Preparing Address Variables #include struct hostent *hp; /* pointer to host info for remote host */ ... peeraddr.sin_family = AF_INET; hp = gethostbyname (argv[1]); peeraddr_in.sin_addr.s_addr = ((struct in_addr *)(hp->h_addr))->s_addr; The argv[1] parameter is the host name specified in the client program command line. Refer to the gethostent(3n) man page for more information on gethostbyname. Getting the Port Address for the Desired Service When a server process is preparing to offer a service, it must get the port address for the service from /etc/services so it can bind that address to its "listen" socket. If the service is not already in /etc/services, you must add it. When a client process needs to use a service that is offered by some server process, it must request a connection to that server process's "listening" socket. The client process must know the port address for that socket. getservbyname obtains the port address of the specified service from /etc/services. getservbyname and its parameters are described in the following table. Include files: System call: #include struct servent *getservbyname(name, proto) char *name, *proto; Parameter Description of Contents INPUT Value name proto pointer to a valid service name pointer to the protocol to be used service name tcp or 0 if TCP is the only protocol for the service Function result: pointer to struct servent containing port address NULL, pointer (0) if failure occurs. Example: Chapter 2 33