gethostbyaddr |
Prototype: |
#include <netdb.h>
struct hostent *gethostbyaddr(const char *addr, int len, int type);
|
General Description: |
Get all the names associated with the given IP address. (Refer to gethostbyname() for more details.) Network support for this system call varies. |
Return Value: |
(Refer to gethostbyname().) |
Parameters |
addr |
A pointer to the array of bytes representing the IP address (IPv4 or IPv6). |
len |
The number of bytes of the array. |
type |
The network type (IPv4 or IPv6). |
Possible Errors |
ENOTFOUND |
The specified host is unknown.NO_ADDRESS or NO_DATAThe requested name is valid but does not have an IP address. |
NO_RECOVERY |
A non-recoverable name server error occurred. |
EAGAIN |
A temporary error occurred on an authoritative name server. Try again later. |
Examples |
int i;
struct hostent *host;
struct in_addr addr;
inet_aton("224.0.0.1", &addr);
host = gethostbyaddr(&addr, sizeof(addr), PF_INET);
if ( host != NULL )
{
printf("Official name: %s\n", host->h_name);
for ( i = 0; host->h_aliases[i] != 0; i++ )
printf(" alias[%d]: %s\n", i+1,
host->h_aliases[i]);
}
else
perror("224.0.0.1");
|