This patch adds sprint_nip6() utility function, it used to print IPv6 address into string.
udhcp: sprint_nip6() - Convert IPv6 address into string
Signed-off-by: Leonid Lisovskiy <[email protected]> --- networking/udhcp/common.c | 16 ++++++++++++++++ networking/udhcp/common.h | 2 ++ 2 files changed, 18 insertions(+) diff --git a/networking/udhcp/common.c b/networking/udhcp/common.c index 70e3461..1627784 100644 --- a/networking/udhcp/common.c +++ b/networking/udhcp/common.c @@ -336,6 +336,22 @@ int FAST_FUNC udhcp_str2nip(const char *str, void *arg) return 1; } +/* Convert IPv6 address into string */ +int FAST_FUNC sprint_nip6(char *dest, const uint8_t *ip6) +{ + int i, len = 0; + + for (i = 0; i < 16; i += 2) { + if (i > 0) + dest[len++] = ':'; + bin2hex(dest + len, (const char * )&ip6[i], 2); + len += 4; + } + dest[len] = '\0'; + + return len; +} + /* udhcp_str2optset: * Parse string option representation to binary form and add it to opt_list. * Called to parse "udhcpc -x OPTNAME:OPTVAL" diff --git a/networking/udhcp/common.h b/networking/udhcp/common.h index 80d97e8..c463a70 100644 --- a/networking/udhcp/common.h +++ b/networking/udhcp/common.h @@ -272,6 +272,8 @@ void udhcp_dump_packet(struct dhcp_packet *packet) FAST_FUNC; /*** Other shared functions ***/ +int FAST_FUNC sprint_nip6(char *, const uint8_t *); + /* 2nd param is "uint32_t*" */ int FAST_FUNC udhcp_str2nip(const char *str, void *arg); /* 2nd param is "struct option_set**" */
_______________________________________________ busybox mailing list [email protected] http://lists.busybox.net/mailman/listinfo/busybox
