getprotobynumber() — Get a protocol entry by number

Standards

Standards / Extensions C or C++ Dependencies

XPG4.2
Single UNIX Specification, Version 3

both  

Format

X/Open:
#define _XOPEN_SOURCE_EXTENDED 1
#include <netdb.h>

struct protoent *getprotobynumber(int proto);
Berkeley sockets:
#define _OE_SOCKETS
#include <netdb.h>

struct protoent *getprotobynumber(int proto);

General description

The getprotobynumber() call searches the /etc/protocol or tcpip.ETC.PROTO data set for the specified protocol number.
Parameter
Description
proto
The protocol number.

The getprotobynumber() call returns a pointer to a protoent structure for the network protocol specified on the call. getprotobyname(), getprotobynumber(), and getprotoent() all use the same static area to return the protoent structure. This static area is only valid until the next one of these functions is called on the same thread.

The protoent structure is defined in the netdb.h include file and contains the following elements:
Element
Description
p_aliases
An array, terminated with a NULL pointer, of alternative names for the protocol.
p_name
The official name of the protocol.
p_proto
The protocol number.

Special behavior for C++: To use this function with C++, you must use the _XOPEN_SOURCE_EXTENDED 1 feature test macro.

Returned value

If successful, getprotobynumber() returns a pointer to a protoent structure. The return value points to data that is overwritten by subsequent calls returning the same data structure.

If unsuccessful, getprotobynumber() returns a NULL pointer, indicating an error or End Of File (EOF).