Node:Services Database, Next:Byte Order, Previous:Ports, Up:Internet Namespace
The database that keeps track of "well-known" services is usually
either the file /etc/services
or an equivalent from a name server.
You can use these utilities, declared in netdb.h
, to access
the services database.
struct servent | Data Type |
This data type holds information about entries from the services database.
It has the following members:
|
To get information about a particular service, use the
getservbyname
or getservbyport
functions. The information
is returned in a statically-allocated structure; you must copy the
information if you need to save it across calls.
struct servent * getservbyname (const char *name, const char *proto) | Function |
The getservbyname function returns information about the
service named name using protocol proto. If it can't find
such a service, it returns a null pointer.
This function is useful for servers as well as for clients; servers use it to determine which port they should listen on (see Listening). |
struct servent * getservbyport (int port, const char *proto) | Function |
The getservbyport function returns information about the
service at port port using protocol proto. If it can't
find such a service, it returns a null pointer.
|
You can also scan the services database using setservent
,
getservent
and endservent
. Be careful when using these
functions because they are not reentrant.
void setservent (int stayopen) | Function |
This function opens the services database to begin scanning it.
If the stayopen argument is nonzero, this sets a flag so that
subsequent calls to |
struct servent * getservent (void) | Function |
This function returns the next entry in the services database. If there are no more entries, it returns a null pointer. |
void endservent (void) | Function |
This function closes the services database. |