[ Bottom of Page | Previous Page | Next Page | 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>
struct servent *getservent ( )

Description

The getservent subroutine is threadsafe in AIX 4.3 and later. However, the return value points to static data that is overwritten by subsequent calls. This data must be copied to be saved for use by subsequent calls.

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.

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.

Return Values

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

If an error occurs or the end of the file is reached, the getservent subroutine returns a null pointer.

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.2 Communications Programming Concepts.

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