[ Previous | Next | Table of Contents | Index | Library Home | Legal | Search ]

Technical Reference: Communications, Volume 2


getprotobynumber Subroutine

Purpose

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

Library

Standard C Library (libc.a)

Syntax

#include <netdb.h>


struct protoent *getprotobynumber ( Protocol)
int Protocol;

Description

Attention: Do not use the getprotobynumber subroutine in a multithreaded environment.

The getprotobynumber 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 subroutine to access a protocol name, its aliases, and protocol number.

The getprotobynumber subroutine searches the /etc/protocols file sequentially from the start of the file until it finds a matching protocol name or protocol number, or until it reaches the end of the file. The subroutine returns a pointer to a protoent structure, which contains fields for a line of information in the /etc/protocols file. The netdb.h file defines the protoent structure.

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

Parameters


Protocol Specifies the protocol number.

Return Values

Upon successful completion, the getprotobynumber subroutine, returns a pointer to a protoent structure.

Note: The return value points to static data that is overwritten by subsequent calls.

If an error occurs or the end of the file is reached, the getprotobynumber subroutine returns a null pointer.

Implementation Specifics

The getprotobynumber subroutine is part of Base Operating System (BOS) Runtime.

All applications containing the getprotobynumber subroutine must be compiled with _BSD set to a specific value. Acceptable values are 43 and 44. In addition, all socket applications must include the BSD libbsd.a library.

Files


/etc/protocols
                          Contains protocol information.

Related Information

The endprotoent subroutine, getprotobyname subroutine, getprotoent subroutine, setprotoent subroutine.

Sockets Overview in AIX 5L Version 5.1 Communications Programming Concepts.


[ Previous | Next | Table of Contents | Index | Library Home | Legal | Search ]