#include <netdb.h> struct servent *getservent(void); struct servent *getservbyname(const char *name, const char *proto); struct servent *getservbyport(int port, const char *proto); void setservent(int stayopen); void endservent(void);
The getservbyname() function returns a servent structure for the line from /etc/services that matches the service name using protocol proto.
The getservbyport() function returns a servent structure for the line that matches the port port given in network byte order using protocol proto.
The setservent() function opens and rewinds the /etc/services file. If stayopen is true (1), then the file will not be closed between calls to getservbyname() and getservbyport().
The endservent() function closes /etc/services.
The servent structure is defined in <netdb.h> as follows:
struct servent { char *s_name; /* official service name */ char **s_aliases; /* alias list */ int s_port; /* port number */ char *s_proto; /* protocol to use */ }
The members of the servent structure are: