From cec5991f40887b4b2add594e7d82857d475224aa Mon Sep 17 00:00:00 2001 From: Gerald Combs Date: Tue, 30 Apr 2019 15:48:06 -0700 Subject: Windows: Modernize our WSAStartup usage. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Make sure we link each application that calls WSAStartup with ws2_32.lib. Pass version 2.2 to WSAStartup. Wikipedia says it was introduced in 1996, so we should be OK. Ping-Bug: 15711 Change-Id: I431839e930e7c646669af7373789640b5180ec28 Reviewed-on: https://code.wireshark.org/review/33033 Petri-Dish: Gerald Combs Reviewed-by: Tomasz Moń Tested-by: Petri Dish Buildbot Reviewed-by: Gerald Combs --- CMakeLists.txt | 10 ++++++---- docbook/wsdg_src/WSDG_chapter_tools.adoc | 2 +- dumpcap.c | 4 +--- extcap/CMakeLists.txt | 6 ++++++ extcap/androiddump.c | 2 +- extcap/ciscodump.c | 2 +- extcap/randpktdump.c | 2 +- extcap/sshdump.c | 2 +- extcap/udpdump.c | 2 +- rawshark.c | 2 +- sharkd_daemon.c | 2 +- tshark.c | 2 +- ui/qt/main.cpp | 2 +- wsutil/CMakeLists.txt | 2 +- 14 files changed, 24 insertions(+), 18 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e2fdafc227..84c2b0d133 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1255,7 +1255,7 @@ endif() # if(WIN32) set(WIN_PSAPI_LIBRARY psapi.lib) - set(WIN_WSOCK32_LIBRARY wsock32.lib) + set(WIN_WS2_32_LIBRARY ws2_32.lib) set(WIN_COMCTL32_LIBRARY comctl32.lib ) set(WIN_VERSION_LIBRARY version.lib) endif() @@ -2176,6 +2176,7 @@ if(BUILD_wireshark AND QT_FOUND) ${APPLE_APPKIT_LIBRARY} ${APPLE_CORE_FOUNDATION_LIBRARY} ${APPLE_SYSTEM_CONFIGURATION_LIBRARY} + ${WIN_WS2_32_LIBRARY} ${WIN_VERSION_LIBRARY} ${WINSPARKLE_LIBRARIES} $<$:UxTheme.lib> @@ -2290,6 +2291,7 @@ if(BUILD_tshark) ${VERSION_INFO_LIBS} ${APPLE_CORE_FOUNDATION_LIBRARY} ${APPLE_SYSTEM_CONFIGURATION_LIBRARY} + ${WIN_WS2_32_LIBRARY} ${M_LIBRARIES} ) set(tshark_FILES @@ -2341,6 +2343,7 @@ if(BUILD_rawshark AND PCAP_FOUND) ${VERSION_INFO_LIBS} ${APPLE_CORE_FOUNDATION_LIBRARY} ${APPLE_SYSTEM_CONFIGURATION_LIBRARY} + ${WIN_WS2_32_LIBRARY} ) set(rawshark_FILES $ @@ -2364,6 +2367,7 @@ if(BUILD_sharkd) ${VERSION_INFO_LIBS} ${APPLE_CORE_FOUNDATION_LIBRARY} ${APPLE_SYSTEM_CONFIGURATION_LIBRARY} + ${WIN_WS2_32_LIBRARY} ) set(sharkd_FILES # @@ -2380,9 +2384,6 @@ if(BUILD_sharkd) add_executable(sharkd ${sharkd_FILES}) set_extra_executable_properties(sharkd "Executables") target_link_libraries(sharkd ${sharkd_LIBS}) - if(WIN32) - target_link_libraries(sharkd "ws2_32.lib") - endif(WIN32) install(TARGETS sharkd RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endif() @@ -2563,6 +2564,7 @@ if(BUILD_dumpcap AND PCAP_FOUND) ${ZLIB_LIBRARIES} ${APPLE_CORE_FOUNDATION_LIBRARY} ${APPLE_SYSTEM_CONFIGURATION_LIBRARY} + ${WIN_WS2_32_LIBRARY} ) set(dumpcap_FILES $ diff --git a/docbook/wsdg_src/WSDG_chapter_tools.adoc b/docbook/wsdg_src/WSDG_chapter_tools.adoc index 17abe019d0..131b416a27 100644 --- a/docbook/wsdg_src/WSDG_chapter_tools.adoc +++ b/docbook/wsdg_src/WSDG_chapter_tools.adoc @@ -296,7 +296,7 @@ compiler, you'll need: . C runtime headers and libraries (e.g. _stdio.h_, _vcruntime140.lib_) . Windows platform headers and libraries (e.g. -_windows.h_, _WSock32.lib_) +_windows.h_, _WS2_32.lib_) + // Can we drop support for CHM? . HTML help headers and libraries (_htmlhelp.h_, _htmlhelp.lib_) diff --git a/dumpcap.c b/dumpcap.c index 9ea7076c35..5e1a7f32e7 100644 --- a/dumpcap.c +++ b/dumpcap.c @@ -2735,9 +2735,7 @@ capture_loop_open_input(capture_options *capture_opts, loop_data *ld, /* Initialize Windows Socket if we are in a Win32 OS This needs to be done before querying the interface for network/netmask */ #ifdef _WIN32 - /* XXX - do we really require 1.1 or earlier? - Are there any versions that support only 2.0 or higher? */ - wVersionRequested = MAKEWORD(1, 1); + wVersionRequested = MAKEWORD(2, 2); err = WSAStartup(wVersionRequested, &wsaData); if (err != 0) { switch (err) { diff --git a/extcap/CMakeLists.txt b/extcap/CMakeLists.txt index 3e59e7df90..9ed9be36e4 100644 --- a/extcap/CMakeLists.txt +++ b/extcap/CMakeLists.txt @@ -92,6 +92,7 @@ if(BUILD_androiddump) ui ${GLIB2_LIBRARIES} ${PCAP_LIBRARIES} + ${WIN_WS2_32_LIBRARY} ) else() message(FATAL_ERROR "You are trying to build androiddump with libpcap but do not have it") @@ -103,6 +104,7 @@ if(BUILD_androiddump) ${GLIB2_LIBRARIES} ${ZLIB_LIBRARIES} ${CMAKE_DL_LIBS} + ${WIN_WS2_32_LIBRARY} ) endif() set(androiddump_FILES @@ -124,6 +126,7 @@ if(BUILD_sshdump AND LIBSSH_FOUND) wsutil ${GLIB2_LIBRARIES} ${CMAKE_DL_LIBS} + ${WIN_WS2_32_LIBRARY} ${LIBSSH_LIBRARIES} ) set(sshdump_FILES @@ -150,6 +153,7 @@ if(BUILD_ciscodump AND LIBSSH_FOUND) wsutil ${GLIB2_LIBRARIES} ${CMAKE_DL_LIBS} + ${WIN_WS2_32_LIBRARY} ${LIBSSH_LIBRARIES} ) set(ciscodump_FILES @@ -198,6 +202,7 @@ if(BUILD_udpdump) set(udpdump_LIBS ${GLIB2_LIBRARIES} ${CMAKE_DL_LIBS} + ${WIN_WS2_32_LIBRARY} wsutil writecap ) @@ -222,6 +227,7 @@ if(BUILD_randpktdump) ${GLIB2_LIBRARIES} ${ZLIB_LIBRARIES} ${CMAKE_DL_LIBS} + ${WIN_WS2_32_LIBRARY} ) set(randpktdump_FILES $ diff --git a/extcap/androiddump.c b/extcap/androiddump.c index 676a02fde9..6ede174d52 100644 --- a/extcap/androiddump.c +++ b/extcap/androiddump.c @@ -2690,7 +2690,7 @@ int main(int argc, char *argv[]) { bt_local_tcp_port = &default_bt_local_tcp_port; #ifdef _WIN32 - result = WSAStartup(MAKEWORD(1,1), &wsaData); + result = WSAStartup(MAKEWORD(2, 2), &wsaData); if (result != 0) { g_warning("WSAStartup failed with %d", result); goto end; diff --git a/extcap/ciscodump.c b/extcap/ciscodump.c index 9a75d82813..b125353251 100644 --- a/extcap/ciscodump.c +++ b/extcap/ciscodump.c @@ -689,7 +689,7 @@ int main(int argc, char *argv[]) } #ifdef _WIN32 - result = WSAStartup(MAKEWORD(1,1), &wsaData); + result = WSAStartup(MAKEWORD(2, 2), &wsaData); if (result != 0) { g_warning("ERROR: WSAStartup failed with error: %d", result); goto end; diff --git a/extcap/randpktdump.c b/extcap/randpktdump.c index 28de98f64f..b4eec55da6 100644 --- a/extcap/randpktdump.c +++ b/extcap/randpktdump.c @@ -279,7 +279,7 @@ int main(int argc, char *argv[]) } #ifdef _WIN32 - result = WSAStartup(MAKEWORD(1,1), &wsaData); + result = WSAStartup(MAKEWORD(2, 2), &wsaData); if (result != 0) { g_warning("ERROR: WSAStartup failed with error: %d", result); goto end; diff --git a/extcap/sshdump.c b/extcap/sshdump.c index 768645e735..a635834800 100644 --- a/extcap/sshdump.c +++ b/extcap/sshdump.c @@ -522,7 +522,7 @@ int main(int argc, char *argv[]) } #ifdef _WIN32 - result = WSAStartup(MAKEWORD(1,1), &wsaData); + result = WSAStartup(MAKEWORD(2, 2), &wsaData); if (result != 0) { g_warning("ERROR: WSAStartup failed with error: %d", result); goto end; diff --git a/extcap/udpdump.c b/extcap/udpdump.c index 4539918fdd..fb1cca1734 100644 --- a/extcap/udpdump.c +++ b/extcap/udpdump.c @@ -475,7 +475,7 @@ int main(int argc, char *argv[]) payload = g_strdup("data"); #ifdef _WIN32 - result = WSAStartup(MAKEWORD(1,1), &wsaData); + result = WSAStartup(MAKEWORD(2, 2), &wsaData); if (result != 0) { g_warning("Error: WSAStartup failed with error: %d", result); goto end; diff --git a/rawshark.c b/rawshark.c index 123a4aa62b..d82dbc5f7a 100644 --- a/rawshark.c +++ b/rawshark.c @@ -727,7 +727,7 @@ main(int argc, char *argv[]) #ifdef _WIN32 /* Start windows sockets */ - result = WSAStartup( MAKEWORD( 1, 1 ), &wsaData ); + result = WSAStartup( MAKEWORD( 2, 2 ), &wsaData ); if (result != 0) { ret = INIT_ERROR; diff --git a/sharkd_daemon.c b/sharkd_daemon.c index 89af1ebcb5..63898636c3 100644 --- a/sharkd_daemon.c +++ b/sharkd_daemon.c @@ -61,7 +61,7 @@ socket_init(char *path) WSADATA wsaData; int result; - result = WSAStartup(MAKEWORD(1, 1), &wsaData); + result = WSAStartup(MAKEWORD(2, 2), &wsaData); if (result != 0) { g_warning("ERROR: WSAStartup failed with error: %d", result); return INVALID_SOCKET; diff --git a/tshark.c b/tshark.c index 723683656b..a7834a8d7f 100644 --- a/tshark.c +++ b/tshark.c @@ -1786,7 +1786,7 @@ main(int argc, char *argv[]) #ifdef _WIN32 /* Start windows sockets */ - result = WSAStartup( MAKEWORD( 1, 1 ), &wsaData ); + result = WSAStartup( MAKEWORD( 2, 2 ), &wsaData ); if (result != 0) { exit_status = INIT_FAILED; diff --git a/ui/qt/main.cpp b/ui/qt/main.cpp index a37ac727a7..71d4b8eabd 100644 --- a/ui/qt/main.cpp +++ b/ui/qt/main.cpp @@ -571,7 +571,7 @@ int main(int argc, char *qt_argv[]) #ifdef _WIN32 /* Start windows sockets */ - result = WSAStartup( MAKEWORD( 1, 1 ), &wsaData ); + result = WSAStartup( MAKEWORD( 2, 2 ), &wsaData ); if (result != 0) { ret_val = INIT_FAILED; diff --git a/wsutil/CMakeLists.txt b/wsutil/CMakeLists.txt index 030dc9e3ce..2eb9e70d70 100644 --- a/wsutil/CMakeLists.txt +++ b/wsutil/CMakeLists.txt @@ -268,7 +268,7 @@ target_link_libraries(wsutil ${GLIB2_LIBRARIES} ${PCAP_LIBRARIES} ${GCRYPT_LIBRARIES} - ${WIN_WSOCK32_LIBRARY} + ${WIN_WS2_32_LIBRARY} ${GNUTLS_LIBRARIES} ) -- cgit v1.2.3