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 /sharkd_daemon.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 'sharkd_daemon.c')
-rw-r--r-- | sharkd_daemon.c | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/sharkd_daemon.c b/sharkd_daemon.c index 63898636c3..f2397821bf 100644 --- a/sharkd_daemon.c +++ b/sharkd_daemon.c @@ -30,6 +30,7 @@ #include <wsutil/socket.h> #include <wsutil/inet_addr.h> +#include <wsutil/please_report_bug.h> #ifndef _WIN32 #include <sys/un.h> @@ -56,17 +57,15 @@ static socket_handle_t socket_init(char *path) { socket_handle_t fd = INVALID_SOCKET; - -#ifdef _WIN32 - WSADATA wsaData; - int result; - - result = WSAStartup(MAKEWORD(2, 2), &wsaData); - if (result != 0) { - g_warning("ERROR: WSAStartup failed with error: %d", result); - return INVALID_SOCKET; + char *err_msg; + + err_msg = ws_init_sockets(); + if (err_msg != NULL) { + g_warning("ERROR: %s", err_msg); + g_free(err_msg); + g_warning("%s", please_report_bug()); + return fd; } -#endif #ifdef SHARKD_UNIX_SUPPORT if (!strncmp(path, "unix:", 5)) |