aboutsummaryrefslogtreecommitdiffstats
path: root/extcap
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2019-05-01 18:46:23 -0700
committerGuy Harris <guy@alum.mit.edu>2019-05-02 09:29:01 +0000
commit2ee483a222bc765f8a738dfa15124826d89dc543 (patch)
treeb1011d49978414331d191c2190318cb1d92d634e /extcap
parent7bc066aa0c74f8c595ba01678832f2ac17e279dc (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 'extcap')
-rw-r--r--extcap/CMakeLists.txt2
-rw-r--r--extcap/androiddump.c25
-rw-r--r--extcap/ciscodump.c25
-rw-r--r--extcap/randpktdump.c26
-rw-r--r--extcap/sshdump.c25
-rw-r--r--extcap/udpdump.c33
6 files changed, 59 insertions, 77 deletions
diff --git a/extcap/CMakeLists.txt b/extcap/CMakeLists.txt
index 9ed9be36e4..398d712efe 100644
--- a/extcap/CMakeLists.txt
+++ b/extcap/CMakeLists.txt
@@ -200,6 +200,7 @@ endif()
if(BUILD_udpdump)
set(udpdump_LIBS
+ wsutil
${GLIB2_LIBRARIES}
${CMAKE_DL_LIBS}
${WIN_WS2_32_LIBRARY}
@@ -224,6 +225,7 @@ if(BUILD_randpktdump)
set(randpktdump_LIBS
randpkt_core
wiretap
+ wsutil
${GLIB2_LIBRARIES}
${ZLIB_LIBRARIES}
${CMAKE_DL_LIBS}
diff --git a/extcap/androiddump.c b/extcap/androiddump.c
index 6ede174d52..8ca775d496 100644
--- a/extcap/androiddump.c
+++ b/extcap/androiddump.c
@@ -21,6 +21,7 @@
#include <wsutil/strtoi.h>
#include <wsutil/filesystem.h>
#include <wsutil/privileges.h>
+#include <wsutil/please_report_bug.h>
#include <ui/cmdarg_err.h>
#include <wsutil/inet_addr.h>
@@ -2482,7 +2483,7 @@ static int capture_android_tcpdump(char *interface, char *fifo,
}
int main(int argc, char *argv[]) {
- char *init_progfile_dir_error;
+ char *err_msg;
int ret = EXIT_CODE_GENERIC;
int option_idx = 0;
int result;
@@ -2507,10 +2508,6 @@ int main(int argc, char *argv[]) {
char *help_url;
char *help_header = NULL;
-#ifdef _WIN32
- WSADATA wsaData;
-#endif /* _WIN32 */
-
cmdarg_err_init(failure_warning_message, failure_warning_message);
/*
@@ -2522,11 +2519,11 @@ int 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) {
g_warning("Can't get pathname of directory containing the captype program: %s.",
- init_progfile_dir_error);
- g_free(init_progfile_dir_error);
+ err_msg);
+ g_free(err_msg);
}
extcap_conf = g_new0(extcap_parameters, 1);
@@ -2689,13 +2686,13 @@ int main(int argc, char *argv[]) {
if (!bt_local_tcp_port)
bt_local_tcp_port = &default_bt_local_tcp_port;
-#ifdef _WIN32
- result = WSAStartup(MAKEWORD(2, 2), &wsaData);
- if (result != 0) {
- g_warning("WSAStartup failed with %d", result);
+ 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());
goto end;
}
-#endif /* _WIN32 */
extcap_cmdline_debug(argv, argc);
diff --git a/extcap/ciscodump.c b/extcap/ciscodump.c
index b125353251..778d83a2b6 100644
--- a/extcap/ciscodump.c
+++ b/extcap/ciscodump.c
@@ -17,6 +17,7 @@
#include <wsutil/strtoi.h>
#include <wsutil/filesystem.h>
#include <wsutil/privileges.h>
+#include <wsutil/please_report_bug.h>
#include <extcap/ssh-base.h>
#include <writecap/pcapio.h>
@@ -518,7 +519,7 @@ static int list_config(char *interface, unsigned int remote_port)
int main(int argc, char *argv[])
{
- char* init_progfile_dir_error;
+ char* err_msg;
int result;
int option_idx = 0;
ssh_params_t* ssh_params = ssh_params_new();
@@ -530,10 +531,6 @@ int main(int argc, char *argv[])
char* help_url;
char* help_header = NULL;
-#ifdef _WIN32
- WSADATA wsaData;
-#endif /* _WIN32 */
-
/*
* Get credential information for later use.
*/
@@ -543,11 +540,11 @@ int 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) {
g_warning("Can't get pathname of directory containing the captype program: %s.",
- init_progfile_dir_error);
- g_free(init_progfile_dir_error);
+ err_msg);
+ g_free(err_msg);
}
help_url = data_file_url("ciscodump.html");
@@ -688,13 +685,13 @@ int main(int argc, char *argv[])
goto end;
}
-#ifdef _WIN32
- result = WSAStartup(MAKEWORD(2, 2), &wsaData);
- if (result != 0) {
- g_warning("ERROR: WSAStartup failed with error: %d", result);
+ 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());
goto end;
}
-#endif /* _WIN32 */
if (extcap_conf->capture) {
if (!ssh_params->host) {
diff --git a/extcap/randpktdump.c b/extcap/randpktdump.c
index b4eec55da6..b035392e6d 100644
--- a/extcap/randpktdump.c
+++ b/extcap/randpktdump.c
@@ -18,6 +18,8 @@
#include <wsutil/strtoi.h>
#include <wsutil/filesystem.h>
#include <wsutil/privileges.h>
+#include <wsutil/socket.h>
+#include <wsutil/please_report_bug.h>
#include <cli_main.h>
@@ -124,7 +126,7 @@ static int list_config(char *interface)
int main(int argc, char *argv[])
{
- char* init_progfile_dir_error;
+ char* err_msg;
int option_idx = 0;
int result;
guint16 maxbytes = 5000;
@@ -138,10 +140,6 @@ int main(int argc, char *argv[])
wtap_dumper* savedump;
int ret = EXIT_FAILURE;
-#ifdef _WIN32
- WSADATA wsaData;
-#endif /* _WIN32 */
-
extcap_parameters * extcap_conf = g_new0(extcap_parameters, 1);
char* help_url;
char* help_header = NULL;
@@ -155,11 +153,11 @@ int 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) {
g_warning("Can't get pathname of directory containing the captype program: %s.",
- init_progfile_dir_error);
- g_free(init_progfile_dir_error);
+ err_msg);
+ g_free(err_msg);
}
help_url = data_file_url("randpktdump.html");
@@ -278,13 +276,13 @@ int main(int argc, char *argv[])
type = NULL;
}
-#ifdef _WIN32
- result = WSAStartup(MAKEWORD(2, 2), &wsaData);
- if (result != 0) {
- g_warning("ERROR: WSAStartup failed with error: %d", result);
+ 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());
goto end;
}
-#endif /* _WIN32 */
if (extcap_conf->capture) {
diff --git a/extcap/sshdump.c b/extcap/sshdump.c
index a635834800..7f91ff231a 100644
--- a/extcap/sshdump.c
+++ b/extcap/sshdump.c
@@ -19,6 +19,7 @@
#include <wsutil/strtoi.h>
#include <wsutil/filesystem.h>
#include <wsutil/privileges.h>
+#include <wsutil/please_report_bug.h>
#include <errno.h>
#include <string.h>
@@ -337,7 +338,7 @@ static char* concat_filters(const char* extcap_filter, const char* remote_filter
int main(int argc, char *argv[])
{
- char* init_progfile_dir_error;
+ char* err_msg;
int result;
int option_idx = 0;
ssh_params_t* ssh_params = ssh_params_new();
@@ -352,10 +353,6 @@ int main(int argc, char *argv[])
gboolean use_sudo = FALSE;
gboolean noprom = FALSE;
-#ifdef _WIN32
- WSADATA wsaData;
-#endif /* _WIN32 */
-
/*
* Get credential information for later use.
*/
@@ -365,11 +362,11 @@ int 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) {
g_warning("Can't get pathname of directory containing the captype program: %s.",
- init_progfile_dir_error);
- g_free(init_progfile_dir_error);
+ err_msg);
+ g_free(err_msg);
}
help_url = data_file_url("sshdump.html");
@@ -521,13 +518,13 @@ int main(int argc, char *argv[])
goto end;
}
-#ifdef _WIN32
- result = WSAStartup(MAKEWORD(2, 2), &wsaData);
- if (result != 0) {
- g_warning("ERROR: WSAStartup failed with error: %d", result);
+ 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());
goto end;
}
-#endif /* _WIN32 */
if (extcap_conf->capture) {
char* filter;
diff --git a/extcap/udpdump.c b/extcap/udpdump.c
index fb1cca1734..a57a371f34 100644
--- a/extcap/udpdump.c
+++ b/extcap/udpdump.c
@@ -23,10 +23,6 @@
#include <sys/time.h>
#endif
-#ifdef HAVE_SYS_SOCKET_H
- #include <sys/socket.h>
-#endif
-
#ifdef HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
@@ -38,16 +34,14 @@
#include <unistd.h>
#endif
-#ifdef HAVE_ARPA_INET_H
- #include <arpa/inet.h>
-#endif
-
#include <writecap/pcapio.h>
#include <wiretap/wtap.h>
#include <wsutil/strtoi.h>
#include <wsutil/inet_addr.h>
#include <wsutil/filesystem.h>
#include <wsutil/privileges.h>
+#include <wsutil/socket.h>
+#include <wsutil/please_report_bug.h>
#include <cli_main.h>
@@ -359,7 +353,7 @@ static void run_listener(const char* fifo, const guint16 port, const char* proto
int main(int argc, char *argv[])
{
- char* init_progfile_dir_error;
+ char* err_msg;
int option_idx = 0;
int result;
guint16 port = 0;
@@ -369,9 +363,6 @@ int main(int argc, char *argv[])
char* help_header = NULL;
char* payload = NULL;
char* port_msg = NULL;
-#ifdef _WIN32
- WSADATA wsaData;
-#endif /* _WIN32 */
/*
* Get credential information for later use.
@@ -382,11 +373,11 @@ int 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) {
g_warning("Can't get pathname of directory containing the captype program: %s.",
- init_progfile_dir_error);
- g_free(init_progfile_dir_error);
+ err_msg);
+ g_free(err_msg);
}
help_url = data_file_url("udpdump.html");
@@ -474,13 +465,13 @@ int main(int argc, char *argv[])
if (!payload)
payload = g_strdup("data");
-#ifdef _WIN32
- result = WSAStartup(MAKEWORD(2, 2), &wsaData);
- if (result != 0) {
- g_warning("Error: WSAStartup failed with error: %d", result);
+ 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());
goto end;
}
-#endif /* _WIN32 */
if (port == 0)
port = UDPDUMP_DEFAULT_PORT;