[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Sun, 26 Oct 2008 09:30:22 +0100
From: Johannes Berg <johannes@...solutions.net>
To: David Miller <davem@...emloft.net>
Cc: anders@...uras.de, netdev@...r.kernel.org
Subject: Re: [PATCH] add %pM printf format specifier
On Sun, 2008-10-26 at 09:21 +0100, Johannes Berg wrote:
> Of course, actually adding, say, %p4 and %p6 would be trivial, but
> making lots of code use it so it's useful would be another mass
> conversion I'm not too keen to do again right away :)
Actually... At least for ipv6 that isn't true, just do something like
this:
@@ include/linux/kernel.h
-#define NIP6(addr) \
-...
+#define NIP6(addr) &addr
-#define NIP6_FMT "%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x"
-#define NIP6_SEQFMT "%04x%04x%04x%04x%04x%04x%04x%04x"
+#define NIP6_FMT "%p6"
+#define NIP6_SEQFMT "%#p6"
and then add the correct stuff to pointer() in lib/vsprintf.c, something
like
static char *ip6_string(char *buf, char *end, be16 *addr, int field_width, int precision, int flags)
{
char ip6[8*5];
char *p = ip6;
int i;
u16 tmp;
for (i=0; i<7; i++) {
tmp = cpu_to_le16(addr[i]);
p = pack_hex_byte(p, tmp >> 8);
p = pack_hex_byte(p, tmp & 0xFF);
if (!(flags & SPECIAL))
*p++ = ':';
}
tmp = cpu_to_le16(addr[7]);
p = pack_hex_byte(p, tmp >> 8);
p = pack_hex_byte(p, tmp & 0xFF);
*p = '\0';
return string(buf, end, ip6, field_width, precision, flags & ~SPECIAL);
}
Download attachment "signature.asc" of type "application/pgp-signature" (837 bytes)
Powered by blists - more mailing lists