Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

getservbyport(3)

getservbyname(3)

endservent(3)

setservent(3)

getservent(3)  —  Subroutines

NAME

getservent, getservent_r − Get a services file entry from the /etc/services file. 

LIBRARY

Standard C Library (libc.a)

SYNOPSIS

#include <netdb.h> struct servent ∗getservent(void); int getservent_r(
struct servent ∗serv,
struct servent_data ∗serv_data);

PARAMETERS

servPoints to the servent structure. 

serv_dataIs data for the services database. 

DESCRIPTION

The getservent() (get service entry) function opens and reads the next line of the /etc/services file. 

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

The getservent() function 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 header file as follows:

struct  servent {
        char    ∗s_name;        /∗ official service name ∗/
        char    ∗∗s_aliases;    /∗ alias list ∗/
        int     s_port;         /∗ port # ∗/
        char    ∗s_proto;       /∗ protocol to use ∗/
};

The /etc/services file remains open after a call by the getservent() function.  Use the endservent() function to close the /etc/services file.  Use the setservent() function to rewind. 

The getservent_r() function is the reentrant version of the getservent() function.  Upon successful completion, the returned structure is pointed to by serv.  The netdb.h header file defines the servent and servent_data structures. 

The system searches either the local /etc/services file or the NIS distributed networks file for the requested information.  To determine which file or files to search, and in which order, the system uses the switches in the /etc/svc.conf file. 

NOTES

The getservent() return value points to static data, which is overwritten by any subsequently called functions using the same structure. 

Before its first access by the getservent_r() function, you must zero-fill the servent_data structure. 

If the system is configured to access the services database through NIS, the getservent_r()  function may not produce correct results if called from multiple threads. 

RETURN VALUES

Upon successful completion, the getservent() function returns a pointer to a servent structure. 

If an error occurs or the end of the file is reached, the getservent() function returns a NULL pointer. 

Upon successful completion, the getservent_r() function returns a value of 0 (zero).  Otherwise, a value of -1 is returned. 

ERRORS

If any of the following conditions occurs, the getservent_r() function sets errno to the corresponding value:

[EINVAL]The serv or serv_data parameter is invalid. 

[ESRCH]The search failed. 

In addition, if the function fails to open the file, it sets errno to indicate the cause of the failure. 

FILES

/etc/services
The DARPA Internet network service name database file. Each record in the file occupies a single line and has four fields: the official service name, the port number, the protocol name, and aliases.

RELATED INFORMATION

Functions: getservbyport(3), getservbyname(3), endservent(3), setservent(3). 

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026