getprotobynumber_r Subroutine

Purpose

Gets a protocol entry from the /etc/protocols file by number.

Library

Standard C Library (libc.a)

Syntax

#include <netdb.h>
int getprotobynumber_r(proto, protoent, proto_data)
register int proto;
struct protoent *protoent;
struct protoent_data *proto_data;

Description

The getprotobynumber_r subroutine retrieves protocol information from the /etc/protocols file using a specified protocol number as a search key.

An application program can use the getprotobynumber_r subroutine to access a protocol name, aliases, and number.

The getprotobynumber_r subroutine searches the /etc/protocols file sequentially from the start of the file until it finds a matching protocol name, protocol number, or until it reaches the end of the file.

The subroutine writes the protoent structure, which contains fields for a line of information in the /etc/protocols file.

The netdb.h file defines the protoent structure.

The getprotobynumber subroutine overwrites static data returned in subsequent calls. The getprotobynumber_r subroutine does not.

Use the endprotoent_r subroutine to close the /etc/protocols file.

Parameters

Item Description
proto Specifies the protocol number.
protoent Points to the protoent structure.
proto_data Points to the proto_data structure.

Return Values

The function returns a 0 if successful and a -1 if unsuccessful.

Note: If an error occurs or the end of the file is reached, the getprotobynumber_r subroutine sets the protoent parameter to NULL and returns a -1 to indicate error.

Files

Item Description
/etc/protocols Contains protocol information.