wsutil: Remove ip6_to_str_buf_with_pfx()

Writing a string prefix shouldn't require a specialized function here.
This commit is contained in:
João Valverde 2021-09-16 20:34:07 +01:00
parent 364df939ea
commit 18c155a3ca
3 changed files with 10 additions and 26 deletions

View File

@ -10,6 +10,7 @@
#include "config.h"
#include <string.h> /* for memcmp */
#include <stdio.h>
#include "packet.h"
#include "address_types.h"
#include "to_str.h"
@ -426,12 +427,16 @@ static int eui64_len(void)
static int
ib_addr_to_str(const address *addr, gchar *buf, int buf_len)
{
if (addr->len >= 16) { /* GID is 128bits */
return ip6_to_str_buf_with_pfx((const ws_in6_addr *)addr->data, buf, buf_len, "GID: ");
}
char buf_ip6[WS_INET6_ADDRSTRLEN];
/* this is a LID (16 bits) */
g_snprintf(buf,buf_len,"LID: %u", *(const guint16 *)addr->data);
if (addr->len >= 16) { /* GID is 128bits */
ws_inet_ntop6((const ws_in6_addr *)addr->data, buf_ip6, sizeof(buf_ip6));
snprintf(buf, buf_len, "GID: %s", buf_ip6);
}
else {
/* this is a LID (16 bits) */
snprintf(buf,buf_len,"LID: %u", *(const guint16 *)addr->data);
}
return (int)(strlen(buf)+1);
}

View File

@ -606,24 +606,6 @@ char *ip6_to_str(wmem_allocator_t *scope, const ws_in6_addr *ad)
return buf;
}
int
ip6_to_str_buf_with_pfx(const ws_in6_addr *addr, gchar *buf, int buf_size, const char *prefix)
{
int bytes; /* the number of bytes which would be produced if the buffer was large enough. */
gchar addr_buf[WS_INET6_ADDRSTRLEN];
int len;
if (prefix == NULL)
prefix = "";
bytes = g_snprintf(buf, buf_size, "%s%s", prefix, ws_inet_ntop6(addr, addr_buf, sizeof(addr_buf)));
len = bytes - 1;
if (len > buf_size - 1) { /* size minus nul terminator */
len = (int)g_strlcpy(buf, BUF_TOO_SMALL_ERR, buf_size); /* Let the unexpected value alert user */
}
return len;
}
gchar *
ipxnet_to_str_punct(wmem_allocator_t *allocator, const guint32 ad, const char punct)
{

View File

@ -293,9 +293,6 @@ WS_DLL_PUBLIC void ip6_to_str_buf(const ws_in6_addr *ad, gchar *buf, size_t buf_
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);
WS_DLL_PUBLIC gchar *ipxnet_to_str_punct(wmem_allocator_t *scope, const guint32 ad, const char punct);
WS_DLL_PUBLIC gchar *eui64_to_str(wmem_allocator_t *scope, const guint64 ad);