path: root/Documentation/printk-formats.txt
diff options
authorDaniel Borkmann <>2013-06-28 19:49:39 +0200
committerDavid S. Miller <>2013-07-01 23:22:13 -0700
commit1067964305df131ede2c08c2f3c9b3892640f1c6 (patch)
tree669ec54a6978c1301ea1003897fadd9b616879e4 /Documentation/printk-formats.txt
parent936faf6c4937c50048e5779f6e49cfce566048d3 (diff)
lib: vsprintf: add IPv4/v6 generic %p[Ii]S[pfs] format specifier
In order to avoid making code that deals with printing both, IPv4 and IPv6 addresses, unnecessary complicated as for example ... if (sa.sa_family == AF_INET6) printk("... %pI6 ...", ..sin6_addr); else printk("... %pI4 ...", ..sin_addr.s_addr); ... it would be better to introduce a format specifier that can deal with those kind of situations internally; just as we have a "struct sockaddr" for generic mapping into "struct sockaddr_in" or "struct sockaddr_in6" as e.g. done in "union sctp_addr". Then, we could reduce the above statement into something like: printk("... %pIS ..", &sockaddr); In case our pointer is NULL, pointer() then deals with that already at an earlier point in time internally. While we're at it, support for both %piS/%pIS, where 'S' stands for sockaddr, comes (almost) for free. Additionally to that, postfix specifiers 'p', 'f' and 's' are supported as suggested and initially implemented in 2009 by Joe Perches [1]. Handling of those additional specifiers orientate on the initial RFC that was proposed. Also we support IPv6 compressed format specified by 'c' and various other IPv4 extensions as stated in the documentation part. Likely, there are many other areas than just SCTP in the kernel to make use of this extension as well. [1] Signed-off-by: Daniel Borkmann <> CC: Joe Perches <> CC: Signed-off-by: David S. Miller <>
Diffstat (limited to 'Documentation/printk-formats.txt')
1 files changed, 32 insertions, 0 deletions
diff --git a/Documentation/printk-formats.txt b/Documentation/printk-formats.txt
index 3af5ae6c9c11..3e8cb73ac43c 100644
--- a/Documentation/printk-formats.txt
+++ b/Documentation/printk-formats.txt
@@ -121,6 +121,38 @@ IPv6 addresses:
print a compressed IPv6 address as described by
+IPv4/IPv6 addresses (generic, with port, flowinfo, scope):
+ %pIS or 0001:0002:0003:0004:0005:0006:0007:0008
+ %piS or 00010002000300040005000600070008
+ %pISc or 1:2:3:4:5:6:7:8
+ %pISpc or [1:2:3:4:5:6:7:8]:12345
+ %p[Ii]S[pfschnbl]
+ For printing an IP address without the need to distinguish whether it's
+ of type AF_INET or AF_INET6, a pointer to a valid 'struct sockaddr',
+ specified through 'IS' or 'iS', can be passed to this format specifier.
+ The additional 'p', 'f', and 's' specifiers are used to specify port
+ (IPv4, IPv6), flowinfo (IPv6) and scope (IPv6). Ports have a ':' prefix,
+ flowinfo a '/' and scope a '%', each followed by the actual value.
+ In case of an IPv6 address the compressed IPv6 address as described by
+ is being used if the additional
+ specifier 'c' is given. The IPv6 address is surrounded by '[', ']' in
+ case of additional specifiers 'p', 'f' or 's' as suggested by
+ In case of IPv4 addresses, the additional 'h', 'n', 'b', and 'l'
+ specifiers can be used as well and are ignored in case of an IPv6
+ address.
+ Further examples:
+ %pISfc or [1:2:3:4:5:6:7:8]/123456789
+ %pISsc or [1:2:3:4:5:6:7:8]%1234567890
+ %pISpfc or [1:2:3:4:5:6:7:8]:12345/123456789
UUID/GUID addresses:
%pUb 00010203-0405-0607-0809-0a0b0c0d0e0f