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

Technical Reference: Base Operating System and Extensions, Volume 1

getipnodebyaddr Subroutine


Address-to-nodename translation.


Standard C Library (libc.a)



#include <sys/socket.h>
#include <netdb.h>
struct hostent *getipnodebyaddr(src, len, af, error_num)
const void *src;
size_t len;
int af;
int *error_num; 


The getipnodebyaddr subroutine has the same arguments as the gethostbyaddr subroutine but adds an error number. It is thread-safe.

The getipnodebyaddr subroutine is similar in its name query to the gethostbyaddr subroutine except in one case. If af equals AF_INET6 and the IPv6 address is an IPv4-mapped IPv6 address or an IPv4-compatible address, then the first 12 bytes are skipped over and the last 4 bytes are used as an IPv4 address with af equal to AF_INET to lookup the name.

If the getipnodebyaddr subroutine is returning success, then the single address that is returned in the hostent structure is a copy of the first argument to the function with the same address family and length that was passed as arguments to this function.

All of the information returned by getipnodebyaddr is dynamically allocated: the hostent structure and the data areas pointed to by the h_name, h_addr_lisy, and h_aliases members of the hostent structure. To return this information to the system the function freehostent is called.


src Specifies a node address. It is a pointer to either a 4-byte (IPv4) or 16-byte (IPv6) binary format address.
af Specifies the address family which is either AF_INET or AF_INET6.
len Specifies the length of the node binary format address.
error_num Returns argument to the caller with the appropriate error code.

Return Values

The getipnodebyaddr subroutine returns a pointer to a hostent structure on success.

The getipnodebyaddr subroutine returns a null pointer if an error occurs. The error_num parameter is set to indicate the error.

Error Codes

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 This error code indicates an unrecoverable error.
NO_ADDRESS The requested name is valid but does not have an Internet address at the name server.

Related Information

The freehostent subroutine and getipnodebyname subroutine.

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