gethostbyaddr_r()--Get Host Information for IP Address


  BSD 4.3 Syntax
  #include <netdb.h>

  int gethostbyaddr_r(char *host_address,
                     int address_length,
                     int address_type,
                     struct hostent *hostent_struct_addr,
                     struct hostent_data *hostent_data_struct_addr)

  Service Program Name: QSOSRV2

  Default Public Authority: *USE

  Threadsafe: Yes



  UNIX 98 Compatible Syntax
  #define _XOPEN_SOURCE 520
  #include <netdb.h>

  int gethostbyaddr_r(const void *host_address,
                      socklen_t address_length,
                      int address_type,
                      struct hostent *hostent_struct_addr,
                      struct hostent_data *hostent_data_struct_addr)

  Service Program Name: QSOSRV2

  Default Public Authority: *USE

  Threadsafe: Yes


The gethostbyaddr_r() function is used to retrieve information about a host.

There are two versions of the API, as shown above. The base i5/OS API uses BSD 4.3 structures and syntax. The other uses syntax and structures compatible with the UNIX 98 programming interface specifications. You can select the UNIX 98 compatible interface with the _XOPEN_SOURCE macro.

Parameters

host_address  (input) 
Specifies the pointer to a structure of type in_addr that contains the address of the host for which information is to be retrieved.

address_length  (input) 
Specifies the length of the host_address.

address_type  (input) 
Specifies the domain type of the host address. Currently, af_inet is the only value for this parameter that is supported.

hostent_struct_addr  (input/output) 
Specifies the pointer to a hostent structure where the results will be placed. All results must be referenced through this structure.

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

Authorities

No authorization is required.


Return Value

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


Error Conditions

When the gethostbyaddr_r() function fails, h_errno (defined in <netdb.h>) can be set to:

[HOST_NOT_FOUND]

The host name specified by the host_address parameter was not found.

[NO_DATA]

The host name is a valid name, but there is no corresponding IP address.

[NO_RECOVERY]

An unrecoverable error has occurred.

[TRY_AGAIN]

The local server did not receive a response from an authoritative server. An attempt at a later time may succeed.

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

[EINVAL]

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


Usage Notes

  1. The iSeries Navigator or the following CL commands can be used to access the host database file:

  2. There are two sources from which host information can be obtained: the domain name server and the host database file. The path taken depends on whether an IP address is configured for a name server using the iSeries Navigator or option 12, Change TCP/IP domain information, on the CFGTCP menu.

    Note: A person with a UNIX background would expect this information to exist in a file known as /etc/resolv.conf. If the IP address is found (indicating that the local network is a domain network), the gethostbyaddr_r() function will attempt to query the domain name server for information about a host. If the query fails, the information will be obtained from the host database file. If the name server IP address is not found (indicating that local network is a flat network), the host database file is used to obtain the host information.

  3. When the host information is obtained from the host database file, the file is opened and the host information is retrieved (if it exists) from the file. The file is then closed only if a sethostent_r() call with a non-zero parameter value was not previously done.

  4. If a sethostent_r() call with a non-zero parameter value was previously done, the gethostbyaddr_r() routine, when obtaining host information from the domain name server, will communicate with the domain name server over a connection-oriented transport service (for example, TCP). Otherwise, gethostbyaddr_r() will use a connectionless transport service (for example, UDP).

  5. If the host information is obtained from the domain name server, the information is returned in the default coded character set identifier (CCSID) currently in effect for the job. (The default CCSID is the same as the job CCSID unless 65535 is requested, in which case the default CCSID is set based on the language ID of the job. See the globalization topic for more information.) If the host information is retrieved from the host database file the default CCSID of the job is not used. To request translation of the host information when it is retrieved from the host database file, you must use a job CCSID of something other than 65535.

  6. Address families are defined in <sys/socket.h>, and the in_addr structure is defined in <netinet/in.h>.

  7. 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 gethostbyaddr_r() API is mapped to qso_gethostbyaddr_r98().

Related Information



API introduced: V3R1
Top | UNIX-Type APIs | APIs by category