summaryrefslogtreecommitdiff
path: root/lib/printf.c
diff options
context:
space:
mode:
authorOndrej Zajicek (work) <santiago@crfreenet.org>2016-04-28 18:01:40 +0200
committerOndrej Zajicek (work) <santiago@crfreenet.org>2016-04-28 18:01:40 +0200
commit937e75d8f1d203b637ba0ea050026f9af92485f3 (patch)
tree2737eba68e77ac4030d24e42506db0947196f775 /lib/printf.c
parenta7baa09862e6b4856cd66197c6bd74c7df336b8f (diff)
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.
Diffstat (limited to 'lib/printf.c')
-rw-r--r--lib/printf.c31
1 files changed, 24 insertions, 7 deletions
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;