DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
Developing applications over TCP/IP using Internet sockets

Mapping service names (Internet domain)

Service names are a bit more complex. A service is expected to reside at a specific ``port'' and employ 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 or support multiple protocols. If either of these occurs, the higher level library routines will have to be bypassed in favor of homegrown routines similar to the gethostbynameandnet routine.

A service mapping is described by the servent structure:

struct  servent {
        char        *s_name;
        char       **s_aliases;
        int          s_port;
        char        *s_proto;
        }

*s_name
is the official service name

**s_aliases
is the alias list.

s_port
is the port number.

*s_proto
is the protocol to use

The routine getservbyname(SLIB) maps service names to a servent structure by specifying a service name and, optionally, a qualifying protocol. Thus, to return the service specification for a telnet server using any protocol:
   sp = getservbyname("telnet", (char *)0);
To return only that telnet server which uses the TCP protocol:
   sp = getservbyname("telnet", "tcp");

The routines getservbyport(SLIB) and getservent(SLIB) 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.


Next topic: Handling network dependencies (Internet domain)
Previous topic: Mapping protocol names (Internet domain)

© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003