Langue: en

Autres versions - même langue

Version: 281782 (debian - 07/07/09)

Section: 3 (Bibliothèques de fonctions)


dns_name4 - IP address to host name


#include <dns.h>

dns_name4(&out, ip);
dns_name_packet(&out, buf, len);
dns_name4_domain(q, ip);

  stralloc out = {0};
  char ip[4];
  char q[DNS_NAME4_DOMAIN];
  char *buf;
  unsigned int len;


dns_name4 looks up the domain name for the 4-byte IP address in ip. It puts the (first) domain name into out and returns 0. If the relevant in-addr.arpa domain does not exist in DNS, or has no PTR records, out will be empty.

If dns_name4 has trouble with the DNS lookup or runs out of memory, it returns -1, setting errno appropriately. It may or may not change out.

dns_name_packet is a low-level component of dns_name4, designed to support asynchronous DNS lookups. It reads a DNS packet of length len from buf, extracts the first PTR record from the answer section of the packet, puts the result into out, and returns 0 or -1 the same way as dns_name4.

dns_name4_domain is another low-level component of dns_name4. It converts an IP address such as into a domain name such as and places the packet-encoded domain name into q.


dns_domain(3), dns_ip4(3), dns_ip4_qualify(3), dns_mx(3), dns_packet(3), dns_random(3), dns_transmit(3), dns_txt(3)