Transport Interfaces Programming Guide

Service Names

An Internet domain service resides at a specific, well-known port and uses a particular protocol. A service-name-to-port-number mapping is described by the servent structure:


struct serven
   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 */
};

getservbyname() maps service names and, optionally, a qualifying protocol to a servent structure. The call:


sp = getservbyname("telnet", (char *) 0);

returns the service specification of a telnet server using any protocol. The call:


sp = getservbyname("telnet", "tcp");

returns the telnet server that uses the TCP protocol. getservbyport() and getservent() are also provided. getservbyport() has an interface similar to that of getservbyname(); an optional protocol name can be specified to qualify lookups.