Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ endprotoent(3N) — SunOS 5.1

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

protocols(4)

getprotobyname(3N)

NAME

getprotobyname, getprotobynumber, getprotoent, setprotoent, endprotoent − get protocol entry

SYNOPSIS

cc [ flag ... ] file ... −lsocket -lnsl [ library ... ]

#include <netdb.h>

struct protoent ∗getprotobyname(char ∗name);

struct protoent ∗getprotobynumber(int proto);

struct protoent ∗getprotoent(void);

int setprotoent(int stayopen);

int endprotoent(void);

DESCRIPTION

getprotoent(), getprotobyname(), and getprotobynumber() each return a protocol entry. 

The entry may come from one of the following sources: the protocols file (see protocols(4)), the NIS maps “protocols.byname” and “protocols.bynumber”, and the NIS+ table “protocols”.  The sources and their lookup order are specified in the /etc/nsswitch.conf file (see nsswitch.conf(4) for details).  Some name services such as NIS will return only one name for a host, whereas others such as NIS+ or DNS will return all aliases. 

getprotobyname() and getprotobynumber() sequentially search from the beginning of the file until a matching protocol name or protocol number is found, or until an EOF is encountered. 

getprotoent() enumerates protocol entries:  successive calls to getprotoent() will return either successive protocol entries or NULL.  Enumeration may not be supported by some sources. 

setprotoent() “rewinds” to the beginning of the enumeration of protocol entries. If the stayopen flag is non-zero, resources such as open file descriptors are not deallocated after each call to getprotobynumber() and getprotobyname().  Calls to getprotobyname() and getprotobynumber() may leave the enumeration in an indeterminate state, so setprotoent() should be called before the first getprotoent(). 

endprotoent() may be called to indicate that protocol processing is complete; the system may then close any open protocols file, deallocate storage, and so forth.  It is legitimate, but possibly less efficient, to call more protocol routines after endprotoent(). 

The internal representation of a protocol entry is a protoent structure defined in <netdb.h> with the following members:

char∗p_name;
char∗∗p_aliases;
intp_proto;

RETURN VALUES

getprotobyname() and getprotobynumber() return a pointer to a struct protoent if they successfully locate the requested entry; otherwise they return NULL. 

getprotoent() returns a pointer to a struct protoent if it successfully enumerates an entry; otherwise it returns NULL, indicating the end of the enumeration. 

FILES

/etc/protocols

/etc/nsswitch.conf

SEE ALSO

protocols(4)

NOTES

All information is contained in a static area so it must be copied if it is to be saved. 

Use of getprotoent() is deprecated; enumeration is well-defined for the protocols file and is supported (albeit inefficiently) for NIS and NIS+, but in general may not be well-defined.  The semantics of enumeration are discussed in nsswitch.conf(4). 

BUGS

Only the Internet protocols are currently understood. 

Programs that call getprotobyname() or getprotobynumber() routines cannot be linked statically since the implementation of these routines requires dynamic linker functionality to access shared objects at run time. 

SunOS 5.1  —  Last change: 24 Feb 1992

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026