diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/vsprintf.c | 48 |
1 files changed, 42 insertions, 6 deletions
diff --git a/lib/vsprintf.c b/lib/vsprintf.c index 3b8aeec4e327..af4aaa6c36f3 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c | |||
@@ -681,24 +681,55 @@ static char *mac_address_string(char *buf, char *end, u8 *addr, | |||
681 | char mac_addr[sizeof("xx:xx:xx:xx:xx:xx")]; | 681 | char mac_addr[sizeof("xx:xx:xx:xx:xx:xx")]; |
682 | char *p = mac_addr; | 682 | char *p = mac_addr; |
683 | int i; | 683 | int i; |
684 | char separator; | ||
685 | |||
686 | if (fmt[1] == 'F') { /* FDDI canonical format */ | ||
687 | separator = '-'; | ||
688 | } else { | ||
689 | separator = ':'; | ||
690 | } | ||
684 | 691 | ||
685 | for (i = 0; i < 6; i++) { | 692 | for (i = 0; i < 6; i++) { |
686 | p = pack_hex_byte(p, addr[i]); | 693 | p = pack_hex_byte(p, addr[i]); |
687 | if (fmt[0] == 'M' && i != 5) | 694 | if (fmt[0] == 'M' && i != 5) |
688 | *p++ = ':'; | 695 | *p++ = separator; |
689 | } | 696 | } |
690 | *p = '\0'; | 697 | *p = '\0'; |
691 | 698 | ||
692 | return string(buf, end, mac_addr, spec); | 699 | return string(buf, end, mac_addr, spec); |
693 | } | 700 | } |
694 | 701 | ||
695 | static char *ip4_string(char *p, const u8 *addr, bool leading_zeros) | 702 | static char *ip4_string(char *p, const u8 *addr, const char *fmt) |
696 | { | 703 | { |
697 | int i; | 704 | int i; |
698 | 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 | } | ||
699 | for (i = 0; i < 4; i++) { | 730 | for (i = 0; i < 4; i++) { |
700 | char temp[3]; /* hold each IP quad in reverse order */ | 731 | char temp[3]; /* hold each IP quad in reverse order */ |
701 | int digits = put_dec_trunc(temp, addr[i]) - temp; | 732 | int digits = put_dec_trunc(temp, addr[index]) - temp; |
702 | if (leading_zeros) { | 733 | if (leading_zeros) { |
703 | if (digits < 3) | 734 | if (digits < 3) |
704 | *p++ = '0'; | 735 | *p++ = '0'; |
@@ -710,6 +741,7 @@ static char *ip4_string(char *p, const u8 *addr, bool leading_zeros) | |||
710 | *p++ = temp[digits]; | 741 | *p++ = temp[digits]; |
711 | if (i < 3) | 742 | if (i < 3) |
712 | *p++ = '.'; | 743 | *p++ = '.'; |
744 | index += step; | ||
713 | } | 745 | } |
714 | *p = '\0'; | 746 | *p = '\0'; |
715 | 747 | ||
@@ -789,7 +821,7 @@ static char *ip6_compressed_string(char *p, const char *addr) | |||
789 | if (useIPv4) { | 821 | if (useIPv4) { |
790 | if (needcolon) | 822 | if (needcolon) |
791 | *p++ = ':'; | 823 | *p++ = ':'; |
792 | p = ip4_string(p, &in6.s6_addr[12], false); | 824 | p = ip4_string(p, &in6.s6_addr[12], "I4"); |
793 | } | 825 | } |
794 | *p = '\0'; | 826 | *p = '\0'; |
795 | 827 | ||
@@ -829,7 +861,7 @@ static char *ip4_addr_string(char *buf, char *end, const u8 *addr, | |||
829 | { | 861 | { |
830 | char ip4_addr[sizeof("255.255.255.255")]; | 862 | char ip4_addr[sizeof("255.255.255.255")]; |
831 | 863 | ||
832 | ip4_string(ip4_addr, addr, fmt[0] == 'i'); | 864 | ip4_string(ip4_addr, addr, fmt); |
833 | 865 | ||
834 | return string(buf, end, ip4_addr, spec); | 866 | return string(buf, end, ip4_addr, spec); |
835 | } | 867 | } |
@@ -896,12 +928,15 @@ static char *uuid_string(char *buf, char *end, const u8 *addr, | |||
896 | * - 'M' For a 6-byte MAC address, it prints the address in the | 928 | * - 'M' For a 6-byte MAC address, it prints the address in the |
897 | * usual colon-separated hex notation | 929 | * usual colon-separated hex notation |
898 | * - 'm' For a 6-byte MAC address, it prints the hex address without colons | 930 | * - 'm' For a 6-byte MAC address, it prints the hex address without colons |
931 | * - 'MF' For a 6-byte MAC FDDI address, it prints the address | ||
932 | * with a dash-separated hex notation | ||
899 | * - 'I' [46] for IPv4/IPv6 addresses printed in the usual way | 933 | * - 'I' [46] for IPv4/IPv6 addresses printed in the usual way |
900 | * IPv4 uses dot-separated decimal without leading 0's (1.2.3.4) | 934 | * IPv4 uses dot-separated decimal without leading 0's (1.2.3.4) |
901 | * IPv6 uses colon separated network-order 16 bit hex with leading 0's | 935 | * IPv6 uses colon separated network-order 16 bit hex with leading 0's |
902 | * - 'i' [46] for 'raw' IPv4/IPv6 addresses | 936 | * - 'i' [46] for 'raw' IPv4/IPv6 addresses |
903 | * IPv6 omits the colons (01020304...0f) | 937 | * IPv6 omits the colons (01020304...0f) |
904 | * 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 | ||
905 | * - 'I6c' for IPv6 addresses printed as specified by | 940 | * - 'I6c' for IPv6 addresses printed as specified by |
906 | * http://tools.ietf.org/html/draft-ietf-6man-text-addr-representation-00 | 941 | * http://tools.ietf.org/html/draft-ietf-6man-text-addr-representation-00 |
907 | * - '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 |
@@ -939,6 +974,7 @@ static char *pointer(const char *fmt, char *buf, char *end, void *ptr, | |||
939 | return resource_string(buf, end, ptr, spec, fmt); | 974 | return resource_string(buf, end, ptr, spec, fmt); |
940 | case 'M': /* Colon separated: 00:01:02:03:04:05 */ | 975 | case 'M': /* Colon separated: 00:01:02:03:04:05 */ |
941 | case 'm': /* Contiguous: 000102030405 */ | 976 | case 'm': /* Contiguous: 000102030405 */ |
977 | /* [mM]F (FDDI, bit reversed) */ | ||
942 | return mac_address_string(buf, end, ptr, spec, fmt); | 978 | return mac_address_string(buf, end, ptr, spec, fmt); |
943 | case 'I': /* Formatted IP supported | 979 | case 'I': /* Formatted IP supported |
944 | * 4: 1.2.3.4 | 980 | * 4: 1.2.3.4 |