From: Joe Perches <joe@perches.com>
To: Alexey Dobriyan <adobriyan@gmail.com>
Cc: davem@davemloft.net, netdev@vger.kernel.org,
Robert Olsson <robert.olsson@its.uu.se>
Subject: Re: [PATCH] pktgen: use %pI6c for printing IPv6 addresses
Date: Tue, 03 May 2011 16:25:13 -0700 [thread overview]
Message-ID: <1304465113.1788.48.camel@Joe-Laptop> (raw)
In-Reply-To: <20110503212340.GA25293@p183>
On Wed, 2011-05-04 at 00:23 +0300, Alexey Dobriyan wrote:
> I don't know why %pI6 doesn't compress, but the format specifier is
> kernel-standard, so use it.
Hi again Alexey.
I doubt it matters but the old routine compresses the first
0 it finds rather than the longest consecutive 0 match so
the output could be a bit different.
given: "0:1:0:0:0:0:0:7"
old: "::1:0:0:0:0:0:7"
new: "0:1::7"
I think the patch is an improvement.
> -static unsigned int fmt_ip6(char *s, const char ip[16])
> -{
> - unsigned int len;
> - unsigned int i;
> - unsigned int temp;
> - unsigned int compressing;
> - int j;
> -
> - len = 0;
> - compressing = 0;
> - for (j = 0; j < 16; j += 2) {
> -
> -#ifdef V4MAPPEDPREFIX
> - if (j == 12 && !memcmp(ip, V4mappedprefix, 12)) {
> - inet_ntoa_r(*(struct in_addr *)(ip + 12), s);
> - temp = strlen(s);
> - return len + temp;
> - }
> -#endif
> - temp = ((unsigned long)(unsigned char)ip[j] << 8) +
> - (unsigned long)(unsigned char)ip[j + 1];
> - if (temp == 0) {
> - if (!compressing) {
> - compressing = 1;
> - if (j == 0) {
> - *s++ = ':';
> - ++len;
> - }
> - }
> - } else {
> - if (compressing) {
> - compressing = 0;
> - *s++ = ':';
> - ++len;
> - }
> - i = fmt_xlong(s, temp);
> - len += i;
> - s += i;
> - if (j < 14) {
> - *s++ = ':';
> - ++len;
> - }
> - }
> - }
> - if (compressing) {
> - *s++ = ':';
> - ++len;
> - }
> - *s = 0;
> - return len;
> -}
prev parent reply other threads:[~2011-05-03 23:25 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-05-03 21:23 [PATCH] pktgen: use %pI6c for printing IPv6 addresses Alexey Dobriyan
2011-05-03 22:11 ` Joe Perches
2011-05-08 22:50 ` David Miller
2011-05-03 23:25 ` Joe Perches [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1304465113.1788.48.camel@Joe-Laptop \
--to=joe@perches.com \
--cc=adobriyan@gmail.com \
--cc=davem@davemloft.net \
--cc=netdev@vger.kernel.org \
--cc=robert.olsson@its.uu.se \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox