Date: Tue, 12 Dec 2006 14:58:15 +0100 From: Max Laier <max@love2party.net> To: freebsd-net@freebsd.org Cc: "Bjoern A. Zeeb" <bzeeb-lists@lists.zabbadoz.net> Subject: Re: ip6_sprintf patch Message-ID: <200612121458.21401.max@love2party.net> In-Reply-To: <20061212111134.J91892@maildrop.int.zabbadoz.net> References: <20061212111134.J91892@maildrop.int.zabbadoz.net>
next in thread | previous in thread | raw e-mail | index | archive | help
[-- Attachment #1 --] On Tuesday 12 December 2006 13:22, Bjoern A. Zeeb wrote: > Hi, > > I have a patch sitting around for quite some time that I'd like to > commit if noone has any objections. It tries to print the addresses > in a more common/readable format eliminating leading zeros like > in :0001 -> :1. > > You can also fetch it from here: > http://sources.zabbadoz.net/freebsd/ipv6/patches/20060611-01.diff > > ! > ! http://perforce.freebsd.org/chv.cgi?CH=98978 > ! > ==== //depot/user/bz/fast_ipsec/src/sys/netinet6/in6.c#4 - > /local/building/freebsd/p4/v6_fast_ipsec/src/sys/netinet6/in6.c ==== > --- /tmp/tmp.47236.0 Sun Jun 11 11:48:05 2006 > +++ /local/building/freebsd/p4/v6_fast_ipsec/src/sys/netinet6/in6.c Sun > Jun 11 11:47:16 2006 @@ -1852,7 +1852,7 @@ > char *cp; > const u_int16_t *a = (const u_int16_t *)addr; > const u_int8_t *d; > - int dcolon = 0; > + int dcolon = 0, zero = 0; > > cp = ip6buf; > > @@ -1880,14 +1880,31 @@ > continue; > } > d = (const u_char *)a; > - *cp++ = digits[*d >> 4]; > - *cp++ = digits[*d++ & 0xf]; > - *cp++ = digits[*d >> 4]; > - *cp++ = digits[*d & 0xf]; > + /* Try to eliminate leading zeros in printout like in :0001. */ > + zero = 1; > + *cp = digits[*d >> 4]; > + if (*cp != '0') { > + zero = 0; > + cp++; > + } > + *cp = digits[*d++ & 0xf]; > + if (zero == 0 || (*cp != '0')) { > + zero = 0; > + cp++; > + } > + *cp = digits[*d >> 4]; > + if (zero == 0 || (*cp != '0')) { > + zero = 0; > + cp++; > + } > + *cp = digits[*d & 0xf]; > + if (zero == 0 || (*cp != '0')) > + cp++; This last if is redundant as we check for "(u_int16_t)0" at the very begining. If we didn't, you should still get rid of the if-check here as we might otherwise have more than one "::" in the address. > *cp++ = ':'; > a++; > } > *--cp = '\0'; > + > return (ip6buf); > } Otherwise the diff seems fine. -- /"\ Best regards, | mlaier@freebsd.org \ / Max Laier | ICQ #67774661 X http://pf4freebsd.love2party.net/ | mlaier@EFnet / \ ASCII Ribbon Campaign | Against HTML Mail and News [-- Attachment #2 --] -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.5 (FreeBSD) iD8DBQBFfrV9XyyEoT62BG0RAlodAJ9Rc85Wk4q+0wLAXUwlsNxA4+Q0LgCfan/6 /0WWaZ/rhMHN3Oi8bgE1t5k= =BSp+ -----END PGP SIGNATURE-----
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200612121458.21401.max>
