Jump to content United States-English
HP.com Home Products and Services Support and Drivers Solutions How to Buy
» Contact HP
More options
HP.com home
HP-UX Reference > G

getprotoent(3N)

HP-UX 11i Version 3: February 2007
» 

Technical documentation

» Feedback
Content starts here

 » Table of Contents

 » Index

NAME

getprotoent(), getprotobynumber(), getprotobyname(), setprotoent(), endprotoent() — get, set, or end 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 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.

If the system is running the Network Information Service (NIS), getprotobyname() and getprotobynumber() get the protocol information from the NIS server (see ypserv(1M) and ypfiles(4)).

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.

RETURN VALUE

getprotoent(), getprotobyname(), and getprotobynumber() return a null pointer (0) on EOF or when they are unable to open /etc/protocols.

OBSOLESCENT INTERFACES

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.

EXAMPLES

The following code excerpt counts the number of protocols entries:

int count = 0; (void) setprotoent(0); while (getprotoent() != NULL) count++; (void) endprotoent();

WARNINGS

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.

AUTHOR

getprotoent() was developed by Sun Microsystems Inc.

FILES

/etc/protocols

STANDARDS CONFORMANCE

getprotoent(): XPG4

Printable version
Privacy statement Using this site means you accept its terms Feedback to webmaster
© 1983-2007 Hewlett-Packard Development Company, L.P.