HP-UX Reference (11i v1 00/12) - 3 Library Functions A-M (vol 6)

__________________________________________________________________________________________________________________________________________________________________________________________________
__________________________________________________________________________________________________________________________________________________________________________________________________
STANDARD Printed by: Nora Chuang [nchuang] STANDARD
/build/1111/BRICK/man3/!!!intro.3c
________________________________________________________________
___ ___
g
getservent(3N) getservent(3N)
NAME
getservent(), getservbyport(), getservbyname(), setservent(), endservent() - get service entry
SYNOPSIS
#include <netdb.h>
struct servent *getservent(void);
struct servent *getservbyname(const char *name,
const char *proto);
struct servent *getservbyport(int port, const char *proto);
int setservent(int stayopen);
int endservent(void);
_XOPEN_SOURCE_EXTENDED only
void setservent(int stayopen);
void endservent(void);
MULTITHREAD USAGE
Thread Safe: Yes
Cancel Safe: Yes
Async-cancel Safe: No
Async-signal Safe: No
These functions can be called safely in a multithreaded environment. They may be cancellation points in
that they call functions that are cancel points.
DESCRIPTION
The getservent() , getservbyname()
, and getservbyport() functions each return a pointer
to a structure of type servent containing the broken-out fields of a line in the network services data base,
/etc/services.
The members of this structure are:
s_name The official name of the service.
s_aliases A null-terminated list of alternate names for the service.
s_port The port number at which the service resides.
s_proto The name of the protocol to use when contacting the service.
Functions behave as follows:
getservent() Reads the next line of the file, opening the file if necessary.
setservent() Opens and rewinds the file. If the stayopen flag is non-zero, the services
data base is not closed after each call to getservent() (either directly
or indirectly through one of the other getserv* calls).
endservent() Closes the file.
getservbyname()
getservbyport()
Each sequentially searches from the beginning of the file until a matching
service name (among either the official names or the aliases) or port
number is found, or until EOF is encountered. If a non-NULL protocol
name is also supplied (such as
tcp or udp), searches must also match the
protocol.
If the system is running the Network Information Service (NIS) or Network Information Service Plus
(NIS+), getservbyname() gets the service information from the NIS server (see ypserv(1M) and
ypfiles(4)) or from the NIS+ server (see nis+(1)), respectively.
In a multithreaded application,
getservent() , getservbyaddr(), and getservbyname() use
thread-specific storage that is re-used in each call. The return value
struct servent should be unique
for each thread and should be saved, if desired, before the thread makes the next
getserv*()
call.
HP-UX Release 11i: December 2000 1 Section 3349
___
___