getservbyport(), getservbyname(), getservent(), setservent(), endservent() - get service entry
#include <netdb.h>
struct servent *getservent(void)
struct servent *getservbyname (char *name, const char *proto)
struct servent *getservbyport (int port, const char *proto)
void setservent (int stayopen)
void endservent (void)
The getservent(2), getservbyname(2) and getservbyport(2) functions each return a pointer to an object with the following structure containing the information from a network services database.
struct servent {
char * s_name; /* official name of service */
char ** s_aliases; /* alias list */
int s_port; /* port service resides at */
char * s_proto; /* protocol to use
};
The members of this structure are:
The getservent(2) function reads the next line of the file, opening the file if necessary.
The setservent(2) and endservent(2) functions are no-ops, provided for portability.
The getservbyname(2) and getservbyport(2) functions return information from a matching protocol name or port number. If a protocol name is also supplied (proto is non-NULL), searches must also match the protocol.
These functions use static data storage; if the data is needed for future use, it should be copied before any subsequent calls overwrite it.
Returns NULL pointer on end of file (EOF) or error.
These functions make use of the following files:
getprotoent(2)