getprotobyname(3) — Subroutines
NAME
getprotobyname, getprotobyname_r − Get a protocol entry by protocol name
LIBRARY
Standard C Library (libc.a)
SYNOPSIS
#include <netdb.h>
struct protoent ∗getprotobyname(
const char ∗name);
int getprotobyname_r(
const char ∗name,
struct protoent ∗proto,
struct protoent_data ∗proto_data);
PARAMETERS
nameSpecifies the official protocol name or alias.
protoPoints to the protoent structure.
proto_dataIs data for the protocols database.
DESCRIPTION
The getprotobyname() 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 getprotobyname() function searches the /etc/protocols file sequentially until a match with the name parameter occurs. The name parameter will specify either the official protocol name or an alias. When EOF (End-of-File) is reached without a match, an error value is returned by this function.
When using the getprotobyname() function, use the endprotoent() function to close the protocols file. When using the getprotobyname_r() function, use the endprotoent_r() function to close the protocols file.
The getprotobyname_r() function is the reentrant version of the getprotobyname() function. Upon successful completion, the returned structure is pointed to by proto. The netdb.h header file defines the protoent and protoent_data structures.
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 getprotobyname() 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 getprotobyname_r() functions, you must zero-fill the protoent_data structure.
RETURN VALUES
Upon successful completion, the getprotobyname() function returns a pointer to a protoent structure, The getprotobyname() function returns a null pointer when a failure occurs or when the end of the /etc/protocols file is reached.
Upon successful completion for getprotobyname_r() a value of 0 (zero) is returned. Otherwise, a value of -1 is returned.
ERRORS
If any of the following conditions occurs, the getprotobyname_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: getprotobynumber(3), getprotoent(3), setprotoent(3), endprotoent(3).