Service Names – servent
An Internet family 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 that is
defined in getprotoent
():
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 */ };
getservbyname
(3C) maps service names and, optionally, a qualifying
protocol to a servent
structure. The following
call returns the service specification of an SSH server that is using
any protocol.
sp = getservbyname("ssh", (char *) 0);
The following call returns the SSH server that uses the TCP protocol.
sp = getservbyname("ssh", "tcp");
getservbyport
()
and
getservent
()
are also provided.
getservbyport
()
has an interface that is similar to
the interface used by getservbyname
(). You can
specify an optional protocol name to qualify lookups For more
information, see the
getservbyname
(3C),
getservbyport
(3C), and
getservent
(3C) man pages.