ip6_sprintf patch
Max Laier
max at love2party.net
Tue Dec 12 06:00:32 PST 2006
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 at freebsd.org
\ / Max Laier | ICQ #67774661
X http://pf4freebsd.love2party.net/ | mlaier at EFnet
/ \ ASCII Ribbon Campaign | Against HTML Mail and News
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 187 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-net/attachments/20061212/85bcc525/attachment.pgp
More information about the freebsd-net
mailing list