forked from osmocom/wireshark
Do not assert in ws_inet_ntop()
Change-Id: I9d420c5f6bc29ce94855017739169dc8e8ce4d48 Reviewed-on: https://code.wireshark.org/review/24173 Petri-Dish: João Valverde <j@v6e.pt> Tested-by: Petri Dish Buildbot Reviewed-by: João Valverde <j@v6e.pt>
This commit is contained in:
parent
bebd79aae9
commit
62b870a722
|
@ -23,6 +23,8 @@
|
|||
|
||||
#include "inet_addr.h"
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#ifdef HAVE_ARPA_INET_H
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
|
@ -44,8 +46,8 @@
|
|||
|
||||
/*
|
||||
* We only employ and require AF_INET/AF_INET6, so we can
|
||||
* have some stronger checks for correctness and convenience. It is a
|
||||
* programming error to pass a too-small buffer to inet_ntop.
|
||||
* have some stronger checks for correctness and convenience (namely
|
||||
* assert that EAFNOSUPPORT cannot happen).
|
||||
*/
|
||||
|
||||
static inline gboolean
|
||||
|
@ -60,8 +62,14 @@ static inline const gchar *
|
|||
_inet_ntop(int af, gconstpointer src, gchar *dst, guint dst_size)
|
||||
{
|
||||
const gchar *ret = inet_ntop(af, _NTOP_SRC_CAST_ src, dst, dst_size);
|
||||
g_assert(ret != NULL);
|
||||
return ret;
|
||||
if (ret == NULL) {
|
||||
g_assert(errno == ENOSPC);
|
||||
/* set result to something that can't be confused with a valid conversion */
|
||||
g_strlcpy(dst, "<<ENOSPC>>", dst_size);
|
||||
/* set errno for caller */
|
||||
errno = ENOSPC;
|
||||
}
|
||||
return dst;
|
||||
}
|
||||
|
||||
const gchar *
|
||||
|
|
|
@ -73,20 +73,18 @@
|
|||
#endif
|
||||
|
||||
/*
|
||||
* 'dst_size' *must* be greater or equal to WS_INET_ADDRSTRLEN.
|
||||
* To check for errors set errno to zero before calling ws_inet_ntop{4,6}.
|
||||
* ENOSPC is set if the result exceeds the given buffer size.
|
||||
*/
|
||||
WS_DLL_PUBLIC WS_RETNONNULL const gchar *
|
||||
ws_inet_ntop4(gconstpointer src, gchar *dst, guint dst_size);
|
||||
|
||||
WS_DLL_PUBLIC gboolean
|
||||
ws_inet_pton4(const gchar *src, guint32 *dst);
|
||||
|
||||
/*
|
||||
* 'dst_size' *must* be greater or equal to WS_INET6_ADDRSTRLEN.
|
||||
*/
|
||||
WS_DLL_PUBLIC WS_RETNONNULL const gchar *
|
||||
ws_inet_ntop6(gconstpointer src, gchar *dst, guint dst_size);
|
||||
|
||||
WS_DLL_PUBLIC gboolean
|
||||
ws_inet_pton4(const gchar *src, guint32 *dst);
|
||||
|
||||
WS_DLL_PUBLIC gboolean
|
||||
ws_inet_pton6(const gchar *src, ws_in6_addr *dst);
|
||||
|
||||
|
|
Loading…
Reference in New Issue