SYNTAX

       #include "dnsresolv.h"

       int dns_ip4_packet(stralloc* out,const char* buf,unsigned int len);
       int dns_ip4_qualify(stralloc* out,stralloc* fqdn,const stralloc* udn);
       int dns_ip4(stralloc* out,stralloc* fqdn);

       int dns_ip6_packet(stralloc* out,const char* buf,unsigned int len);
       int dns_ip6_qualify(stralloc* out,stralloc* fqdn,const stralloc* udn);
       int dns_ip6(stralloc* out,stralloc* fqdn);

       int dns_mx(stralloc* out,stralloc* fqdn);
       int dns_mx_packet(stralloc* out,const char* buf,unsigned int len);

       void dns_name4_domain(char q[DNS_NAME4_DOMAIN],const char* ip[4]);
       int dns_name4(stralloc* out,const char* ip[4]);

       void dns_name6_domain(char q[DNS_NAME6_DOMAIN],const char* ip[16]);
       int dns_name6(stralloc* out,const char* ip[16]);

       int dns_name(stralloc* out,const char* ip[16]);
       int dns_name_packet(stralloc* out,const char* buf,unsigned int len);

       int dns_txt(stralloc* out,stralloc* fqdn);
       int dns_txt_packet(stralloc* out,const char* buf,unsigned int len);


DESCRIPTION

       dns_ip4_packet is a low-level component of dns_ip4, designed to support
       asynchronous DNS lookups.  It reads a DNS packet of length len from
       buf, extracts IP addresses from the answer section of the packet, puts
       the addresses into out.

       dns_ip4_qualify feeds the name udn through qualification and looks up
       4-byte IP addresses for the result. It puts the fully qualified domain
       name into fqdn, puts the concatenation of the IP addresses into out,
       and returns 0. If the domain does not exist in DNS, or has no IP
       addresses, out will be empty.

       dns_ip4 looks up 4-byte IP addresses for the fully-qualified domain
       name in fqdn. It puts the concatenation of the IP addresses into out
       and returns 0. If the domain does not exist in DNS, or has no IP
       addresses, out will be empty.  If fqdn is a dotted-decimal IP address,
       dns_ip4 puts that IP address into out without checking DNS. More
       generally, if fqdn is a dot-separated sequence of dotted-decimal IP
       addresses, dns_ip4 puts those IP addresses into out without checking
       DNS. Brackets may appear inside the dotted-decimal IP addresses; they
       are ignored.

       dns_ip6_packet is a low-level component of dns_ip6, designed to support
       asynchronous DNS lookups.  It reads a DNS packet of length len from
       buf, extracts IPv4 and IPv6 addresses from the answer section of the
       packet, puts the addresses into out, and returns 0 or -1 the same way
       and returns 0. If the domain does not exist in DNS, or has no IP
       addresses, out will be empty.  dns_ip6 also looks up 4-byte IPv4
       addresses and converts them into IPv4-mapped IPv6 addresses
       (::ffff:1.2.3.4) to provide easy backwards compatibility for IPv6
       applications.  If fqdn is an IPv6 address, dns_ip6 puts that IP address
       into out without checking DNS.  IPv4 addresses are also used directly
       without DNS lookup.

       dns_mx looks up MX records for the fully-qualified domain name in fqdn.
       It puts the MX records into out and returns 0.  Each MX record is a
       two-byte MX distance (big endian) followed by a \0-terminated dot-
       encoded domain name. If the domain does not exist in DNS, or has no MX
       records, out will be empty.

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

       dns_name4_domain is a low-level component of dns_name4.  It converts an
       IP address such as 1.2.3.4 into a domain name such as
       4.3.2.1.in-addr.arpa and places the packet-encoded domain name into q.
       q is zero terminated.  q must have space for DNS_NAME4_DOMAIN bytes.

       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.

       dns_name6_domain is a low-level component of dns_name6.  It converts an
       IP address such as 4321:0:1:2:3:4:567:89ab into a domain name such as
       b.a.9.8.7.6.5.0.4.0.0.0.3.0.0.0.2.0.0.0.1.0.0.0.0.0.0.0.1.2.3.4.ip6.arpa
       and places the packet-encoded domain name into q.  q is zero
       terminated.  q must have space for DNS_NAME6_DOMAIN bytes.

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

       dns_name looks up the domain name for the 16-byte IPv6 address in ip
       calling dns_name6.  In case a IPv4-mappped IPv6 address is recognized,
       it uses dns_name4.

       dns_name_packet is a low-level component of dns_name4 and dns_name6
       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.

       dns_txt looks up TXT records for the fully-qualified domain name in
       fqdn. It puts the concatenation of the TXT records into out and returns
       0.  If the domain does not exist in DNS, or has no TXT records, out
       ip4(3), ip6(3), dnsstub(3)

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

RETURN CODES

       The dns routines return 0 in case of a successful operation.  In case
       the DNS lookup fails or the routine runs out of memory, -1 is returned
       and setting errno appropriately.  In case of a failure, the respective
       output variables like out and fqdn  may or may not change.

SEE ALSO

       ip4(3), ip6(3), dnsstub(3)


                                                             qlibs:(dnsresolv)

Man(1) output converted with man2html