shithub: mc

Download patch

ref: 526479d1064ab5daadf7b2a1aad5a00153a5d455
parent: 23223a7626a6ccea0598937a94d15709afd0eb20
author: Ori Bernstein <ori@eigenstate.org>
date: Sun Jun 21 19:17:01 EDT 2015

Add ipv6 support to dial.

    Currently untested.

--- a/libstd/dial+posixy.myr
+++ b/libstd/dial+posixy.myr
@@ -31,7 +31,9 @@
 /* takes a plan 9 style dial string */
 const dial = {str
 	var proto, host, port
-	var sa : sys.sockaddr_in	/* we only support inet sockets right now.. ugh. */
+	var sa4 : sys.sockaddr_in	/* we only support inet sockets right now.. ugh. */
+	var sa6 : sys.sockaddr_in6	/* we only support inet sockets right now.. ugh. */
+	var sa	: sys.sockaddr#
 	var sock
 
 	match parsedial(str)
@@ -41,19 +43,23 @@
 
 	match getaddr(host)
 	| `Ipv4 bits:
-		sa.fam = sys.Afinet
-		sa.addr = bits
-		sa.port = hosttonet(port)
+		sa4.fam = sys.Afinet
+		sa4.addr = bits
+		sa4.port = hosttonet(port)
+		sa = &sa4 castto(sys.sockaddr#)
 	| `Ipv6 bits:
-		-> `Fail "ipv6 not yet supported"
+		sa6.fam = sys.Afinet6
+		sa6.addr = bits
+		sa6.port = hosttonet(port)
+		sa = &sa6 castto(sys.sockaddr#)
 	;;
-
 	sock = sys.socket(sa.fam, proto, 0)
+
 	if sock < 0
 		-> `Fail "failed to connect to socket"
 	;;
 	var err
-	err = sys.connect(sock, (&sa) castto(sys.sockaddr#), sizeof(sys.sockaddr_in))
+	err = sys.connect(sock, sa, sizeof(sys.sockaddr_in))
 	if err < 0
 		sys.close(sock)
 		-> `Fail "Failed to bind socket"
--- a/libstd/sys+linux-x64.myr
+++ b/libstd/sys+linux-x64.myr
@@ -109,6 +109,13 @@
 		zero	: byte[8]
 	;;
 
+	type sockaddr_in6 = struct
+		fam	: sockfam
+		port	: uint16
+		addr	: byte[16]
+		scope	: uint32
+	;;
+
 	type sockaddr_storage = struct
 		fam	: sockfam
 		__align	: uint32