getservent_r()--Get Next Entry from Service Database


  Syntax
 #include <netdb.h>
 int getservent_r(struct servent *servent_struct_addr,
                  struct servent_data
                     *servent_data_struct_addr)

  Service Program Name: QSOSRV2

  Default Public Authority: *USE

  Threadsafe: Yes

The getservent_r() 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 the getservent_r() is first called, the file is opened, and the first entry is returned. Each subsequent call of getservent_r() results in the next entry in the file being returned. To close the file, use endservent_r().


Parameters

struct servent *servent_struct_addr  (input/output) 
Specifies the pointer to a servent structure where the results will be placed. All results must be referenced through this structure.

struct servent_data *servent_data_struct_addr  (input/output) 
Specifies the pointer to the servent_data structure, which is used to pass and preserve results between function calls. The field serve_control_blk in the servent_data structure must be initialized with hexadecimal zeros before its initial use. If compatibility with other platforms is required, then the entire servent_data structure must be initialized with hexadecimal zeros before initial use.

Authorities

No authorization is required.


Return Value

The getservent_r() function returns an integer. Possible values are:

The struct servent denoted by servent_struct_addr and struct servent_datadenoted by servent_data_struct_addr are both defined in <netdb.h>. The structure struct serventis defined as:

      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 list of pointers, each of which points to a character string that represents an alternative name for the service. s_port is the port number assigned to the service. s_proto is a pointer to a character string that contains the name of the protocol being used by the service.


Error Conditions

When the getservent_r() function fails, errno can be set to:

[einval]

The servent_data structure was not properly initialized with hexadecimal zeros before initial use. For corrective action, see the description for structure servent_data.


Usage Notes

System i® Navigator or the following CL commands can be used to access the services database file:

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.


Related Information



API introduced: V3R1

[ Back to top | UNIX-Type APIs | APIs by category ]