DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
Programming with sockets

Service names

Information regarding services is a bit more complicated. A service is expected to reside at a specific port and use a particular communication protocol. This view is consistent with the Internet domain, but inconsistent with other network architectures. Further, a service may reside on multiple ports. If this occurs, the higher level library routines will have to be bypassed or extended.

A service mapping is described by the servent structure:

   struct servent {
        char *s_name;          /* official service name */
        char **s_aliases;      /* alias list */
        int  s_port;           /* port number, network byte order */
        char *s_proto;         /* protocol to use */
   };
The routine getservbyname maps service names to a servent structure by specifying a service name and, optionally, a qualifying protocol. Thus the call
   sp = getservbyname("telnet", (char *) 0);
returns the service specification for a telnet server using any protocol, while the call
   sp = getservbyname("telnet", "tcp");
returns only that telnet server that uses the TCP protocol. The routines getservbyport and getservent(S) are also provided. The getservbyport routine has an interface similar to that provided by getservbyname; an optional protocol name may be specified to qualify lookups.
© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 -- 02 June 2005