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 /rawshark.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 'rawshark.c')
-rw-r--r-- | rawshark.c | 29 |
1 files changed, 13 insertions, 16 deletions
diff --git a/rawshark.c b/rawshark.c index d82dbc5f7a..f8586a1579 100644 --- a/rawshark.c +++ b/rawshark.c @@ -49,9 +49,11 @@ #include <ui/cmdarg_err.h> #include <wsutil/filesystem.h> #include <wsutil/file_util.h> +#include <wsutil/socket.h> #include <wsutil/plugins.h> #include <wsutil/privileges.h> #include <wsutil/report_message.h> +#include <wsutil/please_report_bug.h> #include <ui/clopts_common.h> #include "globals.h" @@ -405,15 +407,12 @@ set_link_type(const char *lt_arg) { int main(int argc, char *argv[]) { - char *init_progfile_dir_error; + char *err_msg; int opt, i; -#ifdef _WIN32 - int result; - WSADATA wsaData; -#else +#ifndef _WIN32 struct rlimit limit; -#endif /* _WIN32 */ +#endif /* !_WIN32 */ gchar *pipe_name = NULL; gchar *rfilters[64]; @@ -470,10 +469,10 @@ main(int argc, char *argv[]) * Attempt to get the pathname of the directory containing the * executable file. */ - init_progfile_dir_error = init_progfile_dir(argv[0]); - if (init_progfile_dir_error != NULL) { + err_msg = init_progfile_dir(argv[0]); + if (err_msg != NULL) { fprintf(stderr, "rawshark: Can't get pathname of rawshark program: %s.\n", - init_progfile_dir_error); + err_msg); } /* nothing more than the standard GLib handler, but without a warning */ @@ -725,15 +724,15 @@ main(int argc, char *argv[]) goto clean_exit; } -#ifdef _WIN32 - /* Start windows sockets */ - result = WSAStartup( MAKEWORD( 2, 2 ), &wsaData ); - if (result != 0) + err_msg = ws_init_sockets(); + if (err_msg != NULL) { + cmdarg_err("%s", err_msg); + g_free(err_msg); + cmdarg_err_cont("%s", please_report_bug()); ret = INIT_ERROR; goto clean_exit; } -#endif /* _WIN32 */ /* * Enabled and disabled protocols and heuristic dissectors as per @@ -746,8 +745,6 @@ main(int argc, char *argv[]) if (n_rfilters != 0) { for (i = 0; i < n_rfilters; i++) { - gchar *err_msg; - if (!dfilter_compile(rfilters[i], &rfcodes[n_rfcodes], &err_msg)) { cmdarg_err("%s", err_msg); g_free(err_msg); |