aboutsummaryrefslogtreecommitdiffstats
path: root/extcap
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2018-12-12 02:53:08 -0800
committerGuy Harris <guy@alum.mit.edu>2018-12-13 00:52:11 +0000
commita34cc98b2ac5a0ad011a1c3a40ce5e59230a9498 (patch)
tree6cff6069cc4b3925fa4af82ce968959444dadd75 /extcap
parent17b721e45180a9decebb70dab77f41d96d5f7a03 (diff)
Put the main() and wmain() routines for CLI programs into a separate file.
That means that code is only in one place, rather than having copies of it in each of those programs. CLI programs that, on Windows, should get UTF-8 arguments rather than arguments in the local code page should: include the top-level cli_main.h header; define the main function as real_main(); be built with the top-level cli_main.c file. On UN*X, cli_main.c has a main() program, and just passes the arguments on to real_main(). On Windows, cli_main.c has a wmain() function that converts the UTF-16 arguments it's handed to UTF-8 arguments, using WideCharToMultiByte() so that it doesn't use any functions other than those provided by the system, and then calls real_main() with the argument count and UTF-8 arguments. Change-Id: I8b11f01dbc5c63fce599d1bef9ad96cd92c3c01e Reviewed-on: https://code.wireshark.org/review/31017 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.txt5
-rw-r--r--extcap/androiddump.c19
-rw-r--r--extcap/ciscodump.c19
-rw-r--r--extcap/extcap-base.h1
-rw-r--r--extcap/randpktdump.c19
-rw-r--r--extcap/sshdump.c19
-rw-r--r--extcap/udpdump.c19
7 files changed, 15 insertions, 86 deletions
diff --git a/extcap/CMakeLists.txt b/extcap/CMakeLists.txt
index 8475a39598..93581b550b 100644
--- a/extcap/CMakeLists.txt
+++ b/extcap/CMakeLists.txt
@@ -96,6 +96,7 @@ if(BUILD_androiddump)
)
endif()
set(androiddump_FILES
+ ../cli_main.c
androiddump.c
extcap-base.c
)
@@ -117,6 +118,7 @@ if(BUILD_sshdump AND LIBSSH_FOUND)
${LIBSSH_LIBRARIES}
)
set(sshdump_FILES
+ ../cli_main.c
sshdump.c
extcap-base.c
ssh-base.c
@@ -142,6 +144,7 @@ if(BUILD_ciscodump AND LIBSSH_FOUND)
${LIBSSH_LIBRARIES}
)
set(ciscodump_FILES
+ ../cli_main.c
ciscodump.c
extcap-base.c
ssh-base.c
@@ -190,6 +193,7 @@ if(BUILD_udpdump)
writecap
)
set(udpdump_FILES
+ ../cli_main.c
udpdump.c
extcap-base.c
)
@@ -212,6 +216,7 @@ if(BUILD_randpktdump)
${CMAKE_DL_LIBS}
)
set(randpktdump_FILES
+ ../cli_main.c
extcap-base.c
randpktdump.c
)
diff --git a/extcap/androiddump.c b/extcap/androiddump.c
index 979a3704c1..5b2d1dfcfa 100644
--- a/extcap/androiddump.c
+++ b/extcap/androiddump.c
@@ -76,6 +76,8 @@
#include "wiretap/pcap-encap.h"
#endif
+#include <cli_main.h>
+
#ifdef ANDROIDDUMP_USE_LIBPCAP
#define EXTCAP_ENCAP_BLUETOOTH_H4_WITH_PHDR DLT_BLUETOOTH_H4_WITH_PHDR
#define EXTCAP_ENCAP_WIRESHARK_UPPER_PDU DLT_WIRESHARK_UPPER_PDU
@@ -2743,23 +2745,6 @@ end:
return ret;
}
-#ifdef _WIN32
-int
-wmain(int argc, wchar_t *wc_argv[])
-{
- char **argv;
-
- argv = arg_list_utf_16to8(argc, wc_argv);
- return real_main(argc, argv);
-}
-#else
-int
-main(int argc, char *argv[])
-{
- return real_main(argc, argv);
-}
-#endif
-
/*
* Editor modelines - http://www.wireshark.org/tools/modelines.html
*
diff --git a/extcap/ciscodump.c b/extcap/ciscodump.c
index 49c3ecbbf2..798cb7ac50 100644
--- a/extcap/ciscodump.c
+++ b/extcap/ciscodump.c
@@ -23,6 +23,8 @@
#include <string.h>
#include <fcntl.h>
+#include <cli_main.h>
+
#define CISCODUMP_VERSION_MAJOR "1"
#define CISCODUMP_VERSION_MINOR "0"
#define CISCODUMP_VERSION_RELEASE "0"
@@ -706,23 +708,6 @@ end:
return ret;
}
-#ifdef _WIN32
-int
-wmain(int argc, wchar_t *wc_argv[])
-{
- char **argv;
-
- argv = arg_list_utf_16to8(argc, wc_argv);
- return real_main(argc, argv);
-}
-#else
-int
-main(int argc, char *argv[])
-{
- return real_main(argc, argv);
-}
-#endif
-
/*
* Editor modelines - https://www.wireshark.org/tools/modelines.html
*
diff --git a/extcap/extcap-base.h b/extcap/extcap-base.h
index 021c2f5015..f5112ab622 100644
--- a/extcap/extcap-base.h
+++ b/extcap/extcap-base.h
@@ -29,7 +29,6 @@
#ifdef _WIN32
#include <io.h>
- #include <wsutil/unicode-utils.h> // arg_list_utf_16to8
#endif
#include <wsutil/socket.h>
diff --git a/extcap/randpktdump.c b/extcap/randpktdump.c
index f7639dcb57..647d291ff9 100644
--- a/extcap/randpktdump.c
+++ b/extcap/randpktdump.c
@@ -18,6 +18,8 @@
#include <wsutil/strtoi.h>
#include <wsutil/filesystem.h>
+#include <cli_main.h>
+
#define RANDPKT_EXTCAP_INTERFACE "randpkt"
#define RANDPKTDUMP_VERSION_MAJOR "0"
#define RANDPKTDUMP_VERSION_MINOR "1"
@@ -318,23 +320,6 @@ end:
return ret;
}
-#ifdef _WIN32
-int
-wmain(int argc, wchar_t *wc_argv[])
-{
- char **argv;
-
- argv = arg_list_utf_16to8(argc, wc_argv);
- return real_main(argc, argv);
-}
-#else
-int
-main(int argc, char *argv[])
-{
- return real_main(argc, argv);
-}
-#endif
-
/*
* Editor modelines - https://www.wireshark.org/tools/modelines.html
*
diff --git a/extcap/sshdump.c b/extcap/sshdump.c
index 4796b857aa..67ee1ee605 100644
--- a/extcap/sshdump.c
+++ b/extcap/sshdump.c
@@ -23,6 +23,8 @@
#include <string.h>
#include <fcntl.h>
+#include <cli_main.h>
+
#define SSHDUMP_VERSION_MAJOR "1"
#define SSHDUMP_VERSION_MINOR "0"
#define SSHDUMP_VERSION_RELEASE "0"
@@ -531,23 +533,6 @@ end:
return ret;
}
-#ifdef _WIN32
-int
-wmain(int argc, wchar_t *wc_argv[])
-{
- char **argv;
-
- argv = arg_list_utf_16to8(argc, wc_argv);
- return real_main(argc, argv);
-}
-#else
-int
-main(int argc, char *argv[])
-{
- return real_main(argc, argv);
-}
-#endif
-
/*
* Editor modelines - https://www.wireshark.org/tools/modelines.html
*
diff --git a/extcap/udpdump.c b/extcap/udpdump.c
index ac74f2421b..444f637200 100644
--- a/extcap/udpdump.c
+++ b/extcap/udpdump.c
@@ -48,6 +48,8 @@
#include <wsutil/inet_addr.h>
#include <wsutil/filesystem.h>
+#include <cli_main.h>
+
#define PCAP_SNAPLEN 0xffff
#define UDPDUMP_DEFAULT_PORT 5555
@@ -475,23 +477,6 @@ end:
return ret;
}
-#ifdef _WIN32
-int
-wmain(int argc, wchar_t *wc_argv[])
-{
- char **argv;
-
- argv = arg_list_utf_16to8(argc, wc_argv);
- return real_main(argc, argv);
-}
-#else
-int
-main(int argc, char *argv[])
-{
- return real_main(argc, argv);
-}
-#endif
-
/*
* Editor modelines - http://www.wireshark.org/tools/modelines.html
*