#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);
getservent reads the next entry in the database and opens a connection to the database if necessary.
getservbyname searches the database from the beginning and finds
the first entry for which the service name specified by name
matches the s_name
member and the protocol name specified by
proto matches the s_proto
member.
A connection to the database is opened if necessary.
If proto is a null value, any value of s_proto
will be
matched.
getservbyport searches the data base from the beginning and finds
the first entry for which the port specified by port matches the
s_port
member.
A connection to the database is opened if necessary.
If proto is a null value, any value of s_proto
will be
matched.
port must be in network byte order.
setservent opens a connection to the database, and sets the next entry to the first entry. If stayopen is non-zero, the net database will not be closed after each call to getservent.
endservent closes the database.
The servent structure includes the following members:
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:
s_name
s_aliases
s_port
s_proto
getservent, getservbyname and getservbyport may return pointers to static data, which may be overwritten by subsequent calls to any of these functions.
These functions are generally used with the Internet address family.
Functions that provide successive entries in files on successive calls must be called from a single thread.
These functions use the name-to-address resolution mechanism described in netdir(3N) and netconfig(4bnu). This mechanism may use a local database or the services of Network Information Service (NIS) or Domain Name Service (DNS).