git: 9front

Download patch

ref: 088b1bd04af5c83f6bb17262e756625ddb4e52d5
parent: c2ff936c5e35bd204411e5170686fb1754b424c8
author: cinap_lenrek <cinap_lenrek@gmx.de>
date: Mon Apr 1 23:48:10 EDT 2013

ape: inet_pton() parse dotted address to IPv4 mapped addresses for AF_INET6

--- a/sys/src/ape/lib/bsd/inet_pton.c
+++ b/sys/src/ape/lib/bsd/inet_pton.c
@@ -31,7 +31,7 @@
 int
 inet_pton(int af, char *src, void *dst)
 {
-	int i, elipsis = 0;
+	int i, v4 = 1, elipsis = 0;
 	unsigned char *to;
 	unsigned long x;
 	char *p, *op;
@@ -52,6 +52,16 @@
 		op = p;
 		x = strtoul(p, &p, 16);
 
+		if(*p == '.' || (*p == 0 && i == 0)){	/* ends with v4? */
+			struct in_addr in;
+
+			if(i > 16-4 || inet_aton(op, &in) == 0)
+				return 0;		/* parse error */
+
+			memmove(to+i, (unsigned char*)&in.s_addr, 4);
+			i += 4;
+			break;
+		}
 		if(x != (unsigned short)x || *p != ':' && !delimchar(*p))
 			return 0;			/* parse error */
 
@@ -58,6 +68,7 @@
 		to[i] = x>>8;
 		to[i+1] = x;
 		if(*p == ':'){
+			v4 = 0;
 			if(*++p == ':'){	/* :: is elided zero short(s) */
 				if (elipsis)
 					return 0;	/* second :: */
@@ -73,5 +84,7 @@
 		memmove(&to[elipsis+16-i], &to[elipsis], i-elipsis);
 		memset(&to[elipsis], 0, 16-i);
 	}
+	if(v4)
+		to[10] = to[11] = 0xff;
 	return 1;
 }
--