[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <1224892008.3919.27.camel@johannes.berg>
Date: Sat, 25 Oct 2008 01:46:48 +0200
From: Johannes Berg <johannes@...solutions.net>
To: "David S. Miller" <davem@...emloft.net>
Cc: netdev <netdev@...r.kernel.org>
Subject: [PATCH] add %pM printf format specifier
This adds a new printf format specifier for the kernel, %pM,
to be used to print out MAC addresses. This has advantages
over the current print_mac scheme:
* no need for DECLARE_MAC_BUF
* can be used safely in statements that might be compiled
out without the print_mac call staying.
Signed-off-by: Johannes Berg <johannes@...solutions.net>
---
lib/vsprintf.c | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
--- everything.orig/lib/vsprintf.c 2008-10-25 01:21:54.000000000 +0200
+++ everything/lib/vsprintf.c 2008-10-25 01:24:15.000000000 +0200
@@ -581,6 +581,22 @@ static char *resource_string(char *buf,
return string(buf, end, sym, field_width, precision, flags);
}
+static char *mac_address(char *buf, char *end, u8 *addr, int field_width, int precision, int flags)
+{
+ /* room for 6 * two hex digits, 5 colons and trailing zero */
+ char mac[18];
+ char *p = mac, *pend = mac + sizeof(mac);
+ int i;
+
+ for (i=0; i < 6; i++) {
+ p = number(p, pend, addr[i], 16, 2, -1, SMALL | ZEROPAD);
+ *p++ = ':';
+ }
+ mac[17] = '\0';
+
+ return string(buf, end, mac, field_width, precision, flags);
+}
+
/*
* Show a '%p' thing. A kernel extension is that the '%p' is followed
* by an extra set of alphanumeric characters that are extended format
@@ -592,6 +608,8 @@ static char *resource_string(char *buf,
* - 'S' For symbolic direct pointers
* - 'R' For a struct resource pointer, it prints the range of
* addresses (not the name nor the flags)
+ * - 'M' For a 6-byte MAC address, it prints the address in the
+ * usual colon-separated hex notation
*
* Note: The difference between 'S' and 'F' is that on ia64 and ppc64
* function pointers are really function descriptors, which contain a
@@ -607,6 +625,8 @@ static char *pointer(const char *fmt, ch
return symbol_string(buf, end, ptr, field_width, precision, flags);
case 'R':
return resource_string(buf, end, ptr, field_width, precision, flags);
+ case 'M':
+ return mac_address(buf, end, ptr, field_width, precision, flags);
}
flags |= SMALL;
if (field_width == -1) {
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Powered by blists - more mailing lists