shithub: riscv

Download patch

ref: 7a54873252a6e8a55dd296ee155469e6ffbdd475
parent: de349cf9b06c155a89675e2b453a518e43808e81
author: cinap_lenrek <[email protected]>
date: Fri Dec 26 04:34:30 EST 2014

libip: skip ipv6 loopback address (thanks mischief)

--- a/sys/src/libip/myipaddr.c
+++ b/sys/src/libip/myipaddr.c
@@ -14,6 +14,12 @@
 	0xff, 0xff, 0xff, 0xff,
 	0xff, 0, 0, 0
 };
+static uchar loopback6[IPaddrlen] = {
+	0, 0, 0, 0,
+	0, 0, 0, 0,
+	0, 0, 0, 0,
+	0, 0, 0, 1
+};
 
 // find first ip addr that isn't the friggin loopback address
 // unless there are no others
@@ -28,14 +34,21 @@
 	ifc = readipifc(net, ifc, -1);
 	for(nifc = ifc; nifc; nifc = nifc->next)
 		for(lifc = nifc->lifc; lifc; lifc = lifc->next){
+			/* unspecified */
+			if(ipcmp(lifc->ip, IPnoaddr) == 0)
+				continue;
+
+			/* ipv6 loopback */
+			if(ipcmp(lifc->ip, loopback6) == 0)
+				continue;
+
+			/* ipv4 loopback */
 			maskip(lifc->ip, loopbackmask, mynet);
-			if(ipcmp(mynet, loopbacknet) == 0){
+			if(ipcmp(mynet, loopbacknet) == 0)
 				continue;
-			}
-			if(ipcmp(lifc->ip, IPnoaddr) != 0){
-				ipmove(ip, lifc->ip);
-				return 0;
-			}
+
+			ipmove(ip, lifc->ip);
+			return 0;
 		}
 	ipmove(ip, IPnoaddr);
 	return -1;