The getservbyname() call returns a pointer to the ETC\SERVICES file entry specified by a service name.
Syntax
#include <netdb.h> struct servent *getservbyname(name, proto) char *name; char *proto;
Parameters
name
Description
This call searches the ETC\SERVICES file for the specified service name, which must match the protocol if a protocol is stated.
The getservbyname() call retrieves an entry from the ETC\SERVICES file using the name parameter as a search key.
An application program can use this call to access a service, service aliases, the protocol for the service, and a protocol port number for the service.
The getservbyname() call searches the ETC\SERVICES file sequentially from the start of the file until it finds one of the following:
Use the endservent() call to close the ETC\SERVICES file.
Return Values
The call returns a pointer to a servent structure for the network service specified on the call. The return value points to static data that subsequent API calls can modify. A pointer to a servent structure indicates success. A NULL pointer indicates an error or EOF.
The servent structure is defined in the <NETDB.H> header file and contains the following elements:
Element
Related Calls
endprotoent() endservent()
getprotobyname()
getprotobynumber()
getprotoent()
getservbyport()
getservent()
setprotoent()
setservent()