ref: a2ef6bfcd8de0ae9f7f2df2fcdd692bde6ea422c
parent: de0a04474a050a5b877ccc9be2381b870c17e222
author: Frank Smit <frank@61924.nl>
date: Sun Oct 25 11:50:09 EDT 2020
Let dnsconnect handle IPv6.
--- a/lib/std/resolve+posixy.myr
+++ b/lib/std/resolve+posixy.myr
@@ -276,31 +276,36 @@
}
const dnsconnect = {ns
+ var sa4 : sys.sockaddr_in
+ var sa6 : sys.sockaddr_in6
+ var sa : sys.sockaddr#
+ var sock, sz
+ var status
+ var port = 53
+
match ns
- | `Ipv4 addr: -> dnsconnectv4(addr)
- | `Ipv6 addr: die("don't support ipv6 yet\n")
+ | `Ipv4 bits:
+ sa4=[.fam=sys.Afinet, .addr=bits, .port=hosttonet(port)]
+ sa = (&sa4 : sys.sockaddr#)
+ sz = sizeof(sys.sockaddr_in)
+ | `Ipv6 bits:
+ sa6=[.fam=sys.Afinet6, .addr=bits, .port=hosttonet(port)]
+ sa = (&sa6 : sys.sockaddr#)
+ sz = sizeof(sys.sockaddr_in6)
;;
-}
-const dnsconnectv4 = {addr
- var sa : sys.sockaddr_in
- var s
- var status
-
- s = sys.socket(sys.Afinet, sys.Sockdgram, 0)
- if s < 0
+ sock = sys.socket(sa.fam, sys.Sockdgram, 0)
+ if sock < 0
-> -1
;;
- sa = [
- .fam = sys.Afinet,
- .port = hosttonet(53),
- .addr = addr,
- ]
- status = sys.connect(s, (&sa : sys.sockaddr#), sizeof(sys.sockaddr_in))
+
+ status = sys.connect(sock, sa, sz)
if status < 0
+ sys.close(sock)
-> -1
;;
- -> s
+
+ -> sock
}
const dnsquery = {srv, host, t