Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 166231
b: refs/heads/master
c: eb78cd2
h: refs/heads/master
i:
  166229: d81cfaa
  166227: b304570
  166223: 4422622
v: v3
  • Loading branch information
Joe Perches authored and David S. Miller committed Sep 22, 2009
1 parent b109904 commit 950fb48
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 95acf7d7ed95fdb9bfd5b7a71752701a0e382bd9
refs/heads/master: eb78cd26b9b519d94e20ce9c0697e5056046669d
25 changes: 15 additions & 10 deletions trunk/lib/vsprintf.c
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ static char *ip4_string(char *p, const u8 *addr, bool leading_zeros)
return p;
}

static char *ip6_compressed_string(char *p, const struct in6_addr *addr)
static char *ip6_compressed_string(char *p, const char *addr)
{
int i;
int j;
Expand All @@ -683,7 +683,12 @@ static char *ip6_compressed_string(char *p, const struct in6_addr *addr)
u8 hi;
u8 lo;
bool needcolon = false;
bool useIPv4 = ipv6_addr_v4mapped(addr) || ipv6_addr_is_isatap(addr);
bool useIPv4;
struct in6_addr in6;

memcpy(&in6, addr, sizeof(struct in6_addr));

useIPv4 = ipv6_addr_v4mapped(&in6) || ipv6_addr_is_isatap(&in6);

memset(zerolength, 0, sizeof(zerolength));

Expand All @@ -695,7 +700,7 @@ static char *ip6_compressed_string(char *p, const struct in6_addr *addr)
/* find position of longest 0 run */
for (i = 0; i < range; i++) {
for (j = i; j < range; j++) {
if (addr->s6_addr16[j] != 0)
if (in6.s6_addr16[j] != 0)
break;
zerolength[i]++;
}
Expand All @@ -722,7 +727,7 @@ static char *ip6_compressed_string(char *p, const struct in6_addr *addr)
needcolon = false;
}
/* hex u16 without leading 0s */
word = ntohs(addr->s6_addr16[i]);
word = ntohs(in6.s6_addr16[i]);
hi = word >> 8;
lo = word & 0xff;
if (hi) {
Expand All @@ -741,19 +746,19 @@ static char *ip6_compressed_string(char *p, const struct in6_addr *addr)
if (useIPv4) {
if (needcolon)
*p++ = ':';
p = ip4_string(p, &addr->s6_addr[12], false);
p = ip4_string(p, &in6.s6_addr[12], false);
}

*p = '\0';
return p;
}

static char *ip6_string(char *p, const struct in6_addr *addr, const char *fmt)
static char *ip6_string(char *p, const char *addr, const char *fmt)
{
int i;
for (i = 0; i < 8; i++) {
p = pack_hex_byte(p, addr->s6_addr[2 * i]);
p = pack_hex_byte(p, addr->s6_addr[2 * i + 1]);
p = pack_hex_byte(p, *addr++);
p = pack_hex_byte(p, *addr++);
if (fmt[0] == 'I' && i != 7)
*p++ = ':';
}
Expand All @@ -768,9 +773,9 @@ static char *ip6_addr_string(char *buf, char *end, const u8 *addr,
char ip6_addr[sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:255.255.255.255")];

if (fmt[0] == 'I' && fmt[2] == 'c')
ip6_compressed_string(ip6_addr, (const struct in6_addr *)addr);
ip6_compressed_string(ip6_addr, addr);
else
ip6_string(ip6_addr, (const struct in6_addr *)addr, fmt);
ip6_string(ip6_addr, addr, fmt);

return string(buf, end, ip6_addr, spec);
}
Expand Down

0 comments on commit 950fb48

Please sign in to comment.