From owner-freebsd-net@FreeBSD.ORG Tue Dec 12 12:25:29 2006 Return-Path: X-Original-To: freebsd-net@freebsd.org Delivered-To: freebsd-net@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 76CDA16A416 for ; Tue, 12 Dec 2006 12:25:29 +0000 (UTC) (envelope-from bzeeb-lists@lists.zabbadoz.net) Received: from transport.cksoft.de (transport.cksoft.de [62.111.66.27]) by mx1.FreeBSD.org (Postfix) with ESMTP id EA10B43CB8 for ; Tue, 12 Dec 2006 12:23:55 +0000 (GMT) (envelope-from bzeeb-lists@lists.zabbadoz.net) Received: from transport.cksoft.de (localhost [127.0.0.1]) by transport.cksoft.de (Postfix) with ESMTP id 535A420029C for ; Tue, 12 Dec 2006 13:25:12 +0100 (CET) Received: by transport.cksoft.de (Postfix, from userid 66) id AE0B31FFE7E; Tue, 12 Dec 2006 13:25:05 +0100 (CET) Received: from maildrop.int.zabbadoz.net (maildrop.int.zabbadoz.net [10.111.66.10]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.int.zabbadoz.net (Postfix) with ESMTP id 7C286444885 for ; Tue, 12 Dec 2006 12:22:12 +0000 (UTC) Date: Tue, 12 Dec 2006 12:22:12 +0000 (UTC) From: "Bjoern A. Zeeb" X-X-Sender: bz@maildrop.int.zabbadoz.net To: freebsd-net@freebsd.org Message-ID: <20061212111134.J91892@maildrop.int.zabbadoz.net> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Virus-Scanned: by AMaViS cksoft-s20020300-20031204bz on transport.cksoft.de Subject: ip6_sprintf patch X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 Dec 2006 12:25:29 -0000 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++; *cp++ = ':'; a++; } *--cp = '\0'; + return (ip6buf); } -- Bjoern A. Zeeb bzeeb at Zabbadoz dot NeT