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

Technical Reference: Communications, Volume 2


getservent Subroutine

Purpose

Gets services file entry.

Library

Standard C Library (libc.a)

Syntax

#include <netdb.h>

truct servent *getservent ( )

Description

Attention: Do not use the getservent subroutine in a multithreaded environment.

The getservent subroutine opens and reads the next line of the /etc/services file.

An application program can use the getservent subroutine to retrieve information about network services and the protocol ports they use.

The getservent subroutine returns a pointer to a servent structure, which contains fields for a line of information from the /etc/services file. The servent structure is defined in the netdb.h file.

The /etc/services file remains open after a call by the getservent subroutine. To close the /etc/services file after each call, use the setservent subroutine. Otherwise, use the endservent subroutine to close the /etc/services file.

Return Values

The getservent subroutine returns a pointer to a servent structure when a successful match occurs.

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 getservent subroutine returns a null pointer.

Implementation Specifics

The getservent subroutine is part of Base Operating System (BOS) Runtime.

All applications containing the getservent 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, getservbyname subroutine, getservbyport subroutine, setprotoent subroutine, setservent subroutine.

Sockets Overview, and Understanding Network Address Translation in AIX 5L Version 5.1 Communications Programming Concepts.


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