[ Bottom of Page | Previous Page | Next Page | Contents | Index | Library Home | Legal | Search ]

Technical Reference: Communications, Volume 2

gethostbyaddr_r Subroutine


Gets network host entry by address.


Standard C Library (libc.a)


#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;


This function internally calls the gethostbyaddr subroutine and stores the value returned by the gethostbyaddr subroutine to the hostent structure.


Addr Points to the host address which is a constant string.
Len Specifies the length of the address.
Type Specifies the domain type of the host address. This works only on the address family AF_INET.
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.

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:

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


/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.

Related Information

endhostent_r Subroutine, gethostbyaddr_r Subroutine, gethostent_r Subroutine, and sethostent_r Subroutine.

[ Top of Page | Previous Page | Next Page | Contents | Index | Library Home | Legal | Search ]