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.
To get information about a particular service, use the
getservbyport functions. The information
is returned in a statically-allocated structure; you must copy the
information if you need to save it across calls.
getservbynamefunction 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 section Listening for Connections).
getservbyportfunction 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
endservent. Be careful in using these
functions, because they are not reentrant.
If the stayopen argument is nonzero, this sets a flag so that
subsequent calls to
not close the database (as they usually would). This makes for more
efficiency if you call those functions several times, by avoiding
reopening the database for each call.
Go to the first, previous, next, last section, table of contents.