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
--nextPart2462898.WnuSPXM266 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline 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=3D98978 > ! > =3D=3D=3D=3D //depot/user/bz/fast_ipsec/src/sys/netinet6/in6.c#4 - > /local/building/freebsd/p4/v6_fast_ipsec/src/sys/netinet6/in6.c =3D=3D=3D= =3D > --- /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 =3D (const u_int16_t *)addr; > const u_int8_t *d; > - int dcolon =3D 0; > + int dcolon =3D 0, zero =3D 0; > > cp =3D ip6buf; > > @@ -1880,14 +1880,31 @@ > continue; > } > d =3D (const u_char *)a; > - *cp++ =3D digits[*d >> 4]; > - *cp++ =3D digits[*d++ & 0xf]; > - *cp++ =3D digits[*d >> 4]; > - *cp++ =3D digits[*d & 0xf]; > + /* Try to eliminate leading zeros in printout like in :0001. */ > + zero =3D 1; > + *cp =3D digits[*d >> 4]; > + if (*cp !=3D '0') { > + zero =3D 0; > + cp++; > + } > + *cp =3D digits[*d++ & 0xf]; > + if (zero =3D=3D 0 || (*cp !=3D '0')) { > + zero =3D 0; > + cp++; > + } > + *cp =3D digits[*d >> 4]; > + if (zero =3D=3D 0 || (*cp !=3D '0')) { > + zero =3D 0; > + cp++; > + } > + *cp =3D digits[*d & 0xf]; > + if (zero =3D=3D 0 || (*cp !=3D '0')) > + cp++; This last if is redundant as we check for "(u_int16_t)0" at the very=20 begining. If we didn't, you should still get rid of the if-check here as=20 we might otherwise have more than one "::" in the address. > *cp++ =3D ':'; > a++; > } > *--cp =3D '\0'; > + > return (ip6buf); > } Otherwise the diff seems fine. =2D-=20 /"\ Best regards, | mlaier@freebsd.org \ / Max Laier | ICQ #67774661 X http://pf4freebsd.love2party.net/ | mlaier@EFnet / \ ASCII Ribbon Campaign | Against HTML Mail and News --nextPart2462898.WnuSPXM266 Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.5 (FreeBSD) iD8DBQBFfrV9XyyEoT62BG0RAlodAJ9Rc85Wk4q+0wLAXUwlsNxA4+Q0LgCfan/6 /0WWaZ/rhMHN3Oi8bgE1t5k= =BSp+ -----END PGP SIGNATURE----- --nextPart2462898.WnuSPXM266--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200612121458.21401.max>