11.4 gethostbyaddr Function


11.4 gethostbyaddr Function

The function gethostbyaddr takes a binary IPv4 address and tries to find the hostname corresponding to that address. This is the reverse of gethostbyname .

#include <netdb.h>

struct hostent *gethostbyaddr (const char * addr , socklen_t len , int family );

Returns: non-null pointer if OK, NULL on error with h_errno set

This function returns a pointer to the same hostent structure that we described with gethostbyname . The field of interest in this structure is normally h_name , the canonical hostname.

The addr argument is not a char *, but is really a pointer to an in_addr structure containing the IPv4 address. len is the size of this structure: 4 for an IPv4 address. The family argument is AF_INET .

In terms of the DNS, gethostbyaddr queries a name server for a PTR record in the in-addr.arpa domain.



UNIX Network Programming Volume 1, Third Edition
Unix Network Programming, Volume 1: The Sockets Networking API (3rd Edition)
ISBN: 0131411551
EAN: 2147483647
Year: 2003
Pages: 441

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net