mailing list of musl libc
 help / color / mirror / code / Atom feed
* [PATCH] inet_ntop() and ipv4 address
@ 2013-07-25  4:21 orc
  2013-07-25  4:36 ` orc
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: orc @ 2013-07-25  4:21 UTC (permalink / raw)
  To: musl list

[-- Attachment #1: Type: text/plain, Size: 277 bytes --]

inet_ntop() does not embed plain ipv4 address at end (like
"::ffff:10.0.0.1"). This patch fixes it, but it is a bit ugly. Without
it is a bit harder to read logs of some daemons that support only one
address family socket binding and seeing output of 'ss -tn'. Adopt if
needed.

[-- Attachment #2: musl-0.9.10git-inet_ntop-ipv4.patch --]
[-- Type: application/octet-stream, Size: 1079 bytes --]

--- musl.o/src/network/inet_ntop.c
+++ musl/src/network/inet_ntop.c
@@ -18,14 +18,25 @@
 			return s;
 		break;
 	case AF_INET6:
+		memset(buf, 0, sizeof buf);
+		i = (!memcmp(a, buf, 10) &&
+		((a[10] == 0 && a[11] == 0) || (a[10] == 255 && a[11] == 255))) ? 1 : 0;
 		memset(buf, 'x', sizeof buf);
 		buf[sizeof buf-1]=0;
-		snprintf(buf, sizeof buf,
-			"%x:%x:%x:%x:%x:%x:%x:%x",
-			256*a[0]+a[1],256*a[2]+a[3],
-			256*a[4]+a[5],256*a[6]+a[7],
-			256*a[8]+a[9],256*a[10]+a[11],
-			256*a[12]+a[13],256*a[14]+a[15]);
+		if (i)
+			snprintf(buf, sizeof buf,
+				"%x:%x:%x:%x:%x:%x:%d.%d.%d.%d",
+				256*a[0]+a[1],256*a[2]+a[3],
+				256*a[4]+a[5],256*a[6]+a[7],
+				256*a[8]+a[9],256*a[10]+a[11],
+				a[12],a[13],a[14],a[15]);
+		else
+			snprintf(buf, sizeof buf,
+				"%x:%x:%x:%x:%x:%x:%x:%x",
+				256*a[0]+a[1],256*a[2]+a[3],
+				256*a[4]+a[5],256*a[6]+a[7],
+				256*a[8]+a[9],256*a[10]+a[11],
+				256*a[12]+a[13],256*a[14]+a[15]);
 		/* Replace longest /(^0|:)[:0]{2,}/ with "::" */
 		for (i=best=0, max=2; buf[i]; i++) {
 			if (i && buf[i] != ':') continue;

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2013-07-25  7:42 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-07-25  4:21 [PATCH] inet_ntop() and ipv4 address orc
2013-07-25  4:36 ` orc
2013-07-25  5:59 ` Rich Felker
2013-07-25  6:42   ` orc
2013-07-25  6:54     ` Rich Felker
2013-07-25  7:09       ` orc
2013-07-25  7:42 ` Rich Felker

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).