diff --git a/ConfigureChecks.cmake b/ConfigureChecks.cmake index d04c61b17a..5eaf77f163 100644 --- a/ConfigureChecks.cmake +++ b/ConfigureChecks.cmake @@ -117,7 +117,7 @@ endif() check_function_exists("getprotobynumber" HAVE_GETPROTOBYNUMBER) check_function_exists("getifaddrs" HAVE_GETIFADDRS) check_function_exists("inet_aton" HAVE_INET_ATON) -check_function_exists("inet_ntop" HAVE_INET_NTOP_PROTO) +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) diff --git a/cmakeconfig.h.in b/cmakeconfig.h.in index a3cddcc8bd..75d9433582 100644 --- a/cmakeconfig.h.in +++ b/cmakeconfig.h.in @@ -109,8 +109,8 @@ /* Define to 1 if you have the `inet_aton' function. */ #cmakedefine HAVE_INET_ATON 1 -/* Define if inet_ntop() prototype exists */ -#cmakedefine HAVE_INET_NTOP_PROTO 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 diff --git a/configure.ac b/configure.ac index ed3d68ab7b..338e15b8e0 100644 --- a/configure.ac +++ b/configure.ac @@ -56,6 +56,8 @@ AC_DEFINE(VERSION_FLAVOR, "Development Build", [Wireshark's package flavor]) AM_DISABLE_STATIC +AC_CONFIG_LIBOBJ_DIR([wsutil]) + # # Checks for programs used in the main build process. # @@ -2706,43 +2708,22 @@ AC_PROG_GCC_TRADITIONAL AC_CHECK_FUNCS([getaddrinfo]) -AC_CHECK_FUNC(getopt_long, - [ - GETOPT_LO="" - AC_DEFINE(HAVE_GETOPT_LONG, 1, [Define to 1 if you have the getopt_long function.]) +AC_REPLACE_FUNCS(getopt_long) +dnl +dnl Do we have optreset? +dnl +if test "x$ac_cv_func_getopt_long" = xyes; then + AC_CACHE_CHECK([whether optreset is defined], ac_cv_have_optreset, + AC_LINK_IFELSE([AC_LANG_SOURCE([[extern int optreset;return optreset;]])], + ac_cv_have_optreset=yes, ac_cv_have_optreset=no)) + if test "$ac_cv_have_optreset" = yes ; then + AC_DEFINE(HAVE_OPTRESET, 1, [Define to 1 if you have the optreset variable]) + fi +fi - # - # Do we have optreset? - # - AC_CACHE_CHECK([whether optreset is defined], - [ac_cv_optreset_defined], [ - AC_TRY_LINK([], - [ - extern int optreset; +AC_REPLACE_FUNCS(inet_aton) - return optreset; - ], - ac_cv_optreset_defined=yes, - ac_cv_optreset_defined=no) - ]) - if test "$ac_cv_optreset_defined" = yes ; then - AC_DEFINE(HAVE_OPTRESET, 1, [Define to 1 if you have the optreset variable]) - fi - ], - GETOPT_LO="wsgetopt.lo") -AC_SUBST(GETOPT_LO) - -AC_CHECK_FUNCS(mkstemp mkdtemp) - -AC_SEARCH_LIBS(inet_aton, [socket nsl], - [ - INET_ATON_LO="" - AC_DEFINE(HAVE_INET_ATON, 1, [Define to 1 if you have the inet_aton function.]) - ], - INET_ATON_LO="inet_aton.lo") -AC_SUBST(INET_ATON_LO) - -AC_SEARCH_LIBS(inet_pton, [socket nsl], [ +AC_CHECK_FUNC(inet_pton, [ dnl check for pre-BIND82 inet_pton() bug. AC_MSG_CHECKING(for broken inet_pton) AC_TRY_RUN([#include @@ -2760,63 +2741,20 @@ int main() #endif }], [AC_MSG_RESULT(ok); have_inet_pton=yes], [AC_MSG_RESULT(broken); -have_inet_pton=no], [AC_MSG_RESULT(cross compiling, assume it is broken); +have_inet_pton=no], [AC_MSG_RESULT([cross compiling, assume it is broken]); have_inet_pton=no])], have_inet_pton=no) if test "$have_inet_pton" = no; then - INET_PTON_LO="inet_pton.lo" + AC_LIBOBJ(inet_pton) else - AC_DEFINE(HAVE_INET_PTON, 1, - [Define to 1 if you have the `inet_pton' function.]) - INET_PTON_LO="" + AC_DEFINE(HAVE_INET_PTON, 1, [Define to 1 if you have the `inet_pton' function.]) fi -AM_CONDITIONAL(NEED_INET_PTON_LO, test "x$have_inet_pton" = "xno") -AC_SUBST(INET_PTON_LO) -AC_SEARCH_LIBS(inet_ntop, [socket nsl], [ - AC_MSG_CHECKING([for inet_ntop prototype]) - AC_TRY_COMPILE([#include -#include -#include -#include -#include - -extern const char *inet_ntop(int, const void *, char *, size_t);],, [ - AC_MSG_RESULT(yes) - AC_DEFINE(HAVE_INET_NTOP_PROTO, 1, - [Define if inet_ntop() prototype exists])], [ - AC_TRY_COMPILE([#include -#include -#include -#include -#include - -extern const char *inet_ntop(int, const void *, char *, socklen_t);],, [ - AC_MSG_RESULT(yes) - AC_DEFINE(HAVE_INET_NTOP_PROTO, 1, - [Define if inet_ntop() prototype exists])], [ - AC_MSG_RESULT(no)])]) - INET_NTOP_LO=""], [ - INET_NTOP_LO="inet_ntop.lo"]) -AM_CONDITIONAL(NEED_INET_NTOP_LO, test "x$INET_NTOP_LO" != "x") -AC_SUBST(INET_NTOP_LO) - -AC_CHECK_FUNC(strptime, - [ - STRPTIME_LO="" - AC_DEFINE(HAVE_STRPTIME, 1, [Define if you have the strptime function.]) - ], - STRPTIME_LO="strptime.lo") -AC_SUBST(STRPTIME_LO) - -AC_CHECK_FUNC(popcount, - [ - POPCOUNT_LO="" - AC_DEFINE(HAVE_POPCOUNT, 1, [Define if you have the popcount function.]) - ], - POPCOUNT_LO="popcount.lo") -AC_SUBST(POPCOUNT_LO) +AC_REPLACE_FUNCS(inet_ntop) +AC_REPLACE_FUNCS(strptime) +AC_REPLACE_FUNCS(popcount) +AC_CHECK_FUNCS(mkstemp mkdtemp) AC_CHECK_FUNCS(getprotobynumber) AC_CHECK_FUNCS(issetugid) AC_CHECK_FUNCS(sysconf) diff --git a/tools/pre-commit-ignore.conf b/tools/pre-commit-ignore.conf index 78631138f0..e792592484 100644 --- a/tools/pre-commit-ignore.conf +++ b/tools/pre-commit-ignore.conf @@ -15,3 +15,5 @@ tools/lemon/* wsutil/inet_aton.c wsutil/inet_ntop.c wsutil/inet_pton.c +wsutil/strptime.c +wsutil/getopt_long.c diff --git a/wsutil/CMakeLists.txt b/wsutil/CMakeLists.txt index c134037d1f..9eeda808bc 100644 --- a/wsutil/CMakeLists.txt +++ b/wsutil/CMakeLists.txt @@ -146,7 +146,7 @@ if(HAVE_SSE4_2) endif() if(NOT HAVE_GETOPT_LONG) - set(WSUTIL_FILES ${WSUTIL_FILES} wsgetopt.c) + set(WSUTIL_FILES ${WSUTIL_FILES} getopt_long.c) endif() if(NOT HAVE_INET_ATON) diff --git a/wsutil/Makefile.am b/wsutil/Makefile.am index 434457ccd8..6b8de84d28 100644 --- a/wsutil/Makefile.am +++ b/wsutil/Makefile.am @@ -42,13 +42,7 @@ libwsutil_abi_INCLUDES = \ # Optional objects that I know how to build. These will be # linked into libwsutil if necessary. -wsutil_optional_objects = \ - @GETOPT_LO@ \ - @INET_ATON_LO@ \ - @INET_NTOP_LO@ \ - @INET_PTON_LO@ \ - @POPCOUNT_LO@ \ - @STRPTIME_LO@ +wsutil_optional_objects = if SSE42_SUPPORTED wsutil_optional_objects += libwsutil_sse42.la @@ -78,23 +72,14 @@ libwsutil_sse42_la_SOURCES = \ libwsutil_sse42_la_CFLAGS = $(AM_CFLAGS) $(CFLAGS_SSE42) EXTRA_libwsutil_la_SOURCES = \ - inet_aton.c \ - inet_aton.h \ - inet_ntop.c \ - inet_pton.c \ inet_addr-int.h \ - popcount.c \ - popcount.h \ - strptime.c \ - strptime.h \ - wsgetopt.c \ - wsgetopt.h \ - wsgetopt_int.h + wsgetopt.h -libwsutil_la_DEPENDENCIES = \ +EXTRA_libwsutil_la_DEPENDENCIES = \ $(wsutil_optional_objects) libwsutil_la_LIBADD = \ + $(LTLIBOBJS) \ @COREFOUNDATION_FRAMEWORKS@ \ @GLIB_LIBS@ \ @LIBGCRYPT_LIBS@ \ diff --git a/wsutil/wsgetopt.c b/wsutil/getopt_long.c similarity index 99% rename from wsutil/wsgetopt.c rename to wsutil/getopt_long.c index 5302bc7563..c44db3cb7d 100644 --- a/wsutil/wsgetopt.c +++ b/wsutil/getopt_long.c @@ -103,7 +103,7 @@ they can distinguish the relative order of options and other arguments. */ #include "wsgetopt.h" -#include "wsgetopt_int.h" +#include "getopt_long.h" /* For communication from `getopt' to the caller. When `getopt' finds an option that takes an argument, diff --git a/wsutil/wsgetopt_int.h b/wsutil/getopt_long.h similarity index 100% rename from wsutil/wsgetopt_int.h rename to wsutil/getopt_long.h diff --git a/wsutil/inet_addr-int.h b/wsutil/inet_addr-int.h index c71b1cd4ad..25f698d1df 100644 --- a/wsutil/inet_addr-int.h +++ b/wsutil/inet_addr-int.h @@ -51,7 +51,7 @@ extern int inet_pton(int af, const char *src, void *dst); #endif -#ifndef HAVE_INET_NTOP_PROTO +#ifndef HAVE_INET_NTOP extern const char *inet_ntop(int af, const void *src, char *dst, size_t size); #endif diff --git a/wsutil/inet_ntop.c b/wsutil/inet_ntop.c index 3fe730bcc6..1d82f30142 100644 --- a/wsutil/inet_ntop.c +++ b/wsutil/inet_ntop.c @@ -125,6 +125,8 @@ inet_ntop6(const u_char *src, char *dst, size_t size) * 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));