From: Guy Harris Date: Mon, 29 Jan 2018 10:16:13 +0000 (-0800) Subject: Not all Windows pcaps have pcap_wsockinit(). X-Git-Tag: tcpdump-4.99-bp~1323 X-Git-Url: https://git.tcpdump.org/tcpdump/commitdiff_plain/0fb509808c60edc0ed52ca355306452a4ca91286 Not all Windows pcaps have pcap_wsockinit(). WinPcap 4.1.3 has only wsockinit(); check for both, on Windows. --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 848626f5..7e2b9db5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -593,6 +593,17 @@ check_function_exists(pcap_dump_ftell64 HAVE_PCAP_DUMP_FTELL64) check_function_exists(pcap_open HAVE_PCAP_OPEN) check_function_exists(pcap_findalldevs_ex HAVE_PCAP_FINDALLDEVS_EX) +# +# On Windows, check for pcap_wsockinit(); if we don't have it, check for +# wsockinit(). +# +if(WIN32) + check_function_exists(pcap_wsockinit HAVE_PCAP_WSOCKINIT) + if(NOT HAVE_PCAP_WSOCKINIT) + check_function_exists(wsockinit HAVE_WSOCKINIT) + endif(NOT HAVE_PCAP_WSOCKINIT) +endif(WIN32) + # # Check for special debugging functions # diff --git a/cmakeconfig.h.in b/cmakeconfig.h.in index 039bc5f3..2d28585e 100644 --- a/cmakeconfig.h.in +++ b/cmakeconfig.h.in @@ -174,6 +174,9 @@ /* define if libpcap has pcap_version */ #cmakedefine HAVE_PCAP_VERSION 1 +/* Define to 1 if you have the `pcap_wsockinit' function. */ +#cmakedefine HAVE_PCAP_WSOCKINIT 1 + /* Define to 1 if you have the `pfopen' function. */ #cmakedefine HAVE_PFOPEN 1 @@ -240,6 +243,9 @@ /* Define to 1 if you have the `vsnprintf' function. */ #cmakedefine HAVE_VSNPRINTF 1 +/* Define to 1 if you have the `wsockinit' function. */ +#cmakedefine HAVE_WSOCKINIT 1 + /* define if libpcap has yydebug */ #cmakedefine HAVE_YYDEBUG 1 diff --git a/tcpdump.c b/tcpdump.c index ddd5551d..b325b28c 100644 --- a/tcpdump.c +++ b/tcpdump.c @@ -1346,10 +1346,13 @@ main(int argc, char **argv) else ndo->program_name = program_name = argv[0]; -#ifdef _WIN32 +#if defined(HAVE_PCAP_WSOCKINIT) if (pcap_wsockinit() != 0) error("Attempting to initialize Winsock failed"); -#endif /* _WIN32 */ +#elif defined(HAVE_WSOCKINIT) + if (wsockinit() != 0) + error("Attempting to initialize Winsock failed"); +#endif /* * On platforms where the CPU doesn't support unaligned loads,