diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2016-10-10 08:31:07 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2016-10-10 08:31:07 +0200 |
commit | bfdb14c7dacf3e50a27b749259f6660ab9e930d5 (patch) | |
tree | fe81dec7194671caee4e94ac7fb68fe6e519e6df /lib | |
parent | df75f19871d764c421cbce19f502ea863e5affd4 (diff) | |
parent | e4a45c096136deaf56a200054c46f474250cc89c (diff) | |
download | barebox-bfdb14c7dacf3e50a27b749259f6660ab9e930d5.tar.gz barebox-bfdb14c7dacf3e50a27b749259f6660ab9e930d5.tar.xz |
Merge branch 'for-next/misc'
Diffstat (limited to 'lib')
-rw-r--r-- | lib/parameter.c | 2 | ||||
-rw-r--r-- | lib/vsprintf.c | 29 |
2 files changed, 30 insertions, 1 deletions
diff --git a/lib/parameter.c b/lib/parameter.c index 529d7ab92a..9f96d0760d 100644 --- a/lib/parameter.c +++ b/lib/parameter.c @@ -777,7 +777,7 @@ static const char *param_ip_get(struct device_d *dev, struct param_d *p) } free(p->value); - p->value = xstrdup(ip_to_string(*pi->ip)); + p->value = xasprintf("%pI4", pi->ip); return p->value; } diff --git a/lib/vsprintf.c b/lib/vsprintf.c index f3885a8201..fa9fb75800 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -191,6 +191,27 @@ static char *symbol_string(char *buf, char *end, void *ptr, int field_width, int } static noinline_for_stack +char *ip4_addr_string(char *buf, char *end, const u8 *addr, int field_width, + int precision, int flags, const char *fmt) +{ + char ip4_addr[sizeof("255.255.255.255")]; + char *pos; + int i; + + pos = ip4_addr; + + for (i = 0; i < 4; i++) { + pos = number(pos, pos + 3, addr[i], 10, 0, 0, LEFT); + if (i < 3) + *pos++ = '.'; + } + + *pos = 0; + + return string(buf, end, ip4_addr, field_width, precision, flags); +} + +static noinline_for_stack char *uuid_string(char *buf, char *end, const u8 *addr, int field_width, int precision, int flags, const char *fmt) { @@ -267,6 +288,8 @@ char *address_val(char *buf, char *end, const void *addr, * * Right now we handle: * + * - 'I' [4] for IPv4 addresses printed in the usual way + * IPv4 uses dot-separated decimal without leading 0's (1.2.3.4) * - 'S' For symbolic direct pointers * - 'U' For a 16 byte UUID/GUID, it prints the UUID/GUID in the form * "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" @@ -297,6 +320,12 @@ static char *pointer(const char *fmt, char *buf, char *end, void *ptr, int field break; case 'a': return address_val(buf, end, ptr, field_width, precision, flags, fmt); + case 'I': + switch (fmt[1]) { + case '4': + return ip4_addr_string(buf, end, ptr, field_width, precision, flags, fmt); + } + break; } flags |= SMALL; if (field_width == -1) { |