diff options
author | Harvey Harrison <harvey.harrison@gmail.com> | 2008-10-28 19:04:44 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2008-10-28 19:04:44 -0400 |
commit | 689afa7da106032a3e859ae35494f80dd6eac640 (patch) | |
tree | 470f00c94ff2f179c6b0405c4726b92a51e7110a /lib | |
parent | 3a2dfbe8acb154905fdc2fd03ec56df42e6c4cc4 (diff) |
printk: add %p6 format specifier for IPv6 addresses
Takes a pointer to a IPv6 address and formats it in the usual
colon-separated hex format:
xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx
Each 16 bit word is printed in network-endian byteorder.
%#p6 is also supported and will omit the colons.
%p6 is a replacement for NIP6_FMT and NIP6()
%#p6 is a replacement for NIP6_SEQFMT and NIP6()
Note that NIP6() took a struct in6_addr whereas this takes a pointer
to a struct in6_addr.
Signed-off-by: Harvey Harrison <harvey.harrison@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/vsprintf.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/vsprintf.c b/lib/vsprintf.c index 0deaaaf2b14e..cb5bc04ff82b 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c | |||
@@ -598,6 +598,24 @@ static char *mac_address_string(char *buf, char *end, u8 *addr, int field_width, | |||
598 | return string(buf, end, mac_addr, field_width, precision, flags & ~SPECIAL); | 598 | return string(buf, end, mac_addr, field_width, precision, flags & ~SPECIAL); |
599 | } | 599 | } |
600 | 600 | ||
601 | static char *ip6_addr_string(char *buf, char *end, u8 *addr, int field_width, | ||
602 | int precision, int flags) | ||
603 | { | ||
604 | char ip6_addr[8 * 5]; /* (8 * 4 hex digits), 7 colons and trailing zero */ | ||
605 | char *p = ip6_addr; | ||
606 | int i; | ||
607 | |||
608 | for (i = 0; i < 8; i++) { | ||
609 | p = pack_hex_byte(p, addr[2 * i]); | ||
610 | p = pack_hex_byte(p, addr[2 * i + 1]); | ||
611 | if (!(flags & SPECIAL) && i != 7) | ||
612 | *p++ = ':'; | ||
613 | } | ||
614 | *p = '\0'; | ||
615 | |||
616 | return string(buf, end, ip6_addr, field_width, precision, flags & ~SPECIAL); | ||
617 | } | ||
618 | |||
601 | /* | 619 | /* |
602 | * Show a '%p' thing. A kernel extension is that the '%p' is followed | 620 | * Show a '%p' thing. A kernel extension is that the '%p' is followed |
603 | * by an extra set of alphanumeric characters that are extended format | 621 | * by an extra set of alphanumeric characters that are extended format |
@@ -611,6 +629,8 @@ static char *mac_address_string(char *buf, char *end, u8 *addr, int field_width, | |||
611 | * addresses (not the name nor the flags) | 629 | * addresses (not the name nor the flags) |
612 | * - 'M' For a 6-byte MAC address, it prints the address in the | 630 | * - 'M' For a 6-byte MAC address, it prints the address in the |
613 | * usual colon-separated hex notation | 631 | * usual colon-separated hex notation |
632 | * - '6' For a IPv6 address prints the address in network-ordered 16 bit hex | ||
633 | * with colon separators | ||
614 | * | 634 | * |
615 | * Note: The difference between 'S' and 'F' is that on ia64 and ppc64 | 635 | * Note: The difference between 'S' and 'F' is that on ia64 and ppc64 |
616 | * function pointers are really function descriptors, which contain a | 636 | * function pointers are really function descriptors, which contain a |
@@ -628,6 +648,8 @@ static char *pointer(const char *fmt, char *buf, char *end, void *ptr, int field | |||
628 | return resource_string(buf, end, ptr, field_width, precision, flags); | 648 | return resource_string(buf, end, ptr, field_width, precision, flags); |
629 | case 'M': | 649 | case 'M': |
630 | return mac_address_string(buf, end, ptr, field_width, precision, flags); | 650 | return mac_address_string(buf, end, ptr, field_width, precision, flags); |
651 | case '6': | ||
652 | return ip6_addr_string(buf, end, ptr, field_width, precision, flags); | ||
631 | } | 653 | } |
632 | flags |= SMALL; | 654 | flags |= SMALL; |
633 | if (field_width == -1) { | 655 | if (field_width == -1) { |