The getservent() call returns a pointer to the next entry in the ETC\SERVICES file.
Syntax
#include <netdb.h> struct servent *getservent()
Description
This call searches for the next line in the ETC\SERVICES file. An application program can use the getservent() call to retrieve information about network services and the protocol ports they use.
The getservent() call returns a pointer to a servent structure, which contains fields for a line of information from the ETC\SERVICES file. The servent structure is defined in the <NETDB.H> file.
The ETC\SERVICES file remains open after a call by getservent(). To close the ETC\SERVICES file after each call, use setservent(). Otherwise, use endservent() to close the file.
Return Values
The getservent() call returns a pointer to the next entry in the ETC\SERVICES file. The return value points to static data that subsequent API calls can modify. A pointer to a servent structure indicates success. A NULL pointer indicates an error or EOF.
The servent structure is defined in the <NETDB.H> header file and contains the following elements:
Element
Related Calls
endprotoent() endservent()
getprotobyname()
getprotobynumber()
getprotoent()
getservbyname()
getservbyport()
setprotoent()
setservent()