[ Bottom of Page | Previous Page | Next Page | Contents | Index | Library Home | Legal | Search ]

Technical Reference: Communications, Volume 2

getservbyname_r Subroutine

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

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.

Parameters

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

/etc/services Contains service names.

Related Information

endservent_r Subroutine, setservent_r Subroutine, getservent_r Subroutine, and getservbyport_r Subroutine.

[ Top of Page | Previous Page | Next Page | Contents | Index | Library Home | Legal | Search ]