getservent(3N)


getservent, getservbyport, getservbyname, setservent, endservent -- get service entry

Synopsis

cc [options] files -lsocket -lnsl
#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);

Description

getservbyname, getersvbyport and getservent return a pointer to a servent structure, whose members contain the fields of an entry in the network services database.

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
The official name of the service.

s_aliases
A zero terminated list of alternate names for the service.

s_port
The port number at which the service resides. Port numbers are returned in network short byte order.

s_proto
The name of the protocol to use when contacting the service.

Files


/etc/services

/var/yp/{domainname}/services.byname

Usage

The port argument of getservbyport need not be compatible with the port values of all address families.

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.

Return values

A NULL pointer is returned on EOF or error.

References

byteorder(3N), inet(3N), gethostent(3N), getprotoent(3N), ypserv(1Mnis), services(4tcp)

Notices

All information is contained in a static area so it must be copied if it is to be saved. For multi-threaded applications, this must be done on a per-thread basis.

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).


© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 25 April 2004