summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorOndrej Zajicek <santiago@crfreenet.org>2009-07-23 16:06:25 +0200
committerOndrej Zajicek <santiago@crfreenet.org>2009-07-23 16:06:25 +0200
commit2f6483cd312ffd7ef055099ce801fb8f437d9abe (patch)
treedd4d468a17017a5b1372057be9bcc40536089a3c /lib
parentf0333f44a5a4bec9f3978a90cf7eda1b0a2ec151 (diff)
downloadbird-2f6483cd312ffd7ef055099ce801fb8f437d9abe.tar
bird-2f6483cd312ffd7ef055099ce801fb8f437d9abe.zip
Adds %R printf directive for Router ID.
Diffstat (limited to 'lib')
-rw-r--r--lib/printf.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/lib/printf.c b/lib/printf.c
index 0e3b4d9..c3f7074 100644
--- a/lib/printf.c
+++ b/lib/printf.c
@@ -120,7 +120,8 @@ static char * number(char * str, long num, int base, int size, int precision,
* available space to avoid buffer overflows and it allows some more
* format specifiers: |%I| for formatting of IP addresses (any non-zero
* width is automatically replaced by standard IP address width which
- * depends on whether we use IPv4 or IPv6; |%#I| gives hexadecimal format)
+ * depends on whether we use IPv4 or IPv6; |%#I| gives hexadecimal format),
+ * |%R| for Router / Network ID (u32 value printed as IPv4 address)
* 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.
@@ -133,6 +134,7 @@ int bvsnprintf(char *buf, int size, const char *fmt, va_list args)
int len;
unsigned long num;
int i, base;
+ u32 x;
char *str, *start;
const char *s;
char ipbuf[STD_ADDRESS_P_LENGTH+1];
@@ -277,6 +279,17 @@ int bvsnprintf(char *buf, int size, const char *fmt, va_list args)
s = ipbuf;
goto str;
+ /* 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));
+ s = ipbuf;
+ goto str;
+
/* integer number formats - set up the flags and "break" */
case 'o':
base = 8;