wahern / dns

dns.c: Single file non-blocking DNS C library without callbacks or external dependencies.
http://25thandclement.com/~william/projects/dns.c.html
MIT License
256 stars 64 forks source link

It doesn't work with IPv6 DNS servers #23

Open sjakub opened 6 years ago

sjakub commented 6 years ago

Hi.

I cannot get it to work with IPv6 DNS servers. Is this supported? I am using current master.

When I set only v6 DNS servers in my resolv.conf, the demo app refused to work:

$ ./dns show-hints
ZONE "."
        (1) [2001:4860:4860::8888]:53
$ ./dns send-query -q google.ca
querying 2001:4860:4860::8888 for google.ca IN AAAA
dns: (send_query:9433) dns_so_query: Address family not supported by protocol (97)

It works just fine with IPv4 DNS:

$ ./dns show-hints
ZONE "."
        (1) [8.8.8.8]:53
$ ./dns send-query -q google.ca
querying 8.8.8.8 for google.ca IN AAAA
;; [HEADER]
;;    qid : 53039
;;     qr : RESPONSE(1)
;; opcode : QUERY(0)
;;     aa : NON-AUTHORITATIVE(0)
;;     tc : NOT-TRUNCATED(0)
;;     rd : RECURSION-DESIRED(1)
;;     ra : RECURSION-ALLOWED(1)
;;  rcode : NOERROR(0)

;; [QUESTION:1]
;google.ca. IN AAAA

;; [ANSWER:1]
google.ca. 294 IN AAAA 2607:f8b0:400b:80e::2003

I also got it working in my application, by adding the DNS server name to hints with dns_hints_insert(), and using dns_res_submit() and dns_res_check(). It works if I provide IPv4 DNS address, but always returns 0 addresses when IPv6 DNS server is used.

I can also see that it creates an AF_INET socket in both cases, but only tries to call 'connect' when IPv4 DNS server is used.

Am I missing something?

sjakub commented 6 years ago

Oh, and it works just fine with the system resolver:

$ nslookup google.ca
Server:         2001:4860:4860::8888
Address:        2001:4860:4860::8888#53

Non-authoritative answer:
Name:   google.ca
Address: 172.217.1.3
Name:   google.ca
Address: 2607:f8b0:400b:80f::2003
sjakub commented 6 years ago

I actually got the 'dns' app working, by calling dns_resconf_setiface(resconf(), "::", 0);

I also tried resolve-stub method, which is more like what I use in my program. However, "./dns resolve-stub -q google.ca" also fails with v6 DNS server (by returning 0 addresses). Adding dns_resconf_setiface() call did not help :(

pspacek commented 4 years ago

I confirm the same problem. Any chance getting it fixed?