|
|
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
**s_aliases
s_port
*s_proto
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.