aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJoe Perches <joe@perches.com>2010-01-13 23:23:30 -0500
committerDavid S. Miller <davem@davemloft.net>2010-01-13 23:23:30 -0500
commit0159f24ee764927bf44c1a25473bd4517febd21c (patch)
tree752c52fb40f1bd77783812d14a84638cad0df594 /lib
parent3ccd4c6167d3b39d52631767ebbf8b5677c5855d (diff)
lib/vsprintf.c: Add IPV4 options %pI4[hnbl] for host, network, big and little endian
This should allow the removal of the #defines and uses of NIPQUAD and NIPQUAD_FMT Signed-off-by: Joe Perches <joe@perches.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'lib')
-rw-r--r--lib/vsprintf.c36
1 files changed, 31 insertions, 5 deletions
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index e83e3e79a989..add0446dd921 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -699,13 +699,37 @@ static char *mac_address_string(char *buf, char *end, u8 *addr,
699 return string(buf, end, mac_addr, spec); 699 return string(buf, end, mac_addr, spec);
700} 700}
701 701
702static char *ip4_string(char *p, const u8 *addr, bool leading_zeros) 702static char *ip4_string(char *p, const u8 *addr, const char *fmt)
703{ 703{
704 int i; 704 int i;
705 705 bool leading_zeros = (fmt[0] == 'i');
706 int index;
707 int step;
708
709 switch (fmt[2]) {
710 case 'h':
711#ifdef __BIG_ENDIAN
712 index = 0;
713 step = 1;
714#else
715 index = 3;
716 step = -1;
717#endif
718 break;
719 case 'l':
720 index = 3;
721 step = -1;
722 break;
723 case 'n':
724 case 'b':
725 default:
726 index = 0;
727 step = 1;
728 break;
729 }
706 for (i = 0; i < 4; i++) { 730 for (i = 0; i < 4; i++) {
707 char temp[3]; /* hold each IP quad in reverse order */ 731 char temp[3]; /* hold each IP quad in reverse order */
708 int digits = put_dec_trunc(temp, addr[i]) - temp; 732 int digits = put_dec_trunc(temp, addr[index]) - temp;
709 if (leading_zeros) { 733 if (leading_zeros) {
710 if (digits < 3) 734 if (digits < 3)
711 *p++ = '0'; 735 *p++ = '0';
@@ -717,6 +741,7 @@ static char *ip4_string(char *p, const u8 *addr, bool leading_zeros)
717 *p++ = temp[digits]; 741 *p++ = temp[digits];
718 if (i < 3) 742 if (i < 3)
719 *p++ = '.'; 743 *p++ = '.';
744 index += step;
720 } 745 }
721 *p = '\0'; 746 *p = '\0';
722 747
@@ -796,7 +821,7 @@ static char *ip6_compressed_string(char *p, const char *addr)
796 if (useIPv4) { 821 if (useIPv4) {
797 if (needcolon) 822 if (needcolon)
798 *p++ = ':'; 823 *p++ = ':';
799 p = ip4_string(p, &in6.s6_addr[12], false); 824 p = ip4_string(p, &in6.s6_addr[12], "I4");
800 } 825 }
801 *p = '\0'; 826 *p = '\0';
802 827
@@ -836,7 +861,7 @@ static char *ip4_addr_string(char *buf, char *end, const u8 *addr,
836{ 861{
837 char ip4_addr[sizeof("255.255.255.255")]; 862 char ip4_addr[sizeof("255.255.255.255")];
838 863
839 ip4_string(ip4_addr, addr, fmt[0] == 'i'); 864 ip4_string(ip4_addr, addr, fmt);
840 865
841 return string(buf, end, ip4_addr, spec); 866 return string(buf, end, ip4_addr, spec);
842} 867}
@@ -911,6 +936,7 @@ static char *uuid_string(char *buf, char *end, const u8 *addr,
911 * - 'i' [46] for 'raw' IPv4/IPv6 addresses 936 * - 'i' [46] for 'raw' IPv4/IPv6 addresses
912 * IPv6 omits the colons (01020304...0f) 937 * IPv6 omits the colons (01020304...0f)
913 * IPv4 uses dot-separated decimal with leading 0's (010.123.045.006) 938 * IPv4 uses dot-separated decimal with leading 0's (010.123.045.006)
939 * - '[Ii]4[hnbl]' IPv4 addresses in host, network, big or little endian order
914 * - 'I6c' for IPv6 addresses printed as specified by 940 * - 'I6c' for IPv6 addresses printed as specified by
915 * http://www.ietf.org/id/draft-kawamura-ipv6-text-representation-03.txt 941 * http://www.ietf.org/id/draft-kawamura-ipv6-text-representation-03.txt
916 * - 'U' For a 16 byte UUID/GUID, it prints the UUID/GUID in the form 942 * - 'U' For a 16 byte UUID/GUID, it prints the UUID/GUID in the form