setservent, getservent, endservent
Prototype:
#include <netdb.h>
void setservent(int stayopen);
struct servent *getservent();
void endservent(void);
General Description: These functions let you open and read the /etc/services file line by line. The setservent call opens the file. Each call to getservent gets the next line from the file. Calling endservent closes the file.
Return Value: The call returns a pointer to servent (defined below) if successful. Otherwise, it returns a NULL.
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 field p_proto is the protocol number you should use with the service. The s_port field is already in network-byte order.
Parameters
stayopen If true, the file is not closed between other servent calls.
Possible Errors
(errno not set)
Examples
#include <netdb.h>
int i;
struct servent *s;
setservent(0);
while ( (s = getservent()) != NULL )
{
   printf("%s %d %s ", s->s_name, ntohs(s->s_port), s->s_proto);
   for ( i = 0; s->s_aliases[i] != 0; i++ )
      printf("%s ", s->s_aliases[i]);
   printf("\n");
}
endservent();