Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

getprotobyname(3)

getprotoent(3)

setprotoent(3)

endprotoent(3)

getprotobynumber(3)  —  Subroutines

NAME

getprotobynumber, getprotobynumber_r − Get a protocol entry by number

LIBRARY

Standard C Library (libc.a)

SYNOPSIS

#include <netdb.h> struct protoent ∗getprotobynumber(
int num); int getprotobynumber_r(
int num,
struct protoent ∗proto,
struct protoent_data ∗proto_data);

PARAMETERS

numSpecifies the protocol number. 

protoPoints to the protoent structure. 

proto_dataIs data for the protocols database. 

DESCRIPTION

The getprotobynumber() function returns a pointer to a structure of type protoent. Its members specify data in fields from a record line in the /etc/protocols network protocols database file. The netdb.h header file defines the protoent structure. 

The getprotobynumber() function searches the /etc/protocols file sequentially until a match with the num parameter occurs. The num parameter must specify the official protocol number. When EOF (End-Of-File) is reached without a match, an error value is returned by this function. 

The getprotobynumber_r() function is the reentrant version of the getprotobynumber() function.  Upon successful completion, the returned structure is pointed to by proto.  The netdb.h header file defines the protoent and protoent_data structures. 

When using the getprotobynumber() function, use the endprotoent() function to close the protocols file.  When using the getprotobynumber_r() function, use the endprotoent_r() function to close the protocols file. 

The system searches either the local /etc/protocols file or the NIS distributed networks file for the requested information.  To determine which file or files to search, and in which order, the system uses the switches in the /etc/svc.conf file. 

NOTES

The getprotobynumber() function return value points to static data, which is overwritten by any subsequently called functions using the same structure. 

Before its first access by either the setprotoent_r() or getprotobynumber_r() functions, you must zero-fill the protoent_data structure. 

RETURN VALUES

Upon successful completion, the getprotobynumber() function returns a pointer to a protoent structure.  The getprotobynumber() function returns a null pointer when a failure occurs or whenever the end of the /etc/protocols file is reached. 

Upon successful completion for getprotobynumber_r(), a value of 0 (zero) is returned.  Otherwise, a value of -1 is returned. 

ERRORS

If any of the following conditions occurs, the getprotobynumber_r() function sets errno to the corresponding value:

[EINVAL]The proto_data or proto parameter is invalid. 

[ESRCH]The search failed. 

In addition, if the function fails to open the file, it sets errno to indicate the cause of the failure. 

FILES

/etc/protocols
The DARPA Internet network protocols name database file. Each record in the file occupies a single line and has three fields: the official protocol name, the protocol number, and protocol aliases.

RELATED INFORMATION

Functions: getprotobyname(3), getprotoent(3), setprotoent(3), endprotoent(3). 

The system searches either the local /etc/protocols file or the NIS distributed networks file for the requested information.  To determine which file or files to search, and in which order, the system uses the switches in the /etc/svc.conf file. 

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