mailing list of musl libc
 help / color / mirror / code / Atom feed
From: orc <orc@sibserver.ru>
To: musl list <musl@lists.openwall.com>
Subject: [PATCH] inet_ntop() and ipv4 address
Date: Thu, 25 Jul 2013 12:21:27 +0800	[thread overview]
Message-ID: <20130725122127.4dcbf8de@sibserver.ru> (raw)

[-- 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;

             reply	other threads:[~2013-07-25  4:21 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-25  4:21 orc [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130725122127.4dcbf8de@sibserver.ru \
    --to=orc@sibserver.ru \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).