Gets service entry by name.
Standard C Library (libc.a)
#include <netdb.h> int getservbyname_r(name, proto, servent, serv_data) const char *Name, proto; struct servent *servent; struct servent_data *serv_data;
An application program can use the getservbyname_r subroutine to access a service, service aliases, the protocol for the service, and a protocol port number for the service.
The getservbyname_r subroutine searches the /etc/services file sequentially from the start of the file until it finds one of the following:
Upon locating a matching name and protocol, the getservbyname_r subroutine stores the values to the servent structure. The getservbyname subroutine overwrites the static data it returns in subsequent calls. The getservbyname_r subroutine does not.
Use the endservent_r subroutine to close the /etc/hosts file.
name | Specifies the name of a service. |
proto | Specifies a protocol for use with the specified service. |
servent | Points to the servent structure. |
serv_data | Points to the serv_data structure. |
The function returns a 0 if successful and a -1 if unsuccessful. The getservbyname subroutine returns a pointer to a servent structure when a successful match occurs. Entries in this structure are in network byte order.
/etc/services | Contains service names. |
endservent_r Subroutine, setservent_r Subroutine, getservent_r Subroutine, and getservbyport_r Subroutine.