summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrank Smit <frank@61924.nl>2020-10-25 15:50:09 +0100
committerFrank Smit <frank@61924.nl>2020-10-25 16:19:02 +0100
commita2ef6bfcd8de0ae9f7f2df2fcdd692bde6ea422c (patch)
treec93b0f73db10552cdf4f8e978113a53411f9f3d3
parentde0a04474a050a5b877ccc9be2381b870c17e222 (diff)
downloadmc-a2ef6bfcd8de0ae9f7f2df2fcdd692bde6ea422c.tar.gz
Let dnsconnect handle IPv6.
-rw-r--r--lib/std/resolve+posixy.myr41
1 files changed, 23 insertions, 18 deletions
diff --git a/lib/std/resolve+posixy.myr b/lib/std/resolve+posixy.myr
index 119608d..3bc279b 100644
--- a/lib/std/resolve+posixy.myr
+++ b/lib/std/resolve+posixy.myr
@@ -276,31 +276,36 @@ const dnsresolve = {host, rt
}
const dnsconnect = {ns
- match ns
- | `Ipv4 addr: -> dnsconnectv4(addr)
- | `Ipv6 addr: die("don't support ipv6 yet\n")
- ;;
-}
-
-const dnsconnectv4 = {addr
- var sa : sys.sockaddr_in
- var s
+ var sa4 : sys.sockaddr_in
+ var sa6 : sys.sockaddr_in6
+ var sa : sys.sockaddr#
+ var sock, sz
var status
+ var port = 53
- s = sys.socket(sys.Afinet, sys.Sockdgram, 0)
- if s < 0
+ match ns
+ | `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)
+ ;;
+
+ 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