[ Next Article | Previous Article | Book Contents | Library Home | Legal | Search ]
Communications Technical Reference, Volume 2

getservbyname Subroutine

Purpose

Gets service entry by name.

Library

Standard C Library (libc.a)

Syntax

#include <netdb.h>
struct servent *getservbyname (Name, Protocol)
char *Name, *Protocol;

Description

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.

Parameters

Name Specifies the name of a service.
Protocol Specifies a protocol for use with the specified service.

Return Values

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.

Implementation Specifics

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.

Files

/etc/services
                          Contains service names.

Related Information

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.


[ Next Article | Previous Article | Book Contents | Library Home | Legal | Search ]