Purpose
Gets service
entry by name.
Library
Standard C
Library (libc.a)
Syntax
#include <netdb.h>
int getservbyname_r(name, proto, servent, serv_data)
const char *Name, proto;
struct servent *servent;
struct servent_data *serv_data;
Description
Requirement: Use the getservbyname subroutine
instead of the getservbyname_r subroutine. The getservbyname_r subroutine
is compatible only with earlier versions of AIX®.
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:
- Matching name and protocol number.
- Matching name when the Protocol parameter is set to 0.
- End of the file.
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.
You
must fill the servent_data structure with zeros before its
first access by either the setservent_r or the getservbyname_r subroutine.
Parameters
Item |
Description |
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. |
Return Values
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.
Note: If an error
occurs or the end of the file is reached, the getservbyname_r returns
a -1.
Files
Item |
Description |
/etc/services |
Contains service names. |