# endservent

## PROLOG



           This manual page is part of the POSIX Programmer's Manual.  The
           Linux implementation of this interface may differ (consult the
           corresponding Linux manual page for details of Linux behavior), or
           the interface may not be implemented on Linux.
    


## NAME



           endservent, getservbyname, getservbyport, getservent, setservent —
           network services database functions
    


## SYNOPSIS



           #include <netdb.h>
    
           void endservent(void);
           struct servent *getservbyname(const char *_name_ , const char *_proto_);
           struct servent *getservbyport(int _port_ , const char *_proto_);
           struct servent *getservent(void);
           void setservent(int _stayopen_);
    


## DESCRIPTION



           These functions shall retrieve information about network services.
           This information is considered to be stored in a database that can
           be accessed sequentially or randomly. The implementation of this
           database is unspecified.
    
           The _setservent_() function shall open a connection to the database,
           and set the next entry to the first entry. If the _stayopen_
           argument is non-zero, the _net_ database shall not be closed after
           each call to the _getservent_() function (either directly, or
           indirectly through one of the other _getserv*_() functions), and the
           implementation may maintain an open file descriptor for the
           database.
    
           The _getservent_() function shall read the next entry of the
           database, opening and closing a connection to the database as
           necessary.
    
           The _getservbyname_() function shall search the database from the
           beginning and find the first entry for which the service name
           specified by _name_ matches the _s_name_ member and the protocol name
           specified by _proto_ matches the _s_proto_ member, opening and closing
           a connection to the database as necessary.  If _proto_ is a null
           pointer, any value of the _s_proto_ member shall be matched.
    
           The _getservbyport_() function shall search the database from the
           beginning and find the first entry for which the port specified by
           _port_ matches the _s_port_ member and the protocol name specified by
           _proto_ matches the _s_proto_ member, opening and closing a connection
           to the database as necessary.  If _proto_ is a null pointer, any
           value of the _s_proto_ member shall be matched. The _port_ argument
           shall be a value obtained by converting a **uint16_t** in network byte
           order to **int**.
    
           The _getservbyname_(), _getservbyport_(), and _getservent_() functions
           shall each return a pointer to a **servent** structure, the members of
           which shall contain the fields of an entry in the network services
           database.
    
           The _endservent_() function shall close the database, releasing any
           open file descriptor.
    
           These functions need not be thread-safe.
    


## RETURN VALUE



           Upon successful completion, _getservbyname_(), _getservbyport_(), and
           _getservent_() return a pointer to a **servent** structure if the
           requested entry was found, and a null pointer if the end of the
           database was reached or the requested entry was not found.
           Otherwise, a null pointer is returned.
    
           The application shall not modify the structure to which the return
           value points, nor any storage areas pointed to by pointers within
           the structure. The returned pointer, and pointers within the
           structure, might be invalidated or the structure or the storage
           areas might be overwritten by a subsequent call to
           _getservbyname_(), _getservbyport_(), or _getservent_().  The returned
           pointer, and pointers within the structure, might also be
           invalidated if the calling thread is terminated.
    


## ERRORS



           No errors are defined.
    
           _The following sections are informative._
    


## EXAMPLES



           None.
    


## APPLICATION USAGE



           The _port_ argument of _getservbyport_() need not be compatible with
           the port values of all address families.
    


## RATIONALE



           None.
    


## FUTURE DIRECTIONS



           None.
    


* * *