#include <netdb.h>
struct servent *getservbyname (Name, Protocol) char *Name, *Protocol;
Attention: Do not use the getservbyname subroutine in a multithreaded environment.
The getservbyname subroutine retrieves an entry from the /etc/services file using the service name as a search key.
An application program can use the getservbyname subroutine to access a service, service aliases, the protocol for the service, and a protocol port number for the service.
The getservbyname 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 subroutine returns a pointer to the servent structure, which contains fields for a line of information from the /etc/services file. The netdb.h file defines the servent structure and structure fields.
Use the endservent subroutine to close the /etc/hosts file.
Name | Specifies the name of a service. |
Protocol | Specifies a protocol for use with the specified service. |
The getservbyname subroutine returns a pointer to a servent structure when a successful match occurs. Entries in this structure are in network byte order.
Note: The return value points to static data that is overwritten by subsequent calls.
If an error occurs or the end of the file is reached, the getservbyname subroutine returns a null pointer.
The getservbyname subroutine is part of Base Operating System (BOS) Runtime.
All applications containing the getservbyname subroutine must be compiled with _BSD set to a specific value. Acceptable values are 43 and 44. In addition, all socket applications must include the BSD libbsd.a library.
/etc/services | |
Contains service names. |
The endprotoent subroutine, endservent subroutine, getprotobyname subroutine, getprotobynumber subroutine, getprotoent subroutine, getservbyport subroutine, getservent subroutine, setprotoent subroutine, setservent subroutine.
Sockets Overview, and Understanding Network Address Translation in AIX Version 4.3 Communications Programming Concepts.