getservent()--Get Next Entry from Service Database
Syntax
#include <netdb.h> struct servent *getservent()
Service Program Name: QSOSRV2
Default Public Authority: *USE
Threadsafe: No; see Usage Notes.
The getservent() function is used to retrieve information about services (the protocol being used by the service and the port number assigned for the service). The information is retrieved from the services database file. When getservent() is first called, the file is opened, and the first entry is returned. Each subsequent call to getservent() results in the next entry in the file being returned. To close the file, use endservent().
Authorities
No authorization is required.
Return Value
getservent() returns a pointer. Possible values are:
- NULL (unsuccessful or end-of-file)
- p (successful), where p is a pointer to struct servent.
struct servent { char *s_name; char **s_aliases; int s_port; char *s_proto };
s_name points to the character string that contains the name of the service. s_aliases is a pointer to a NULL-terminated array of alternate names for the service. s_port is the port number assigned to the service. s_proto is the protocol being used by the service.
The structure struct servent is defined in <netdb.h>.
Usage Notes
- System i® Navigator or the following CL commands can be
used to access the services database file:
- WRKSRVTBLE (Work with Service Table Entries)
- ADDSRVTBLE (Add Service Table Entry)
- RMVSRVTBLE (Remove Service Table Entry)
- WRKSRVTBLE (Work with Service Table Entries)
- The pointer returned by getservent() points to static storage that
is overwritten on subsequent calls to the getservent(),
getservbyname(), or getservbyport() functions.
- A coded character set identifier (CCSID) of 65535 for the job requests that
no database translation be performed. For translation to occur for the service
names returned in the servent structure, the job CCSID must be something other
than 65535.
- Do not use the getservent() function in a multithreaded
environment. See the multithread alternative getservent_r()
function.
- When you develop in C-based languages and an application is compiled with the _XOPEN_SOURCE macro defined to the value 520 or greater, the getservent() API is mapped to qso_getservent98().
Related Information
- _XOPEN_SOURCE--Using _XOPEN_SOURCE for the UNIX® 98
compatible interface
- getservbyname()--Get Port Number for Service
Name
- getservbyport()--Get Service Name for Port
Number
- endservent()--Close Service Database
- setservent()--Open Service Database
API introduced: V4R2