diff options
author | Guy Harris <guy@alum.mit.edu> | 2019-05-01 18:46:23 -0700 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2019-05-02 09:29:01 +0000 |
commit | 2ee483a222bc765f8a738dfa15124826d89dc543 (patch) | |
tree | b1011d49978414331d191c2190318cb1d92d634e /dumpcap.c | |
parent | 7bc066aa0c74f8c595ba01678832f2ac17e279dc (diff) |
Move the Winsock initialization and cleanup to wsutil routines.
Those routines exist on both Windows and UN*X, but they don't do
anything on UN*X (they could if it were ever necessary).
That eliminates some #ifdefs, and also means that the gory details of
initializing Winsock, including the Winsock version being requested,
are buried in one routine.
The initialization routine returns NULL on success and a pointer to a
g_malloc()ated error message on failure; report the error to the user,
along with a "report this to the Wireshark developers" suggestion.
That means including wsutil/socket.h, which obviates the need to include
some headers for socket APIs, as it includes them for you.
Change-Id: I9327bbf25effbb441e4217edc5354a4d5ab07186
Reviewed-on: https://code.wireshark.org/review/33045
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'dumpcap.c')
-rw-r--r-- | dumpcap.c | 31 |
1 files changed, 13 insertions, 18 deletions
@@ -17,10 +17,6 @@ #include <sys/types.h> -#ifdef HAVE_SYS_SOCKET_H -#include <sys/socket.h> -#endif - #ifdef HAVE_NETINET_IN_H #include <netinet/in.h> #endif @@ -29,10 +25,6 @@ #include <getopt.h> #endif -#ifdef HAVE_ARPA_INET_H -#include <arpa/inet.h> -#endif - #if defined(__APPLE__) && defined(__LP64__) #include <sys/utsname.h> #endif @@ -45,6 +37,8 @@ #include <cli_main.h> #include <version_info.h> +#include <wsutil/socket.h> + #ifndef HAVE_GETOPT_LONG #include "wsutil/wsgetopt.h" #endif @@ -1131,10 +1125,9 @@ report_counts_siginfo(int signum _U_) static void exit_main(int status) { -#ifdef _WIN32 - /* Shutdown windows sockets */ - WSACleanup(); + ws_cleanup_sockets(); +#ifdef _WIN32 /* can be helpful for debugging */ #ifdef DEBUG_DUMPCAP printf("Press any key\n"); @@ -4631,6 +4624,7 @@ get_dumpcap_runtime_info(GString *str) int main(int argc, char *argv[]) { + char *err_msg; int opt; static const struct option long_options[] = { {"help", no_argument, NULL, 'h'}, @@ -4814,19 +4808,20 @@ main(int argc, char *argv[]) /* ... and also load the packet.dll from wpcap */ /* XXX - currently not required, may change later. */ /*wpcap_packet_load();*/ +#endif - DWORD result; - WSADATA wsaData; - - /* Start windows sockets */ - result = WSAStartup( MAKEWORD(2, 2), &wsaData ); - if (result != 0) + err_msg = ws_init_sockets(); + if (err_msg != NULL) { g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_ERROR, - "ERROR: WSAStartup failed with error %d: %s", result, win32strerror(result)); + "ERROR: %s", err_msg); + g_free(err_msg); + g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_ERROR, + "%s", please_report_bug()); exit_main(1); } +#ifdef _WIN32 /* Set handler for Ctrl+C key */ SetConsoleCtrlHandler(capture_cleanup_handler, TRUE); #else |