HP-UX Reference (11i v2 03/08) - 3 Library Functions A-M (vol 6)

g
getprotoent(3N) getprotoent(3N)
NAME
getprotoent(), getprotobynumber(), getprotobyname(), setprotoent(), endprotoent() - get protocol entry
SYNOPSIS
#include <netdb.h>
struct protoent *getprotoent(void);
struct protoent *getprotobyname(const char *name);
struct protoent *getprotobynumber(int proto);
int setprotoent(int stayopen);
int endprotoent(void);
_XOPEN_SOURCE_EXTENDED only
void setprotoent(int stayopen);
void endprotoent(void);
DESCRIPTION
The getprotoent()
, getprotobyname()
, and getprotobynumber()
functions each return a
pointer to a structure of type protoent containing the broken-out fields of a line in the network protocol
data base,
/etc/protocols
.
The members of this structure are:
p_name The official name of the protocol.
p_aliases A null-terminated list of alternate names for the protocol.
p_proto The protocol number.
Functions behave as follows:
getprotoent() Reads the next line of the file, opening the file if necessary.
setprotoent() Opens and rewinds the file. If the stayopen flag is non-zero, the
protocol data base is not closed after each call to getprotoent()
(either directly or indirectly through one of the other getproto*
calls).
endprotoent() Closes the file.
getprotobyname(),
getprotobynumber()
Each sequentially searches from the beginning of the file until a
matching protocol name (among either the official names or the
aliases) or protocol number is found, or until EOF is encountered.
In a multithreaded application,
getprotoent(), getprotobyaddr(), and getprotobyname()
use thread-specific storage that is re-used in each call. The return value struct protoent should be
unique for each thread and should be saved, if desired, before the thread makes the next getproto*()
call.
For enumeration in multithreaded applications, the position within the enumeration is a process-wide
property shared by all threads.
setprotoent() may be used in a multithreaded application, but
resets the enumeration position for all threads. getprotoent() enumerates protocol entries: succes-
sive calls to getprotoent() will return either successive protocol entries or NULL. If multiple threads
interleave calls to getprotoent(), the threads will enumerate disjoint subsets of the protocol data-
base.
If the system is running the Network Information Service (NIS) services or Network Information Service
Plus (NIS+) services,
getprotobyname() and getprotobynumber() get the protocol information
from the NIS server (see ypserv (1M) and ypfiles(4)) or NIS+ server (see nis+(1)), respectively.
Name Service Switch-Based Operation
The library routines
getprotobyname(), getprotobynumber(), getprotoent(), and their
reentrant counterparts, internally call the name service switch to access the "protocols" database lookup
policy configured in the /etc/nsswitch.conf file (see nsswitch.conf(4)). The lookup policy defines
the order and the criteria of the supported name services used to resolve protocol names and numbers.
Section 3396 Hewlett-Packard Company 1 HP-UX 11i Version 2: August 2003