getservbyname(3) — Subroutines
OSF — Environment_Note_Added
NAME
getservbyname − Get service entry by name
LIBRARY
Sockets Library (libc.a)
SYNOPSIS
#include <netdb.h>
struct servent ∗getservbyname (
char ∗name,
char ∗proto );
PARAMETERS
nameSpecifies the official name or alias name of the service.
protoSpecifies the name of the protocol to use when contacting the service.
DESCRIPTION
The getservbyname() function returns a pointer to a structure of type servent. Its members specify data in fields from a record line in the /etc/services database file. The netdb.h header file defines the servent structure.
The getservbyname() function searches the /etc/services file sequentially until a match with the name parameter or with the proto parameter occurs. The name parameter may specify either the official name or its alias. When EOF (End-of-File) is reached without a match, an error value is returned by this subroutine. When the protocol name is not specified (proto parameter is null), the proto parameter need not be matched during the /etc/services file record search.
The getservbyname() function searches the /etc/services file sequentially until one of the following occurs:
•A name and protocol number match.
•A name match when the proto parameter is set to null.
•The end of the /etc/services file is reached.
Use the endservent() function to close the /etc/services file.
NOTES
The return value points to static data, which is overwritten by any subsequently called functions using the same structure.
RETURN VALUES
Upon successful completion, a pointer to a servent structure is returned. A null pointer is returned when an error occurs or whenever the end of the /etc/services file is reached.
FILES
/etc/services
The DARPA Internet network service-name database. Each record in the file occupies a single line and has four fields consisting of the official service name, port reference, protocol name, and alias.
ENVIRONMENT NOTES
This section describes system features that are not generic to OSF/1 but that are provided in this OSF/1 implementation.
Digital Extensions
The system searches either the local /etc/services 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.
RELATED INFORMATION
Functions: getprotobyname(3), getprotobynumber(3), getprotoent(3), setprotoent(3), endprotoent(3)