diff options
Diffstat (limited to 'epan')
-rw-r--r-- | epan/addr_resolv.c | 82 | ||||
-rw-r--r-- | epan/address_types.c | 16 | ||||
-rw-r--r-- | epan/dissectors/packet-uaudp.c | 17 |
3 files changed, 32 insertions, 83 deletions
diff --git a/epan/addr_resolv.c b/epan/addr_resolv.c index b8b0fe18c2..45342af7d2 100644 --- a/epan/addr_resolv.c +++ b/epan/addr_resolv.c @@ -73,10 +73,6 @@ #include <netdb.h> #endif -#ifdef HAVE_ARPA_INET_H -#include <arpa/inet.h> -#endif - #ifdef HAVE_SYS_SOCKET_H #include <sys/socket.h> /* needed to define AF_ values on UNIX */ #endif @@ -85,10 +81,6 @@ #include <winsock2.h> /* needed to define AF_ values on Windows */ #endif -#ifdef NEED_INET_V6DEFS_H -# include "wsutil/inet_v6defs.h" -#endif - #ifdef _WIN32 # include <ws2tcpip.h> #endif @@ -109,7 +101,6 @@ # endif /* HAVE_GNU_ADNS */ #endif /* HAVE_C_ARES */ - #include <glib.h> #include "packet.h" @@ -122,6 +113,7 @@ #include <wsutil/file_util.h> #include <wsutil/pint.h> #include "wsutil/inet_aton.h" +#include <wsutil/inet_addr.h> #include <epan/strutil.h> #include <epan/to_str-int.h> @@ -1960,10 +1952,11 @@ read_hosts_file (const char *hostspath, gboolean store_entries) char *line = NULL; int size = 0; gchar *cp; - guint32 host_addr[4]; /* IPv4 or IPv6 */ - struct e_in6_addr ip6_addr; + union { + guint32 ip4_addr; + struct e_in6_addr ip6_addr; + } host_addr; gboolean is_ipv6, entry_found = FALSE; - int ret; /* * See the hosts(4) or hosts(5) man page for hosts file format @@ -1979,17 +1972,14 @@ read_hosts_file (const char *hostspath, gboolean store_entries) if ((cp = strtok(line, " \t")) == NULL) continue; /* no tokens in the line */ - ret = inet_pton(AF_INET6, cp, &host_addr); - if (ret < 0) - continue; /* error parsing */ - if (ret > 0) { + if (ws_inet_pton6(cp, &host_addr.ip6_addr)) { /* Valid IPv6 */ is_ipv6 = TRUE; - } else { - /* Not valid IPv6 - valid IPv4? */ - if (!str_to_ip(cp, &host_addr)) - continue; /* no */ + } else if (ws_inet_pton4(cp, &host_addr.ip4_addr)) { + /* Valid IPv4 */ is_ipv6 = FALSE; + } else { + continue; } if ((cp = strtok(NULL, " \t")) == NULL) @@ -1998,26 +1988,10 @@ read_hosts_file (const char *hostspath, gboolean store_entries) entry_found = TRUE; if (store_entries) { if (is_ipv6) { - memcpy(&ip6_addr, host_addr, sizeof ip6_addr); - add_ipv6_name(&ip6_addr, cp); - } else - add_ipv4_name(host_addr[0], cp); - -#if 0 - /* - * Add the aliases, too, if there are any. - * XXX - except we only store the last one added. The name - * resolver returns the first name in the hosts file, we should - * too. - */ - while ((cp = strtok(NULL, " \t")) != NULL) { - if (is_ipv6) { - memcpy(&ip6_addr, host_addr, sizeof ip6_addr); - add_ipv6_name(&ip6_addr, cp); - } else - add_ipv4_name(host_addr[0], cp); + add_ipv6_name(&host_addr.ip6_addr, cp); + } else { + add_ipv4_name(host_addr.ip4_addr, cp); } -#endif } } g_free(line); @@ -2053,36 +2027,30 @@ add_hosts_file (const char *hosts_file) gboolean add_ip_name_from_string (const char *addr, const char *name) { - guint32 host_addr[4]; /* IPv4 */ - struct e_in6_addr ip6_addr; /* IPv6 */ + union { + guint32 ip4_addr; + struct e_in6_addr ip6_addr; + } host_addr; gboolean is_ipv6; - int ret; resolved_ipv4_t *resolved_ipv4_entry; resolved_ipv6_t *resolved_ipv6_entry; - ret = inet_pton(AF_INET6, addr, &ip6_addr); - if (ret < 0) - /* Error parsing address */ - return FALSE; - - if (ret > 0) { - /* Valid IPv6 */ + if (ws_inet_pton6(addr, &host_addr.ip6_addr)) { is_ipv6 = TRUE; - } else { - /* Not valid IPv6 - valid IPv4? */ - if (!str_to_ip(addr, &host_addr)) - return FALSE; /* no */ + } else if (ws_inet_pton4(addr, &host_addr.ip4_addr)) { is_ipv6 = FALSE; + } else { + return FALSE; } if (is_ipv6) { resolved_ipv6_entry = g_new(resolved_ipv6_t, 1); - memcpy(&(resolved_ipv6_entry->ip6_addr), &ip6_addr, 16); + memcpy(&(resolved_ipv6_entry->ip6_addr), &host_addr.ip6_addr, 16); g_strlcpy(resolved_ipv6_entry->name, name, MAXNAMELEN); manually_resolved_ipv6_list = g_slist_prepend(manually_resolved_ipv6_list, resolved_ipv6_entry); } else { resolved_ipv4_entry = g_new(resolved_ipv4_t, 1); - resolved_ipv4_entry->host_addr = host_addr[0]; + resolved_ipv4_entry->host_addr = host_addr.ip4_addr; g_strlcpy(resolved_ipv4_entry->name, name, MAXNAMELEN); manually_resolved_ipv4_list = g_slist_prepend(manually_resolved_ipv4_list, resolved_ipv4_entry); } @@ -3499,13 +3467,13 @@ addr_resolv_cleanup(void) gboolean str_to_ip(const char *str, void *dst) { - return inet_pton(AF_INET, str, dst) > 0; + return ws_inet_pton4(str, (guint32 *)dst); } gboolean str_to_ip6(const char *str, void *dst) { - return inet_pton(AF_INET6, str, dst) > 0; + return ws_inet_pton6(str, (struct e_in6_addr *)dst); } /* diff --git a/epan/address_types.c b/epan/address_types.c index e84be71ad6..f7da4deeeb 100644 --- a/epan/address_types.c +++ b/epan/address_types.c @@ -21,18 +21,6 @@ #include "config.h" -#ifdef HAVE_NETINET_IN_H -# include <netinet/in.h> /* needed for <arpa/inet.h> on some platforms */ -#endif - -#ifdef HAVE_ARPA_INET_H -#include <arpa/inet.h> -#endif - -#ifdef HAVE_SYS_SOCKET_H -#include <sys/socket.h> /* needed to define AF_ values on UNIX */ -#endif - #include <string.h> /* for memcmp */ #include "packet.h" #include "address_types.h" @@ -41,7 +29,7 @@ #include "addr_resolv.h" #include "wsutil/pint.h" #include "wsutil/str_util.h" -#include "wsutil/inet_v6defs.h" +#include "wsutil/inet_addr.h" #include <epan/dissectors/packet-mtp3.h> @@ -599,7 +587,7 @@ ib_addr_to_str( const address *addr, gchar *buf, int buf_len){ #define PREAMBLE_STR_LEN ((int)(sizeof("GID: ") - 1)) g_strlcpy(buf, "GID: ", buf_len); if (buf_len < PREAMBLE_STR_LEN || - inet_ntop(AF_INET6, addr->data, buf + PREAMBLE_STR_LEN, + ws_inet_ntop6(addr->data, buf + PREAMBLE_STR_LEN, buf_len - PREAMBLE_STR_LEN) == NULL ) /* Returns NULL if no space and does not touch buf */ g_strlcpy(buf, BUF_TOO_SMALL_ERR, buf_len); /* Let the unexpected value alert user */ } else { /* this is a LID (16 bits) */ diff --git a/epan/dissectors/packet-uaudp.c b/epan/dissectors/packet-uaudp.c index 047d497268..0dc3117230 100644 --- a/epan/dissectors/packet-uaudp.c +++ b/epan/dissectors/packet-uaudp.c @@ -26,14 +26,7 @@ #include "epan/packet.h" #include "epan/prefs.h" #include "wsutil/report_err.h" - -#ifdef HAVE_ARPA_INET_H -#include <arpa/inet.h> -#endif -#ifdef HAVE_WINSOCK2_H -# include <winsock2.h> /* Needed for AF_INET on Windows */ -#endif -#include "wsutil/inet_v6defs.h" +#include "wsutil/inet_addr.h" #include "packet-uaudp.h" @@ -71,7 +64,7 @@ static int hf_uaudp_sntseq = -1; static gint ett_uaudp = -1; /* pref */ -static guint8 sys_ip[4]; +static guint32 sys_ip; static const char* pref_sys_ip_s = ""; static gboolean use_sys_ip = FALSE; @@ -366,12 +359,12 @@ static int dissect_uaudp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, vo /* server address, if present, has precedence on ports */ if (use_sys_ip) { /* use server address to find direction*/ - if (memcmp((pinfo->src).data, sys_ip, 4) == 0) + if (memcmp((pinfo->src).data, &sys_ip, sizeof(sys_ip)) == 0) { _dissect_uaudp(tvb, pinfo, tree, SYS_TO_TERM); return tvb_captured_length(tvb); } - else if (memcmp((pinfo->dst).data, sys_ip, 4) == 0) + else if (memcmp((pinfo->dst).data, &sys_ip, sizeof(sys_ip)) == 0) { _dissect_uaudp(tvb, pinfo, tree, TERM_TO_SYS); return tvb_captured_length(tvb); @@ -638,7 +631,7 @@ void proto_reg_handoff_uaudp(void) dissector_delete_uint("udp.port", ports[i].last_port, uaudp_handle); } if (*pref_sys_ip_s) { - use_sys_ip = inet_pton(AF_INET, pref_sys_ip_s, sys_ip) == 1; + use_sys_ip = ws_inet_pton4(pref_sys_ip_s, &sys_ip); if (!use_sys_ip) { report_failure("Invalid value for pref uaudp.system_ip: %s", pref_sys_ip_s); |