diff options
-rw-r--r-- | ConfigureChecks.cmake | 1 | ||||
-rw-r--r-- | capchild/capture_ifinfo.c | 22 | ||||
-rw-r--r-- | cmakeconfig.h.in | 7 | ||||
-rw-r--r-- | config.h.win32 | 2 | ||||
-rw-r--r-- | configure.ac | 6 | ||||
-rw-r--r-- | dumpcap.c | 11 | ||||
-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 | ||||
-rw-r--r-- | text2pcap.c | 58 | ||||
-rw-r--r-- | tools/pre-commit-check.conf | 2 | ||||
-rw-r--r-- | wsutil/CMakeLists.txt | 1 | ||||
-rw-r--r-- | wsutil/Makefile.am | 2 | ||||
-rw-r--r-- | wsutil/Makefile.common | 2 | ||||
-rw-r--r-- | wsutil/inet_addr-int.h (renamed from wsutil/inet_v6defs.h) | 47 | ||||
-rw-r--r-- | wsutil/inet_addr.c | 60 | ||||
-rw-r--r-- | wsutil/inet_addr.h | 43 | ||||
-rw-r--r-- | wsutil/inet_aton.c | 2 | ||||
-rw-r--r-- | wsutil/inet_ntop.c | 59 | ||||
-rw-r--r-- | wsutil/inet_pton.c | 52 |
20 files changed, 219 insertions, 273 deletions
diff --git a/ConfigureChecks.cmake b/ConfigureChecks.cmake index b30274310e..25e4a888d4 100644 --- a/ConfigureChecks.cmake +++ b/ConfigureChecks.cmake @@ -117,6 +117,7 @@ endif() check_function_exists("getprotobynumber" HAVE_GETPROTOBYNUMBER) check_function_exists("inet_aton" HAVE_INET_ATON) check_function_exists("inet_ntop" HAVE_INET_NTOP_PROTO) +check_function_exists("inet_pton" HAVE_INET_PTON) check_function_exists("issetugid" HAVE_ISSETUGID) check_function_exists("mkdtemp" HAVE_MKDTEMP) check_function_exists("mkstemp" HAVE_MKSTEMP) diff --git a/capchild/capture_ifinfo.c b/capchild/capture_ifinfo.c index b6bef3cf1e..3753ee2684 100644 --- a/capchild/capture_ifinfo.c +++ b/capchild/capture_ifinfo.c @@ -28,22 +28,6 @@ #include <string.h> #include <stdio.h> -#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 - -#ifdef HAVE_WINSOCK2_H -#include <winsock2.h> /* needed to define AF_ values on Windows */ -#endif - -#ifdef NEED_INET_V6DEFS_H -# include "wsutil/inet_v6defs.h" -#endif - #include <glib.h> #include "capture_opts.h" @@ -56,6 +40,7 @@ #include "log.h" #include <caputils/capture_ifinfo.h> +#include <wsutil/inet_addr.h> #ifdef HAVE_PCAP_REMOTE static GList *remote_interface_list = NULL; @@ -187,10 +172,9 @@ capture_interface_list(int *err, char **err_str, void (*update_cb)(void)) addr_parts = g_strsplit(if_parts[4], ",", 0); for (j = 0; addr_parts[j] != NULL; j++) { if_addr = g_new0(if_addr_t,1); - if (inet_pton(AF_INET, addr_parts[j], &if_addr->addr.ip4_addr) > 0) { + if (ws_inet_pton4(addr_parts[j], &if_addr->addr.ip4_addr)) { if_addr->ifat_type = IF_AT_IPv4; - } else if (inet_pton(AF_INET6, addr_parts[j], - &if_addr->addr.ip6_addr) > 0) { + } else if (ws_inet_pton6(addr_parts[j], (struct e_in6_addr *)&if_addr->addr.ip6_addr)) { if_addr->ifat_type = IF_AT_IPv6; } else { g_free(if_addr); diff --git a/cmakeconfig.h.in b/cmakeconfig.h.in index bff142b520..5d0543df96 100644 --- a/cmakeconfig.h.in +++ b/cmakeconfig.h.in @@ -112,6 +112,9 @@ /* Define if inet_ntop() prototype exists */ #cmakedefine HAVE_INET_NTOP_PROTO 1 +/* Define to 1 if you have the `inet_pton' function. */ +#cmakedefine HAVE_INET_PTON 1 + /* Define to 1 if you have the `inflatePrime' function. */ #cmakedefine HAVE_INFLATEPRIME 1 @@ -357,9 +360,6 @@ /* HTML viewer, e.g. mozilla */ #cmakedefine HTML_VIEWER "${HTML_VIEWER_EXECUTABLE}" -/* Define if inet/v6defs.h needs to be included */ -#cmakedefine NEED_INET_V6DEFS_H 1 - /* Name of package */ #cmakedefine PACKAGE @@ -468,6 +468,5 @@ # define UNICODE 1 # define _UNICODE 1 -# define NEED_INET_V6DEFS_H 1 # define NEED_STRPTIME_H 1 #endif diff --git a/config.h.win32 b/config.h.win32 index 9c8d563ad1..5faac21994 100644 --- a/config.h.win32 +++ b/config.h.win32 @@ -217,8 +217,6 @@ /* Define if you have the strptime function. */ /* #undef HAVE_STRPTIME 1 */ -#define NEED_INET_V6DEFS_H 1 - #ifndef WIN32 #define WIN32 1 #endif diff --git a/configure.ac b/configure.ac index e57727bdfd..759e7e52b3 100644 --- a/configure.ac +++ b/configure.ac @@ -2945,6 +2945,8 @@ have_inet_pton=no) if test "$have_inet_pton" = no; then INET_PTON_LO="inet_pton.lo" else + AC_DEFINE(HAVE_INET_NTOP, 1, + [Define to 1 if you have the `inet_pton' function.]) INET_PTON_LO="" fi AM_CONDITIONAL(NEED_INET_PTON_LO, test "x$have_inet_pton" = "xno") @@ -2974,9 +2976,7 @@ extern const char *inet_ntop(int, const void *, char *, socklen_t);],, [ [Define if inet_ntop() prototype exists])], [ AC_MSG_RESULT(no)])]) INET_NTOP_LO=""], [ - INET_NTOP_LO="inet_ntop.lo" - AC_DEFINE(NEED_INET_V6DEFS_H, 1, - [Define if inet/v6defs.h needs to be included])]) + INET_NTOP_LO="inet_ntop.lo"]) AM_CONDITIONAL(NEED_INET_NTOP_LO, test "x$INET_NTOP_LO" != "x") AC_SUBST(INET_NTOP_LO) @@ -95,10 +95,6 @@ #include <sys/un.h> #endif -#ifdef NEED_INET_V6DEFS_H -# include "wsutil/inet_v6defs.h" -#endif - #include <wsutil/clopts_common.h> #include <wsutil/privileges.h> @@ -116,6 +112,7 @@ #include "wsutil/file_util.h" #include "wsutil/os_version_info.h" #include "wsutil/str_util.h" +#include "wsutil/inet_addr.h" #include "caputils/ws80211_utils.h" @@ -859,7 +856,7 @@ print_machine_readable_interfaces(GList *if_list) if_addr = (if_addr_t *)addr->data; switch(if_addr->ifat_type) { case IF_AT_IPv4: - if (inet_ntop(AF_INET, &if_addr->addr.ip4_addr, addr_str, + if (ws_inet_ntop4(&if_addr->addr.ip4_addr, addr_str, ADDRSTRLEN)) { printf("%s", addr_str); } else { @@ -867,7 +864,7 @@ print_machine_readable_interfaces(GList *if_list) } break; case IF_AT_IPv6: - if (inet_ntop(AF_INET6, &if_addr->addr.ip6_addr, + if (ws_inet_ntop6(&if_addr->addr.ip6_addr, addr_str, ADDRSTRLEN)) { printf("%s", addr_str); } else { @@ -1390,7 +1387,7 @@ cap_open_socket(char *pipename, pcap_options *pcap_opts, char *errmsg, int errms g_snprintf ( buf,(gulong)len + 1, "%s", sockname ); buf[len] = '\0'; - if (inet_pton(AF_INET, buf, &sa.sin_addr) <= 0) { + if (!ws_inet_pton4(buf, (guint32 *)&sa.sin_addr)) { goto fail_invalid; } 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); diff --git a/text2pcap.c b/text2pcap.c index 64e1423bd7..bc958cbb4f 100644 --- a/text2pcap.c +++ b/text2pcap.c @@ -114,6 +114,7 @@ #include <wsutil/crash_info.h> #include <wsutil/ws_diag_control.h> #include <wsutil/ws_version_info.h> +#include <wsutil/inet_addr.h> #include <time.h> #include <glib.h> @@ -144,22 +145,6 @@ #include <wsutil/unicode-utils.h> #endif /* _WIN32 */ -#ifdef HAVE_ARPA_INET_H -#include <arpa/inet.h> -#endif - -#ifdef HAVE_WINSOCK2_H -#include <winsock2.h> /* needed to define AF_ values on Windows */ -#endif - -#ifdef HAVE_SYS_SOCKET_H -#include <sys/socket.h> -#endif - -#ifdef NEED_INET_V6DEFS_H -# include "wsutil/inet_v6defs.h" -#endif - /*--- Options --------------------------------------------------------------------*/ /* File format */ @@ -182,9 +167,9 @@ static long hdr_ip_proto = 0; /* Destination and source addresses for IP header */ static guint32 hdr_ip_dest_addr = 0; static guint32 hdr_ip_src_addr = 0; -static guint8 hdr_ipv6_dest_addr[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; -static guint8 hdr_ipv6_src_addr[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; -static guint8 NO_IPv6_ADDRESS[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static struct e_in6_addr hdr_ipv6_dest_addr = {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}; +static struct e_in6_addr hdr_ipv6_src_addr = {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}; +static struct e_in6_addr NO_IPv6_ADDRESS = {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}; /* Dummy UDP header */ static int hdr_udp = FALSE; @@ -344,17 +329,6 @@ static struct { /* pseudo header for checksum calculation */ /* headers taken from glibc */ -/* IPv6 address */ -struct hdr_in6_addr -{ - union - { - guint8 __u6_addr8[16]; - guint16 __u6_addr16[8]; - guint32 __u6_addr32[4]; - } __in6_u; -}; - typedef struct { union { struct ip6_hdrctl { @@ -365,15 +339,15 @@ typedef struct { } ip6_un1; guint8 ip6_un2_vfc; /* 4 bits version, 4 bits priority */ } ip6_ctlun; - struct hdr_in6_addr ip6_src; /* source address */ - struct hdr_in6_addr ip6_dst; /* destination address */ + struct e_in6_addr ip6_src; /* source address */ + struct e_in6_addr ip6_dst; /* destination address */ } hdr_ipv6_t; static hdr_ipv6_t HDR_IPv6; static struct { /* pseudo header ipv6 for checksum calculation */ - struct hdr_in6_addr src_addr6; - struct hdr_in6_addr dst_addr6; + struct e_in6_addr src_addr6; + struct e_in6_addr dst_addr6; guint32 protocol; guint32 zero; } pseudoh6; @@ -697,10 +671,10 @@ write_current_packet (gboolean cont) HDR_IP.hdr_checksum = in_checksum(&HDR_IP, sizeof(HDR_IP)); write_bytes((const char *)&HDR_IP, sizeof(HDR_IP)); } else if (hdr_ipv6) { - if (memcmp(isInbound ? hdr_ipv6_dest_addr : hdr_ipv6_src_addr, NO_IPv6_ADDRESS, sizeof(struct hdr_in6_addr))) - memcpy(&HDR_IPv6.ip6_src, isInbound ? &hdr_ipv6_dest_addr : &hdr_ipv6_src_addr, sizeof(struct hdr_in6_addr)); - if (memcmp(isInbound ? hdr_ipv6_src_addr : hdr_ipv6_dest_addr, NO_IPv6_ADDRESS, sizeof(struct hdr_in6_addr))) - memcpy(&HDR_IPv6.ip6_dst, isInbound ? &hdr_ipv6_src_addr : &hdr_ipv6_dest_addr, sizeof(struct hdr_in6_addr)); + if (memcmp(isInbound ? &hdr_ipv6_dest_addr : &hdr_ipv6_src_addr, &NO_IPv6_ADDRESS, sizeof(struct e_in6_addr))) + memcpy(&HDR_IPv6.ip6_src, isInbound ? &hdr_ipv6_dest_addr : &hdr_ipv6_src_addr, sizeof(struct e_in6_addr)); + if (memcmp(isInbound ? &hdr_ipv6_src_addr : &hdr_ipv6_dest_addr, &NO_IPv6_ADDRESS, sizeof(struct e_in6_addr))) + memcpy(&HDR_IPv6.ip6_dst, isInbound ? &hdr_ipv6_src_addr : &hdr_ipv6_dest_addr, sizeof(struct e_in6_addr)); HDR_IPv6.ip6_ctlun.ip6_un2_vfc &= 0x0F; HDR_IPv6.ip6_ctlun.ip6_un2_vfc |= (6<< 4); @@ -1762,13 +1736,13 @@ parse_options (int argc, char *argv[]) hdr_ethernet = TRUE; if (hdr_ipv6 == TRUE) { - if (inet_pton( AF_INET6, optarg, hdr_ipv6_src_addr) <= 0) { + if (!ws_inet_pton6(optarg, &hdr_ipv6_src_addr)) { fprintf(stderr, "Bad src addr -%c '%s'\n", c, p); print_usage(stderr); exit(1); } } else { - if (inet_pton( AF_INET, optarg, &hdr_ip_src_addr) <= 0) { + if (!ws_inet_pton4(optarg, &hdr_ip_src_addr)) { fprintf(stderr, "Bad src addr -%c '%s'\n", c, p); print_usage(stderr); exit(1); @@ -1783,13 +1757,13 @@ parse_options (int argc, char *argv[]) } if (hdr_ipv6 == TRUE) { - if (inet_pton( AF_INET6, p, hdr_ipv6_dest_addr) <= 0) { + if (!ws_inet_pton6(p, &hdr_ipv6_dest_addr)) { fprintf(stderr, "Bad dest addr for -%c '%s'\n", c, p); print_usage(stderr); exit(1); } } else { - if (inet_pton( AF_INET, p, &hdr_ip_dest_addr) <= 0) { + if (!ws_inet_pton4(p, &hdr_ip_dest_addr)) { fprintf(stderr, "Bad dest addr for -%c '%s'\n", c, p); print_usage(stderr); exit(1); diff --git a/tools/pre-commit-check.conf b/tools/pre-commit-check.conf index 0129272196..f3eebc58f3 100644 --- a/tools/pre-commit-check.conf +++ b/tools/pre-commit-check.conf @@ -13,3 +13,5 @@ asn1/*/packet-*-template.c extcap/* tools/lemon/* wsutil/inet_aton.c +wsutil/inet_ntop.c +wsutil/inet_pton.c diff --git a/wsutil/CMakeLists.txt b/wsutil/CMakeLists.txt index 02e7823649..7d63757132 100644 --- a/wsutil/CMakeLists.txt +++ b/wsutil/CMakeLists.txt @@ -53,6 +53,7 @@ set(WSUTIL_FILES filesystem.c frequency-utils.c g711.c + inet_addr.c jsmn.c md4.c md5.c diff --git a/wsutil/Makefile.am b/wsutil/Makefile.am index 23c171d104..e7b0813093 100644 --- a/wsutil/Makefile.am +++ b/wsutil/Makefile.am @@ -82,7 +82,7 @@ EXTRA_libwsutil_la_SOURCES = \ inet_aton.h \ inet_ntop.c \ inet_pton.c \ - inet_v6defs.h \ + inet_addr-int.h \ popcount.c \ popcount.h \ strptime.c \ diff --git a/wsutil/Makefile.common b/wsutil/Makefile.common index 9f69cee14c..6e93833de2 100644 --- a/wsutil/Makefile.common +++ b/wsutil/Makefile.common @@ -50,6 +50,7 @@ LIBWSUTIL_COMMON_SRC = \ filesystem.c \ frequency-utils.c \ g711.c \ + inet_addr.c \ jsmn.c \ md4.c \ md5.c \ @@ -100,6 +101,7 @@ libwsutil_nonrepl_INCLUDES = \ filesystem.h \ frequency-utils.h \ g711.h \ + inet_addr.h \ jsmn.h \ md4.h \ md5.h \ diff --git a/wsutil/inet_v6defs.h b/wsutil/inet_addr-int.h index 9e1f6f5caf..631787dfca 100644 --- a/wsutil/inet_v6defs.h +++ b/wsutil/inet_addr-int.h @@ -1,4 +1,4 @@ -/* inet_v6defs.h +/* inet_addr-int.h * * Wireshark - Network traffic analyzer * By Gerald Combs <gerald@wireshark.org> @@ -19,30 +19,36 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#ifndef __INET_V6DEFS_H__ -#define __INET_V6DEFS_H__ +#ifndef __WS_INET_ADDR_INT_H__ +#define __WS_INET_ADDR_INT_H__ -#include "ws_symbol_export.h" +#include "config.h" + +#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 + +#ifdef HAVE_WINSOCK2_H +#include <winsock2.h> /* needed to define AF_ values on Windows */ +#if _MSC_VER < 1600 /* errno.h defines EAFNOSUPPORT in Windows VC10 (and presumably eventually in VC11 ...) */ +#define EAFNOSUPPORT WSAEAFNOSUPPORT +#endif +#endif /* * Versions of "inet_pton()" and "inet_ntop()", for the benefit of OSes that * don't have it. */ - -/* Windows does not have inet_pton() and inet_ntop() until Vista. In order - * to allow binaries compiled on Vista or later to work on pre-Vista Windows - * (without resorting to fragile link ordering tricks), we give our versions - * of those functions Wireshark-specific names. - */ -#ifdef _WIN32 -#define inet_pton ws_inet_pton -#define inet_ntop ws_inet_ntop -WS_DLL_PUBLIC int inet_pton(int af, const char *src, void *dst); +#ifndef HAVE_INET_PTON +extern int inet_pton(int af, const char *src, void *dst); #endif #ifndef HAVE_INET_NTOP_PROTO -WS_DLL_PUBLIC const char *inet_ntop(int af, const void *src, char *dst, - size_t size); +extern const char *inet_ntop(int af, const void *src, char *dst, size_t size); #endif /* @@ -53,13 +59,4 @@ WS_DLL_PUBLIC const char *inet_ntop(int af, const void *src, char *dst, #define AF_INET6 127 /* pick a value unlikely to duplicate an existing AF_ value */ #endif -/* - * And if __P isn't defined, define it here, so we can use it in - * "inet_ntop.c" and "inet_pton.c" (rather than having to change them - * not to use it). - */ -#ifndef __P -#define __P(args) args -#endif - #endif diff --git a/wsutil/inet_addr.c b/wsutil/inet_addr.c new file mode 100644 index 0000000000..b5f4cea62e --- /dev/null +++ b/wsutil/inet_addr.c @@ -0,0 +1,60 @@ +/* inet_addr.c + * + * Wireshark - Network traffic analyzer + * By Gerald Combs <gerald@wireshark.org> + * Copyright 1998 Gerald Combs + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "inet_addr.h" + +#include "inet_addr-int.h" + + + +static inline gboolean +_inet_pton(int af, const gchar *src, gpointer dst) +{ + gint ret; + + ret = inet_pton(af, src, dst); + g_assert(ret >= 0); + return ret == 1; +} + +const gchar * +ws_inet_ntop4(gconstpointer src, gchar *dst, gsize dst_size) +{ + return inet_ntop(AF_INET, src, dst, dst_size); +} + +gboolean +ws_inet_pton4(const gchar *src, guint32 *dst) +{ + return _inet_pton(AF_INET, src, dst); +} + +const gchar * +ws_inet_ntop6(gconstpointer src, gchar *dst, gsize dst_size) +{ + return inet_ntop(AF_INET6, src, dst, dst_size); +} + +gboolean +ws_inet_pton6(const gchar *src, struct e_in6_addr *dst) +{ + return _inet_pton(AF_INET6, src, dst); +} diff --git a/wsutil/inet_addr.h b/wsutil/inet_addr.h new file mode 100644 index 0000000000..330f6e0d88 --- /dev/null +++ b/wsutil/inet_addr.h @@ -0,0 +1,43 @@ +/* inet_addr.h + * + * Wireshark - Network traffic analyzer + * By Gerald Combs <gerald@wireshark.org> + * Copyright 1998 Gerald Combs + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef __WS_INET_ADDR_H__ +#define __WS_INET_ADDR_H__ + +#include "ws_symbol_export.h" + +#include <glib.h> + +#include <epan/ipv6.h> + +WS_DLL_PUBLIC const gchar * +ws_inet_ntop4(gconstpointer src, gchar *dst, gsize dst_size); + +WS_DLL_PUBLIC gboolean +ws_inet_pton4(const gchar *src, guint32 *dst); + +WS_DLL_PUBLIC const gchar * +ws_inet_ntop6(gconstpointer src, gchar *dst, gsize dst_size); + +WS_DLL_PUBLIC gboolean +ws_inet_pton6(const gchar *src, struct e_in6_addr *dst); + +#endif diff --git a/wsutil/inet_aton.c b/wsutil/inet_aton.c index 296b225109..08939f7929 100644 --- a/wsutil/inet_aton.c +++ b/wsutil/inet_aton.c @@ -35,6 +35,8 @@ static char sccsid[] = "@(#)inet_addr.c 8.1 (Berkeley) 6/17/93"; #endif /* LIBC_SCCS and not lint */ +#include <ctype.h> + #ifdef HAVE_SYS_PARAM_H #include <sys/param.h> #endif diff --git a/wsutil/inet_ntop.c b/wsutil/inet_ntop.c index c4e080a255..cbb9c227dd 100644 --- a/wsutil/inet_ntop.c +++ b/wsutil/inet_ntop.c @@ -15,48 +15,21 @@ * SOFTWARE. */ - #include "config.h" -#ifdef HAVE_SYS_PARAM_H -#include <sys/param.h> -#endif - -#ifdef HAVE_SYS_TYPES_H -#include <sys/types.h> -#endif - -#ifdef HAVE_SYS_SOCKET_H -#include <sys/socket.h> /* needed to define AF_ values on UNIX */ -#endif +#include "inet_addr-int.h" -#ifdef HAVE_WINSOCK2_H -#include <winsock2.h> /* needed to define AF_ values on Windows */ -#if _MSC_VER < 1600 /* errno.h defines EAFNOSUPPORT in Windows VC10 (and presumably eventually in VC11 ...) */ -#define EAFNOSUPPORT WSAEAFNOSUPPORT -#endif -#endif +#include <string.h> +#include <errno.h> -#ifdef HAVE_NETINET_IN_H -#include <netinet/in.h> -#endif +#include <glib.h> -#ifdef HAVE_ARPA_INET_H -#include <arpa/inet.h> -#endif +#include <wsutil/ws_diag_control.h> -#ifdef HAVE_ARPA_NAMESER_H -#include <arpa/nameser.h> +#ifndef __P +#define __P(args) args #endif -#include <errno.h> -#include <stdio.h> -#include <string.h> - -#include "inet_v6defs.h" - -#include <glib.h> - #ifndef NS_INADDRSZ #define NS_INADDRSZ 4 #endif @@ -67,6 +40,8 @@ #define NS_INT16SZ 2 #endif +DIAG_OFF(c++-compat) + /* * WARNING: Don't even consider trying to compile this on a system where * sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX. @@ -84,11 +59,7 @@ static const char *inet_ntop6 __P((const u_char *src, char *dst, size_t size)); * Paul Vixie, 1996. */ const char * -inet_ntop(af, src, dst, size) - int af; - const void *src; - char *dst; - size_t size; +inet_ntop(int af, const void *src, char *dst, size_t size) { switch (af) { case AF_INET: @@ -114,10 +85,7 @@ inet_ntop(af, src, dst, size) * Paul Vixie, 1996. */ static const char * -inet_ntop4(src, dst, size) - const u_char *src; - char *dst; - size_t size; +inet_ntop4(const u_char *src, char *dst, size_t size) { static const char fmt[] = "%u.%u.%u.%u"; char tmp[sizeof "255.255.255.255"]; @@ -140,10 +108,7 @@ inet_ntop4(src, dst, size) * Paul Vixie, 1996. */ static const char * -inet_ntop6(src, dst, size) - const u_char *src; - char *dst; - size_t size; +inet_ntop6(const u_char *src, char *dst, size_t size) { /* * Note that int32_t and int16_t need only be "at least" large enough diff --git a/wsutil/inet_pton.c b/wsutil/inet_pton.c index 28c295abb0..78b14fd3d6 100644 --- a/wsutil/inet_pton.c +++ b/wsutil/inet_pton.c @@ -17,42 +17,19 @@ #include "config.h" -#ifdef HAVE_SYS_PARAM_H -#include <sys/param.h> -#endif - -#ifdef HAVE_SYS_TYPES_H -#include <sys/types.h> -#endif - -#ifdef HAVE_SYS_SOCKET_H -#include <sys/socket.h> /* needed to define AF_ values on UNIX */ -#endif +#include "inet_addr-int.h" -#ifdef HAVE_WINSOCK2_H -#include <winsock2.h> /* needed to define AF_ values on Windows */ -#if _MSC_VER < 1600 /* errno.h defines EAFNOSUPPORT in Windows VC10 (and presumably eventually in VC11 ...) */ -#define EAFNOSUPPORT WSAEAFNOSUPPORT -#endif -#endif +#include <string.h> +#include <errno.h> -#ifdef HAVE_NETINET_IN_H -#include <netinet/in.h> -#endif +#include <glib.h> -#ifdef HAVE_ARPA_INET_H -#include <arpa/inet.h> -#endif +#include <wsutil/ws_diag_control.h> -#ifdef HAVE_ARPA_NAMESER_H -#include <arpa/nameser.h> +#ifndef __P +#define __P(args) args #endif -#include <string.h> -#include <errno.h> - -#include "inet_v6defs.h" - #ifndef NS_INADDRSZ #define NS_INADDRSZ 4 #endif @@ -63,6 +40,8 @@ #define NS_INT16SZ 2 #endif +DIAG_OFF(c++-compat) + /* * WARNING: Don't even consider trying to compile this on a system where * sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX. @@ -87,10 +66,7 @@ static int inet_pton6 __P((const char *src, u_char *dst)); * Paul Vixie, 1996. */ int -inet_pton(af, src, dst) - int af; - const char *src; - void *dst; +inet_pton(int af, const char *src, void *dst) { switch (af) { #ifdef AF_INET @@ -120,9 +96,7 @@ inet_pton(af, src, dst) * Paul Vixie, 1996. */ static int -inet_pton4(src, dst) - const char *src; - u_char *dst; +inet_pton4(const char *src, u_char *dst) { static const char digits[] = "0123456789"; int saw_digit, octets, ch; @@ -175,9 +149,7 @@ inet_pton4(src, dst) * Paul Vixie, 1996. */ static int -inet_pton6(src, dst) - const char *src; - u_char *dst; +inet_pton6(const char *src, u_char *dst) { static const char xdigits_l[] = "0123456789abcdef", xdigits_u[] = "0123456789ABCDEF"; |