getprotoent_r Subroutine

Purpose

Gets protocol entry from the /etc/protocols file.

Library

Standard C Library (libc.a)

Syntax

#include <netdb.h>

int getprotoent_r(protoent, proto_data)
struct protoent *protoent;
struct protoent_data *proto_data;

Description

The getprotoent_r subroutine retrieves protocol information from the /etc/protocols file. An application program can use the getprotoent_r subroutine to access a protocol name, its aliases, and protocol number. The getprotoent_r subroutine opens and performs a sequential read of the /etc/protocols file. This subroutine writes to the protoent structure, which contains the fields for a line of information in the /etc/protocols file.

The netdb.h file defines the protoent structure.

Use the endprotoent_r subroutine to close the /etc/protocols file. Static data is overwritten in subsequent calls when using the getprotoent subroutine. The getprotoent_r subroutine does not overwrite.

Parameters

Item Description
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 getprotoent_r subroutine sets the protoent parameter to NULL.

Files

Item Description
/etc/protocols Contains protocol information.