|HP-UX Reference > G
HP-UX 11i Version 3: February 2007
getprotoent(), getprotobynumber(), getprotobyname(), setprotoent(), endprotoent() — get, set, or end protocol entry
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:
Functions behave as follows:
In a multithreaded application, getprotoent(), getprotobyaddr(), and getprotobyname() use thread-specific storage that is re-used in each call. The return value structprotoent 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: successive 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 database.
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.
getprotoent(), getprotobyname(), and getprotobynumber() return a null pointer (0) on EOF or when they are unable to open /etc/protocols.
int getprotoent_r(struct protoent *result, struct protoent_data *buffer); int getprotobyname_r(const char *name, struct protoent *result, struct protoent_data *buffer); int getprotobynumber_r(int proto, struct protoent *result, struct protoent_data *buffer); int setprotoent_r(int stayopen, struct protoent_data *buffer); int endprotoent_r(struct protoent_data *buffer);
The above reentrant interfaces have been moved from libc to libd4r. They are included to support existing applications and may be removed in a future release. New multithreaded applications should use the regular APIs without _r.
The reentrant interfaces performs the same operation as their regular counterpart (those without the _r suffix.) However, getprotoent_r(), getprotobyname_r(), and getprotobyport_r() expect to be passed the address of a struct protoent parameter and will store the address of the result at this supplied parameter. An additional parameter, an address to struct protoent_data, which is defined in the file <netdb.h> cannot be a NULL pointer.
The reentrant routines return -1 if the operation is unsuccessful, or, in the case of getprotoent_r(), if the end of the services list has been reached. 0 is returned otherwise.
The following code excerpt counts the number of protocols entries:
int count = 0; (void) setprotoent(0); while (getprotoent() != NULL) count++; (void) endprotoent();
Programs that use the interfaces described in this manpage cannot be linked statically because the implementations of these functions employ dynamic loading and linking of shared objects at run time.