From eae216ef1db4b22e533231c8766cf4fad148eda6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Valverde?= Date: Wed, 25 Oct 2017 00:29:14 +0100 Subject: Remove replacement inet_pton/inet_ntop Should be available on every platform we support. Change-Id: Ib65d78e351d22d581b427e5e93fc8d5e5348b260 Reviewed-on: https://code.wireshark.org/review/24047 Reviewed-by: Gerald Combs Petri-Dish: Gerald Combs Tested-by: Petri Dish Buildbot Reviewed-by: Michael Mann --- ConfigureChecks.cmake | 2 - cmakeconfig.h.in | 6 -- configure.ac | 1 - tools/pre-commit-ignore.conf | 2 - wsutil/.editorconfig | 8 -- wsutil/CMakeLists.txt | 2 - wsutil/Makefile.am | 5 +- wsutil/inet_addr-int.h | 64 ----------- wsutil/inet_addr.c | 23 +++- wsutil/inet_ntop.c | 209 ------------------------------------ wsutil/inet_pton.c | 248 ------------------------------------------- 11 files changed, 21 insertions(+), 549 deletions(-) delete mode 100644 wsutil/inet_addr-int.h delete mode 100644 wsutil/inet_ntop.c delete mode 100644 wsutil/inet_pton.c diff --git a/ConfigureChecks.cmake b/ConfigureChecks.cmake index d9cdc0b547..bdbd6329b5 100644 --- a/ConfigureChecks.cmake +++ b/ConfigureChecks.cmake @@ -114,8 +114,6 @@ if(HAVE_GETOPT_LONG) endif() check_function_exists("getprotobynumber" HAVE_GETPROTOBYNUMBER) check_function_exists("getifaddrs" HAVE_GETIFADDRS) -check_function_exists("inet_ntop" HAVE_INET_NTOP) -check_function_exists("inet_pton" HAVE_INET_PTON) check_function_exists("issetugid" HAVE_ISSETUGID) check_function_exists("mkdtemp" HAVE_MKDTEMP) check_function_exists("mkstemps" HAVE_MKSTEMPS) diff --git a/cmakeconfig.h.in b/cmakeconfig.h.in index 6fe980b08c..fe5491cc08 100644 --- a/cmakeconfig.h.in +++ b/cmakeconfig.h.in @@ -104,12 +104,6 @@ /* Define to use heimdal kerberos */ #cmakedefine HAVE_HEIMDAL_KERBEROS 1 -/* Define to 1 if you have the `inet_ntop' function. */ -#cmakedefine HAVE_INET_NTOP 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 diff --git a/configure.ac b/configure.ac index b2363193f0..7e368c6cf4 100644 --- a/configure.ac +++ b/configure.ac @@ -2366,7 +2366,6 @@ if test "x$ac_cv_func_getopt_long" = xyes; then fi fi -AC_REPLACE_FUNCS(inet_pton inet_ntop) AC_REPLACE_FUNCS(strptime) AC_REPLACE_FUNCS(popcount) diff --git a/tools/pre-commit-ignore.conf b/tools/pre-commit-ignore.conf index 503f1e259b..6110bac094 100644 --- a/tools/pre-commit-ignore.conf +++ b/tools/pre-commit-ignore.conf @@ -18,7 +18,5 @@ epan/wmem/wmem_strutil.c extcap/* tools/lemon/* wsutil/file_util.h -wsutil/inet_ntop.c -wsutil/inet_pton.c wsutil/strptime.c wsutil/getopt_long.c diff --git a/wsutil/.editorconfig b/wsutil/.editorconfig index f3406ee5a9..7e659188ca 100644 --- a/wsutil/.editorconfig +++ b/wsutil/.editorconfig @@ -57,14 +57,6 @@ indent_size = tab indent_style = tab indent_size = tab -[inet_ntop.[ch]] -indent_style = tab -indent_size = tab - -[inet_pton.[ch]] -indent_style = tab -indent_size = tab - [interface.[ch]] indent_style = tab indent_size = tab diff --git a/wsutil/CMakeLists.txt b/wsutil/CMakeLists.txt index e00c493d19..2102dcb5ba 100644 --- a/wsutil/CMakeLists.txt +++ b/wsutil/CMakeLists.txt @@ -136,8 +136,6 @@ set(WSUTIL_FILES ${WSUTIL_COMMON_FILES}) if(WIN32) list(APPEND WSUTIL_FILES file_util.c - inet_ntop.c - inet_pton.c win32-utils.c ) ENDIF(WIN32) diff --git a/wsutil/Makefile.am b/wsutil/Makefile.am index 5f0fad20b8..bea58f3dde 100644 --- a/wsutil/Makefile.am +++ b/wsutil/Makefile.am @@ -92,8 +92,7 @@ WSUTIL_PUBLIC_INCLUDES = \ wspcap.h \ xtea.h -WSUTIL_PRIVATE_INCLUDES = \ - inet_addr-int.h +WSUTIL_PRIVATE_INCLUDES = subpkgincludedir = $(pkgincludedir)/wsutil @@ -192,8 +191,6 @@ EXTRA_DIST = \ file_util.h \ getopt_long.c \ getopt_long.h \ - inet_ntop.c \ - inet_pton.c \ popcount.c \ popcount.h \ strptime.c \ diff --git a/wsutil/inet_addr-int.h b/wsutil/inet_addr-int.h deleted file mode 100644 index c702a9a435..0000000000 --- a/wsutil/inet_addr-int.h +++ /dev/null @@ -1,64 +0,0 @@ -/* inet_addr-int.h - * - * Wireshark - Network traffic analyzer - * By Gerald Combs - * 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_INT_H__ -#define __WS_INET_ADDR_INT_H__ - -#ifdef HAVE_ARPA_INET_H -#include -#endif - -#ifdef HAVE_SYS_TYPES_H -#include -#endif - -#ifdef HAVE_SYS_SOCKET_H -#include /* needed to define AF_ values on UNIX */ -#endif - -#ifdef HAVE_WINSOCK2_H -#include /* 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. - */ -#ifndef HAVE_INET_PTON -extern int inet_pton(int af, const char *src, void *dst); -#endif - -#ifndef HAVE_INET_NTOP -extern const char *inet_ntop(int af, const void *src, char *dst, size_t size); -#endif - -/* - * Those OSes may also not have AF_INET6, so declare it here if it's not - * already declared, so that we can pass it to "inet_ntop()" and "inet_pton()". - */ -#ifndef AF_INET6 -#define AF_INET6 127 /* pick a value unlikely to duplicate an existing AF_ value */ -#endif - -#endif diff --git a/wsutil/inet_addr.c b/wsutil/inet_addr.c index 0059f6ccfb..d7f756031e 100644 --- a/wsutil/inet_addr.c +++ b/wsutil/inet_addr.c @@ -23,7 +23,24 @@ #include "inet_addr.h" -#include "inet_addr-int.h" +#ifdef HAVE_ARPA_INET_H +#include +#endif + +#ifdef HAVE_SYS_TYPES_H +#include +#endif + +#ifdef HAVE_SYS_SOCKET_H +#include /* needed to define AF_ values on UNIX */ +#endif + +#ifdef _WIN32 +#include /* indirectly defines AF_ values on Windows */ +#define _NTOP_SRC_CAST_ (PVOID) +#else +#define _NTOP_SRC_CAST_ +#endif static inline gboolean _inet_pton(int af, const gchar *src, gpointer dst) @@ -38,7 +55,7 @@ _inet_pton(int af, const gchar *src, gpointer dst) const gchar * ws_inet_ntop4(gconstpointer src, gchar *dst, guint dst_size) { - return inet_ntop(AF_INET, src, dst, dst_size); + return inet_ntop(AF_INET, _NTOP_SRC_CAST_ src, dst, dst_size); } gboolean @@ -50,7 +67,7 @@ ws_inet_pton4(const gchar *src, guint32 *dst) const gchar * ws_inet_ntop6(gconstpointer src, gchar *dst, guint dst_size) { - return inet_ntop(AF_INET6, src, dst, dst_size); + return inet_ntop(AF_INET6, _NTOP_SRC_CAST_ src, dst, dst_size); } gboolean diff --git a/wsutil/inet_ntop.c b/wsutil/inet_ntop.c deleted file mode 100644 index 1d82f30142..0000000000 --- a/wsutil/inet_ntop.c +++ /dev/null @@ -1,209 +0,0 @@ -/* - * Copyright (c) 1996-1999 by Internet Software Consortium. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. - */ - -#include - -#include "inet_addr-int.h" - -#include -#include - -#include - -#ifndef __P -#define __P(args) args -#endif - -#ifndef NS_INADDRSZ -#define NS_INADDRSZ 4 -#endif -#ifndef NS_IN6ADDRSZ -#define NS_IN6ADDRSZ 16 -#endif -#ifndef NS_INT16SZ -#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. - */ - -static const char *inet_ntop4 __P((const u_char *src, char *dst, size_t size)); -static const char *inet_ntop6 __P((const u_char *src, char *dst, size_t size)); - -/* char * - * inet_ntop(af, src, dst, size) - * convert a network format address to presentation format. - * return: - * pointer to presentation format address (`dst'), or NULL (see errno). - * author: - * Paul Vixie, 1996. - */ -const char * -inet_ntop(int af, const void *src, char *dst, size_t size) -{ - switch (af) { - case AF_INET: - return (inet_ntop4(src, dst, size)); - case AF_INET6: - return (inet_ntop6(src, dst, size)); - default: - errno = EAFNOSUPPORT; - return (NULL); - } - /* NOTREACHED */ -} - -/* const char * - * inet_ntop4(src, dst, size) - * format an IPv4 address - * return: - * `dst' (as a const) - * notes: - * (1) uses no statics - * (2) takes a u_char* not an in_addr as input - * author: - * Paul Vixie, 1996. - */ -static const char * -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"]; - int nprinted; - - nprinted = g_snprintf(tmp, sizeof(tmp), fmt, src[0], src[1], src[2], src[3]); - /* Note: nprinted *excludes* the trailing '\0' character */ - if ((size_t)nprinted >= size) { - errno = ENOSPC; - return (NULL); - } - g_strlcpy(dst, tmp, size); - return (dst); -} - -/* const char * - * inet_ntop6(src, dst, size) - * convert IPv6 binary address into presentation (printable) format - * author: - * Paul Vixie, 1996. - */ -static const char * -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 - * to contain a value of the specified size. On some systems, like - * Crays, there is no such thing as an integer variable with 16 bits. - * Keep this in mind if you think this function should have been coded - * to use pointer overlays. All the world's not a VAX. - */ - char tmp[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"], *tp; - struct { int base, len; } best, cur; - u_int words[NS_IN6ADDRSZ / NS_INT16SZ]; - int i; - - /* - * Preprocess: - * Copy the input (bytewise) array into a wordwise array. - * Find the longest run of 0x00's in src[] for :: shorthanding. - */ - memset(&best, 0, sizeof best); - memset(&cur, 0, sizeof cur); - memset(words, '\0', sizeof words); - for (i = 0; i < NS_IN6ADDRSZ; i++) - words[i / 2] |= (src[i] << ((1 - (i % 2)) << 3)); - best.base = -1; - cur.base = -1; - for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++) { - if (words[i] == 0) { - if (cur.base == -1) - cur.base = i, cur.len = 1; - else - cur.len++; - } else { - if (cur.base != -1) { - if (best.base == -1 || cur.len > best.len) - best = cur; - cur.base = -1; - } - } - } - if (cur.base != -1) { - if (best.base == -1 || cur.len > best.len) - best = cur; - } - if (best.base != -1 && best.len < 2) - best.base = -1; - - /* - * Format the result. - */ - tp = tmp; - for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++) { - /* Are we inside the best run of 0x00's? */ - if (best.base != -1 && i >= best.base && - i < (best.base + best.len)) { - if (i == best.base) - *tp++ = ':'; - continue; - } - /* Are we following an initial run of 0x00s or any real hex? */ - if (i != 0) - *tp++ = ':'; - /* Is this address an encapsulated IPv4? */ - if (i == 6 && best.base == 0 && - (best.len == 6 || (best.len == 5 && words[5] == 0xffff))) { - if (!inet_ntop4(src+12, tp, sizeof tmp - (tp - tmp))) - return (NULL); - tp += strlen(tp); - break; - } - tp += g_snprintf(tp, (gulong) (sizeof tmp - (tp - tmp)), "%x", words[i]); - } - /* Was it a trailing run of 0x00's? */ - if (best.base != -1 && (best.base + best.len) == - (NS_IN6ADDRSZ / NS_INT16SZ)) - *tp++ = ':'; - *tp++ = '\0'; - - /* - * Check for overflow, copy, and we're done. - */ - if ((size_t)(tp - tmp) > size) { - errno = ENOSPC; - return (NULL); - } - g_strlcpy(dst, tmp, size); - return (dst); -} - -/* - * Editor modelines - http://www.wireshark.org/tools/modelines.html - * - * Local variables: - * c-basic-offset: 8 - * tab-width: 8 - * indent-tabs-mode: t - * End: - * - * vi: set shiftwidth=8 tabstop=8 noexpandtab: - * :indentSize=8:tabSize=8:noTabs=false: - */ diff --git a/wsutil/inet_pton.c b/wsutil/inet_pton.c deleted file mode 100644 index 3c2b6b4620..0000000000 --- a/wsutil/inet_pton.c +++ /dev/null @@ -1,248 +0,0 @@ -/* - * Copyright (c) 1996,1999 by Internet Software Consortium. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. - */ - -#include - -#include "inet_addr-int.h" - -#include -#include - -#include - -#ifndef __P -#define __P(args) args -#endif - -#ifndef NS_INADDRSZ -#define NS_INADDRSZ 4 -#endif -#ifndef NS_IN6ADDRSZ -#define NS_IN6ADDRSZ 16 -#endif -#ifndef NS_INT16SZ -#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. - */ - -#ifdef AF_INET -static int inet_pton4 __P((const char *src, u_char *dst)); -#endif -#ifdef AF_INET6 -static int inet_pton6 __P((const char *src, u_char *dst)); -#endif - -/* int - * inet_pton(af, src, dst) - * convert from presentation format (which usually means ASCII printable) - * to network format (which is usually some kind of binary format). - * return: - * 1 if the address was valid for the specified address family - * 0 if the address wasn't valid (`dst' is untouched in this case) - * -1 if some other error occurred (`dst' is untouched in this case, too) - * author: - * Paul Vixie, 1996. - */ -int -inet_pton(int af, const char *src, void *dst) -{ - switch (af) { -#ifdef AF_INET - case AF_INET: - return (inet_pton4(src, dst)); -#endif -#ifdef AF_INET6 - case AF_INET6: - return (inet_pton6(src, dst)); -#endif - default: - errno = EAFNOSUPPORT; - return (-1); - } - /* NOTREACHED */ -} - -#ifdef AF_INET -/* int - * inet_pton4(src, dst) - * like inet_aton() but without all the hexadecimal and shorthand. - * return: - * 1 if `src' is a valid dotted quad, else 0. - * notice: - * does not touch `dst' unless it's returning 1. - * author: - * Paul Vixie, 1996. - */ -static int -inet_pton4(const char *src, u_char *dst) -{ - static const char digits[] = "0123456789"; - int saw_digit, octets, ch; - u_char tmp[NS_INADDRSZ], *tp; - - saw_digit = 0; - octets = 0; - *(tp = tmp) = 0; - while ((ch = *src++) != '\0') { - const char *pch; - - if ((pch = strchr(digits, ch)) != NULL) { - size_t new = *tp * 10 + (pch - digits); - - if (new > 255) - return (0); - *tp = (u_char) new; - if (! saw_digit) { - if (++octets > 4) - return (0); - saw_digit = 1; - } - } else if (ch == '.' && saw_digit) { - if (octets == 4) - return (0); - *++tp = 0; - saw_digit = 0; - } else - return (0); - } - if (octets < 4) - return (0); - memcpy(dst, tmp, NS_INADDRSZ); - return (1); -} -#endif - -#ifdef AF_INET6 -/* int - * inet_pton6(src, dst) - * convert presentation level address to network order binary form. - * return: - * 1 if `src' is a valid [RFC1884 2.2] address, else 0. - * notice: - * (1) does not touch `dst' unless it's returning 1. - * (2) :: in a full address is silently ignored. - * credit: - * inspired by Mark Andrews. - * author: - * Paul Vixie, 1996. - */ -static int -inet_pton6(const char *src, u_char *dst) -{ - static const char xdigits_l[] = "0123456789abcdef", - xdigits_u[] = "0123456789ABCDEF"; - u_char tmp[NS_IN6ADDRSZ], *tp, *endp, *colonp; - const char *xdigits, *curtok; - int ch, saw_xdigit; - u_int val; - - memset((tp = tmp), '\0', NS_IN6ADDRSZ); - endp = tp + NS_IN6ADDRSZ; - colonp = NULL; - /* Leading :: requires some special handling. */ - if (*src == ':') - if (*++src != ':') - return (0); - curtok = src; - saw_xdigit = 0; - val = 0; - while ((ch = *src++) != '\0') { - const char *pch; - - if ((pch = strchr((xdigits = xdigits_l), ch)) == NULL) - pch = strchr((xdigits = xdigits_u), ch); - if (pch != NULL) { - val <<= 4; - val |= (pch - xdigits); - if (val > 0xffff) - return (0); - saw_xdigit = 1; - continue; - } - if (ch == ':') { - curtok = src; - if (!saw_xdigit) { - if (colonp) - return (0); - colonp = tp; - continue; - } else if (*src == '\0') { - return (0); - } - if (tp + NS_INT16SZ > endp) - return (0); - *tp++ = (u_char) (val >> 8) & 0xff; - *tp++ = (u_char) val & 0xff; - saw_xdigit = 0; - val = 0; - continue; - } - if (ch == '.' && ((tp + NS_INADDRSZ) <= endp) && - inet_pton4(curtok, tp) > 0) { - tp += NS_INADDRSZ; - saw_xdigit = 0; - break; /* '\0' was seen by inet_pton4(). */ - } - return (0); - } - if (saw_xdigit) { - if (tp + NS_INT16SZ > endp) - return (0); - *tp++ = (u_char) (val >> 8) & 0xff; - *tp++ = (u_char) val & 0xff; - } - if (colonp != NULL) { - /* - * Since some memmove()'s erroneously fail to handle - * overlapping regions, we'll do the shift by hand. - */ - const int n = (int) (tp - colonp); - int i; - - if (tp == endp) - return (0); - for (i = 1; i <= n; i++) { - endp[- i] = colonp[n - i]; - colonp[n - i] = 0; - } - tp = endp; - } - if (tp != endp) - return (0); - memcpy(dst, tmp, NS_IN6ADDRSZ); - return (1); -} -#endif - -/* - * Editor modelines - http://www.wireshark.org/tools/modelines.html - * - * Local variables: - * c-basic-offset: 8 - * tab-width: 8 - * indent-tabs-mode: t - * End: - * - * vi: set shiftwidth=8 tabstop=8 noexpandtab: - * :indentSize=8:tabSize=8:noTabs=false: - */ -- cgit v1.2.3