gethostbyaddr_r Subroutine
Purpose
Gets network host entry by address.
Library
Standard C Library (libc.a)
(libbind)
(libnis)
(liblocal)
Syntax
#include <netdb.h>
int gethostbyadd_r(Addr, Len, Type, Htent, Ht_data)
const char *Addr, size_t Len, int Type, struct hostent *Htent, struct hostent_data *Ht_data;
Description
This function internally calls the gethostbyaddr subroutine and stores the value returned by the gethostbyaddr subroutine to the hostent structure.
Parameters
Item | Description |
---|---|
Addr | Points to the host address that is a pointer to the binary format address. |
Len | Specifies the length of the address. |
Type | Specifies the domain type of the host address. It can be either AF_INET or AF_INET6. |
Htent | Points to a hostent structure which is used to store the return value of the gethostaddr subroutine. |
Ht_data | Points to a hostent_data structure. |
Return Values
The function returns a 0 if successful and a -1 if unsuccessful.
Note: The
return value of the gethostbyaddr subroutine points to static
data that is overwritten by subsequent calls. This data must be copied
at every call to be saved for use by subsequent calls. The gethostbyaddr_r subroutine
solves this problem.
If the Name parameter is a hostname, this subroutine searches for a machine with that name as an IP address. Because of this, use the gethostbyname_r subroutine.
Error Codes
The gethostbyaddr_r subroutine
is unsuccessful if any of the following errors occur:
Item | Description |
---|---|
HOST_NOT_FOUND | The host specified by the Name parameter was not found. |
TRY_AGAIN | The local server did not receive a response from an authoritative server. Try again later. |
NO_RECOVERY | Indicates an unrecoverable error occured. |
NO_ADDRESS | The requested Name parameter is valid but does not have an Internet address at the name server. |
SERVICE_UNAVAILABLE | None of the name services specified are running or available. |
EINVAL | The hostent pointer is NULL |
Files
Item | Description |
---|---|
/etc/hosts | Contains the host name data base. |
/etc/resolv.conf | Contains the name server and domain name. |
/etc/netsvc.conf | Contains the name services ordering. |
/usr/include/netdb.h | Contains the network database structure. |