wsutil: Add ip_to_str()

This commit is contained in:
João Valverde 2021-09-16 19:05:11 +01:00
parent 8c4a479c52
commit d4c7978f68
2 changed files with 22 additions and 0 deletions

View File

@ -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)
{

View File

@ -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);