From d4c7978f68fabf742cef764f37fc515af8c8a5ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Valverde?= Date: Thu, 16 Sep 2021 19:05:11 +0100 Subject: [PATCH] wsutil: Add ip_to_str() --- wsutil/to_str.c | 18 ++++++++++++++++++ wsutil/to_str.h | 4 ++++ 2 files changed, 22 insertions(+) diff --git a/wsutil/to_str.c b/wsutil/to_str.c index a503794c59..aaaa28044a 100644 --- a/wsutil/to_str.c +++ b/wsutil/to_str.c @@ -578,6 +578,15 @@ ip_to_str_buf(const guint8 *ad, gchar *buf, const int buf_len) *b=0; } +char *ip_to_str(wmem_allocator_t *scope, const guint8 *ad) +{ + char *buf = wmem_alloc(scope, WS_INET_ADDRSTRLEN * sizeof(char)); + + ip_to_str_buf(ad, buf, WS_INET_ADDRSTRLEN); + + return buf; +} + int ip6_to_str_buf(const ws_in6_addr *addr, gchar *buf, int buf_size) { @@ -593,6 +602,15 @@ ip6_to_str_buf(const ws_in6_addr *addr, gchar *buf, int buf_size) return len; } +char *ip6_to_str(wmem_allocator_t *scope, const ws_in6_addr *ad) +{ + char *buf = wmem_alloc(scope, WS_INET6_ADDRSTRLEN * sizeof(char)); + + ip6_to_str_buf(ad, buf, WS_INET6_ADDRSTRLEN); + + return buf; +} + int ip6_to_str_buf_with_pfx(const ws_in6_addr *addr, gchar *buf, int buf_size, const char *prefix) { diff --git a/wsutil/to_str.h b/wsutil/to_str.h index d43141dc7c..3955fb9ef0 100644 --- a/wsutil/to_str.h +++ b/wsutil/to_str.h @@ -286,9 +286,13 @@ WS_DLL_PUBLIC void guint64_to_str_buf(guint64 u, gchar *buf, int buf_len); WS_DLL_PUBLIC void ip_to_str_buf(const guint8 *ad, gchar *buf, const int buf_len); +WS_DLL_PUBLIC char *ip_to_str(wmem_allocator_t *scope, const guint8 *ad); + /* Returns length of the result. */ WS_DLL_PUBLIC int ip6_to_str_buf(const ws_in6_addr *ad, gchar *buf, int buf_size); +WS_DLL_PUBLIC char *ip6_to_str(wmem_allocator_t *scope, const ws_in6_addr *ad); + /* Returns length of the result. Takes a prefix to be inserted before the address. */ WS_DLL_PUBLIC int ip6_to_str_buf_with_pfx(const ws_in6_addr *ad, gchar *buf, int buf_size, const char *prefix);