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

* Re: [PATCH] inet_ntop() and ipv4 address
  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  7:42 ` Rich Felker
  2 siblings, 0 replies; 7+ messages in thread
From: orc @ 2013-07-25  4:36 UTC (permalink / raw)
  To: musl

On Thu, 25 Jul 2013 12:21:27 +0800
orc <orc@sibserver.ru> wrote:

> 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.

And my mistake: should be
!memcmp(a, buf, 10) && memcmp(a, buf, 14) &&
instead of !memcmp(a, buf, 10)

Sorry.


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

* Re: [PATCH] inet_ntop() and ipv4 address
  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  7:42 ` Rich Felker
  2 siblings, 1 reply; 7+ messages in thread
From: Rich Felker @ 2013-07-25  5:59 UTC (permalink / raw)
  To: musl

On Thu, Jul 25, 2013 at 12:21:27PM +0800, orc wrote:
> 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.

As I understand it, the "IPv4 compatible" addresses (::a.b.c.d) are
deprecated and have never actually been used in deployed IPv6. Only
the v4-mapped form (::ffff:a.b.c.d) is used/usable. For the most part,
supporting the useless form seems harmless, but there is one harmful
case: it looks like your code will wrongly convert :: to ::0.0.0.0
instead of plain ::. Is it worth trying to keep the "v4 compatible"
form supported and just special-casing ::, or should we just drop it?

Rich


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

* Re: [PATCH] inet_ntop() and ipv4 address
  2013-07-25  5:59 ` Rich Felker
@ 2013-07-25  6:42   ` orc
  2013-07-25  6:54     ` Rich Felker
  0 siblings, 1 reply; 7+ messages in thread
From: orc @ 2013-07-25  6:42 UTC (permalink / raw)
  To: musl

On Thu, 25 Jul 2013 01:59:13 -0400
Rich Felker <dalias@aerifal.cx> wrote:

> On Thu, Jul 25, 2013 at 12:21:27PM +0800, orc wrote:
> > 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.
> 
> As I understand it, the "IPv4 compatible" addresses (::a.b.c.d) are
> deprecated and have never actually been used in deployed IPv6. Only
> the v4-mapped form (::ffff:a.b.c.d) is used/usable. For the most part,
> supporting the useless form seems harmless, but there is one harmful
> case: it looks like your code will wrongly convert :: to ::0.0.0.0
> instead of plain ::. Is it worth trying to keep the "v4 compatible"
> form supported and just special-casing ::, or should we just drop it?
> 
> Rich

I think it's still worth supporting ::ffff:a.b.c.d form, just quote
from my vsftpd logs:
CONNECT: Client "::ffff:a00:203" # (for 10.0.2.3)
Same output of 'ss -tn' when someone connected to IPv6-only listening
socket. IPv4 compatible addresses I taken from glibc.
Wrong convert: see my next message. It was my fault.


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

* Re: [PATCH] inet_ntop() and ipv4 address
  2013-07-25  6:42   ` orc
@ 2013-07-25  6:54     ` Rich Felker
  2013-07-25  7:09       ` orc
  0 siblings, 1 reply; 7+ messages in thread
From: Rich Felker @ 2013-07-25  6:54 UTC (permalink / raw)
  To: musl

On Thu, Jul 25, 2013 at 02:42:12PM +0800, orc wrote:
> On Thu, 25 Jul 2013 01:59:13 -0400
> Rich Felker <dalias@aerifal.cx> wrote:
> 
> > On Thu, Jul 25, 2013 at 12:21:27PM +0800, orc wrote:
> > > 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.
> > 
> > As I understand it, the "IPv4 compatible" addresses (::a.b.c.d) are
> > deprecated and have never actually been used in deployed IPv6. Only
> > the v4-mapped form (::ffff:a.b.c.d) is used/usable. For the most part,
> > supporting the useless form seems harmless, but there is one harmful
> > case: it looks like your code will wrongly convert :: to ::0.0.0.0
> > instead of plain ::. Is it worth trying to keep the "v4 compatible"
> > form supported and just special-casing ::, or should we just drop it?
> 
> I think it's still worth supporting ::ffff:a.b.c.d form, just quote
> from my vsftpd logs:

Oh I agree the ::ffff:a.b.c.d form is worth supporting. I was asking
if there's any need to also support the ::a.b.c.d form, which would
require a special workaround for ::.

Rich


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

* Re: [PATCH] inet_ntop() and ipv4 address
  2013-07-25  6:54     ` Rich Felker
@ 2013-07-25  7:09       ` orc
  0 siblings, 0 replies; 7+ messages in thread
From: orc @ 2013-07-25  7:09 UTC (permalink / raw)
  To: musl

On Thu, 25 Jul 2013 02:54:33 -0400
Rich Felker <dalias@aerifal.cx> wrote:

> On Thu, Jul 25, 2013 at 02:42:12PM +0800, orc wrote:
> > On Thu, 25 Jul 2013 01:59:13 -0400
> > Rich Felker <dalias@aerifal.cx> wrote:
> > 
> > > On Thu, Jul 25, 2013 at 12:21:27PM +0800, orc wrote:
> > > > 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.
> > > 
> > > As I understand it, the "IPv4 compatible" addresses (::a.b.c.d)
> > > are deprecated and have never actually been used in deployed
> > > IPv6. Only the v4-mapped form (::ffff:a.b.c.d) is used/usable.
> > > For the most part, supporting the useless form seems harmless,
> > > but there is one harmful case: it looks like your code will
> > > wrongly convert :: to ::0.0.0.0 instead of plain ::. Is it worth
> > > trying to keep the "v4 compatible" form supported and just
> > > special-casing ::, or should we just drop it?
> > 
> > I think it's still worth supporting ::ffff:a.b.c.d form, just quote
> > from my vsftpd logs:
> 
> Oh I agree the ::ffff:a.b.c.d form is worth supporting. I was asking
> if there's any need to also support the ::a.b.c.d form, which would
> require a special workaround for ::.
> 
> Rich

If it needs hacks that don't worth implementing, then no. Can't
remember where I seen ::a.b.c.d last time.


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

* Re: [PATCH] inet_ntop() and ipv4 address
  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  7:42 ` Rich Felker
  2 siblings, 0 replies; 7+ messages in thread
From: Rich Felker @ 2013-07-25  7:42 UTC (permalink / raw)
  To: musl

On Thu, Jul 25, 2013 at 12:21:27PM +0800, orc wrote:
> 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.

I just committed a simplified version, as well as a bugfix for an
issue I noticed due to looking at this code again. Let me know if you
think anything still needs to be changed.

Rich


^ 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).