All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] add %pM printf format specifier
@ 2008-10-24 23:46 Johannes Berg
  2008-10-25  1:41 ` Joe Perches
  2008-10-25 17:44 ` Sven Anders
  0 siblings, 2 replies; 33+ messages in thread
From: Johannes Berg @ 2008-10-24 23:46 UTC (permalink / raw)
  To: David S. Miller; +Cc: netdev

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@sipsolutions.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) {



^ permalink raw reply	[flat|nested] 33+ messages in thread

end of thread, other threads:[~2008-10-28  8:06 UTC | newest]

Thread overview: 33+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-10-24 23:46 [PATCH] add %pM printf format specifier Johannes Berg
2008-10-25  1:41 ` Joe Perches
2008-10-25  8:00   ` Johannes Berg
2008-10-25 17:44 ` Sven Anders
2008-10-26  8:01   ` Johannes Berg
2008-10-26  8:03     ` David Miller
2008-10-26  8:21       ` Johannes Berg
2008-10-26  8:30         ` Johannes Berg
2008-10-26 19:01           ` Harvey Harrison
2008-10-26 19:33             ` Johannes Berg
2008-10-26 19:38               ` Harvey Harrison
2008-10-26 19:40                 ` Johannes Berg
2008-10-26 22:39                   ` [RFC PATCH] printk: add the %pM, %p4, %p6 format specifiers Harvey Harrison
2008-10-27  0:31                     ` [RFC PATCHv2] " Harvey Harrison
2008-10-27  1:21                       ` Frans Pop
2008-10-27  2:08                         ` H. Peter Anvin
2008-10-27  6:59                       ` Johannes Berg
2008-10-27 16:28                         ` Harvey Harrison
2008-10-27 19:38                           ` David Miller
2008-10-27 19:47                             ` Johannes Berg
2008-10-27 19:59                             ` [RFC PATCHv3] printk: add %pM format specifier for MAC addresses Harvey Harrison
2008-10-27 21:55                               ` Joe Perches
2008-10-27 22:46                                 ` David Miller
2008-10-27 22:47                               ` David Miller
2008-10-27 23:14                                 ` Harvey Harrison
2008-10-27 23:31                                   ` Alexey Dobriyan
2008-10-27 23:48                                   ` Joe Perches
2008-10-28  8:04                                     ` Johannes Berg
2008-10-27 23:55                                   ` David Miller
2008-10-28  0:05                                     ` Harvey Harrison
2008-10-28  0:22                                       ` Joe Perches
2008-10-28  8:06                                         ` Johannes Berg
2008-10-26  8:38         ` [PATCH] add %pM printf format specifier Johannes Berg

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.