From 937e75d8f1d203b637ba0ea050026f9af92485f3 Mon Sep 17 00:00:00 2001 From: "Ondrej Zajicek (work)" Date: Thu, 28 Apr 2016 18:01:40 +0200 Subject: Add the Babel routing protocol (RFC 6126) This patch implements the IPv6 subset of the Babel routing protocol. Based on the patch from Toke Hoiland-Jorgensen, with some heavy modifications and bugfixes. Thanks to Toke Hoiland-Jorgensen for the original patch. --- lib/printf.c | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) (limited to 'lib/printf.c') diff --git a/lib/printf.c b/lib/printf.c index e4cc3006..a067fe98 100644 --- a/lib/printf.c +++ b/lib/printf.c @@ -124,6 +124,7 @@ static char * number(char * str, long num, int base, int size, int precision, * width is automatically replaced by standard IP address width which * depends on whether we use IPv4 or IPv6; |%#I| gives hexadecimal format), * |%R| for Router / Network ID (u32 value printed as IPv4 address) + * |%lR| for 64bit Router / Network ID (u64 value printed as eight :-separated octets) * and |%m| resp. |%M| for error messages (uses strerror() to translate @errno code to * message text). On the other hand, it doesn't support floating * point numbers. @@ -137,9 +138,10 @@ int bvsnprintf(char *buf, int size, const char *fmt, va_list args) unsigned long num; int i, base; u32 x; + u64 X; char *str, *start; const char *s; - char ipbuf[STD_ADDRESS_P_LENGTH+1]; + char ipbuf[MAX(STD_ADDRESS_P_LENGTH,ROUTER_ID_64_LENGTH)+1]; struct iface *iface; int flags; /* flags to number() */ @@ -309,12 +311,27 @@ int bvsnprintf(char *buf, int size, const char *fmt, va_list args) /* Router/Network ID - essentially IPv4 address in u32 value */ case 'R': - x = va_arg(args, u32); - bsprintf(ipbuf, "%d.%d.%d.%d", - ((x >> 24) & 0xff), - ((x >> 16) & 0xff), - ((x >> 8) & 0xff), - (x & 0xff)); + if(qualifier == 'l') { + X = va_arg(args, u64); + bsprintf(ipbuf, "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x", + ((X >> 56) & 0xff), + ((X >> 48) & 0xff), + ((X >> 40) & 0xff), + ((X >> 32) & 0xff), + ((X >> 24) & 0xff), + ((X >> 16) & 0xff), + ((X >> 8) & 0xff), + (X & 0xff)); + } + else + { + x = va_arg(args, u32); + bsprintf(ipbuf, "%d.%d.%d.%d", + ((x >> 24) & 0xff), + ((x >> 16) & 0xff), + ((x >> 8) & 0xff), + (x & 0xff)); + } s = ipbuf; goto str; -- cgit v1.2.3