aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDario Lombardo <lomato@gmail.com>2016-02-22 16:28:15 +0100
committerRoland Knall <rknall@gmail.com>2016-02-26 10:02:59 +0000
commit298012359b52a9bf1ca22e0d1bedf23ec3e7680f (patch)
treea45d34417930edf1b3a9299bac31efdf7f71ef2b
parent3b9306e91b397755785b6b85be10594b2bfaf740 (diff)
extcap: move windows functions into extcap-base
Change-Id: Iec7fed027a24992afd673b09c32470af51739ae5 Reviewed-on: https://code.wireshark.org/review/14075 Reviewed-by: Roland Knall <rknall@gmail.com>
-rw-r--r--CMakeLists.txt4
-rw-r--r--extcap/Makefile.common11
-rw-r--r--extcap/androiddump.c46
-rw-r--r--extcap/extcap-base.c85
-rw-r--r--extcap/extcap-base.h7
-rw-r--r--extcap/randpktdump.c43
-rw-r--r--extcap/sshdump.c44
7 files changed, 103 insertions, 137 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index d39c3086ec..dca9ee746f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -209,6 +209,7 @@ include_directories(
${CMAKE_SOURCE_DIR}
${CMAKE_SOURCE_DIR}/epan
${CMAKE_SOURCE_DIR}/tools/lemon
+ ${CMAKE_SOURCE_DIR}/extcap
)
include( CMakeOptions.txt )
@@ -2367,6 +2368,7 @@ if(BUILD_androiddump)
endif()
set(androiddump_FILES
extcap/androiddump.c
+ extcap/extcap-base.c
)
add_executable(androiddump WIN32 ${androiddump_FILES})
@@ -2387,6 +2389,7 @@ if(BUILD_sshdump AND LIBSSH_FOUND)
endif()
set(sshdump_FILES
extcap/sshdump.c
+ extcap/extcap-base.c
)
add_executable(sshdump WIN32 ${sshdump_FILES})
@@ -2407,6 +2410,7 @@ if(BUILD_randpktdump)
)
set(randpktdump_FILES
extcap/randpktdump.c
+ extcap/extcap-base.c
)
add_executable(randpktdump WIN32 ${randpktdump_FILES})
diff --git a/extcap/Makefile.common b/extcap/Makefile.common
index a2f26a69b1..1f2ac07537 100644
--- a/extcap/Makefile.common
+++ b/extcap/Makefile.common
@@ -23,15 +23,18 @@
# androiddump specifics
androiddump_SOURCES = \
- androiddump.c
+ androiddump.c \
+ extcap-base.c
# randpktdump specifics
randpktdump_SOURCES = \
- randpktdump.c
+ randpktdump.c \
+ extcap-base.c
# sshdump specifics
sshdump_SOURCES = \
- sshdump.c
+ sshdump.c \
+ extcap-base.c
noinst_HEADERS = \
- extcap-base.h
+ extcap-base.c
diff --git a/extcap/androiddump.c b/extcap/androiddump.c
index e5b68fbfb7..a862c9ec76 100644
--- a/extcap/androiddump.c
+++ b/extcap/androiddump.c
@@ -104,7 +104,6 @@
#define PACKET_LENGTH 65535
#define verbose_print(...) { if (verbose) printf(__VA_ARGS__); }
-#define errmsg_print(...) { fprintf(stderr, __VA_ARGS__); fprintf(stderr, "\n"); }
enum {
EXTCAP_BASE_OPTIONS_ENUM,
@@ -1990,52 +1989,7 @@ static int capture_android_logcat(char *interface, char *fifo,
/*============================================================================*/
-#ifdef _WIN32
-BOOLEAN IsHandleRedirected(DWORD handle)
-{
- HANDLE h = GetStdHandle(handle);
- if (h) {
- BY_HANDLE_FILE_INFORMATION fi;
- if (GetFileInformationByHandle(h, &fi)) {
- return TRUE;
- }
- }
- return FALSE;
-}
-
-static void attach_parent_console()
-{
- BOOL outRedirected, errRedirected;
-
- outRedirected = IsHandleRedirected(STD_OUTPUT_HANDLE);
- errRedirected = IsHandleRedirected(STD_ERROR_HANDLE);
-
- if (outRedirected && errRedirected) {
- /* Both standard output and error handles are redirected.
- * There is no point in attaching to parent process console.
- */
- return;
- }
-
- if (AttachConsole(ATTACH_PARENT_PROCESS) == 0) {
- /* Console attach failed. */
- return;
- }
-
- /* Console attach succeeded */
- if (outRedirected == FALSE) {
- if (!freopen("CONOUT$", "w", stdout)) {
- errmsg_print("WARNING: Cannot redirect to stdout.");
- }
- }
- if (errRedirected == FALSE) {
- if (!freopen("CONOUT$", "w", stderr)) {
- errmsg_print("WARNING: Cannot redirect to strerr.");
- }
- }
-}
-#endif
/*----------------------------------------------------------------------------*/
/* Android Wifi Tcpdump */
diff --git a/extcap/extcap-base.c b/extcap/extcap-base.c
new file mode 100644
index 0000000000..51d2061469
--- /dev/null
+++ b/extcap/extcap-base.c
@@ -0,0 +1,85 @@
+/* extcap_base.c
+ * Base function for extcaps
+ *
+ * Copyright 2015, Dario Lombardo
+ *
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
+ * Copyright 1998 Gerald Combs
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "extcap-base.h"
+
+#ifdef _WIN32
+BOOLEAN IsHandleRedirected(DWORD handle)
+{
+ HANDLE h = GetStdHandle(handle);
+ if (h) {
+ BY_HANDLE_FILE_INFORMATION fi;
+ if (GetFileInformationByHandle(h, &fi)) {
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+void attach_parent_console()
+{
+ BOOL outRedirected, errRedirected;
+
+ outRedirected = IsHandleRedirected(STD_OUTPUT_HANDLE);
+ errRedirected = IsHandleRedirected(STD_ERROR_HANDLE);
+
+ if (outRedirected && errRedirected) {
+ /* Both standard output and error handles are redirected.
+ * There is no point in attaching to parent process console.
+ */
+ return;
+ }
+
+ if (AttachConsole(ATTACH_PARENT_PROCESS) == 0) {
+ /* Console attach failed. */
+ return;
+ }
+
+ /* Console attach succeeded */
+ if (outRedirected == FALSE) {
+ if (!freopen("CONOUT$", "w", stdout)) {
+ errmsg_print("WARNING: Cannot redirect to stdout.");
+ }
+ }
+
+ if (errRedirected == FALSE) {
+ if (!freopen("CONOUT$", "w", stderr)) {
+ errmsg_print("WARNING: Cannot redirect to strerr.");
+ }
+ }
+}
+#endif
+
+/*
+ * Editor modelines - https://www.wireshark.org/tools/modelines.html
+ *
+ * Local variables:
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: t
+ * End:
+ *
+ * vi: set shiftwidth=4 tabstop=4 noexpandtab:
+ * :indentSize=4:tabSize=4:noTabs=false:
+ */
diff --git a/extcap/extcap-base.h b/extcap/extcap-base.h
index 83500e449e..07617b15df 100644
--- a/extcap/extcap-base.h
+++ b/extcap/extcap-base.h
@@ -83,6 +83,13 @@
{ "extcap-capture-filter", required_argument, NULL, OPT_CAPTURE_FILTER}, \
{ "fifo", required_argument, NULL, OPT_FIFO} \
+#ifdef _WIN32
+BOOLEAN IsHandleRedirected(DWORD handle);
+void attach_parent_console();
+#endif
+
+#define errmsg_print(...) { fprintf(stderr, __VA_ARGS__); fprintf(stderr, "\n"); }
+
#endif
/*
diff --git a/extcap/randpktdump.c b/extcap/randpktdump.c
index c808fbaf74..7651b6635c 100644
--- a/extcap/randpktdump.c
+++ b/extcap/randpktdump.c
@@ -34,7 +34,6 @@
#define RANDPKTDUMP_VERSION_RELEASE 0
#define verbose_print(...) { if (verbose) printf(__VA_ARGS__); }
-#define errmsg_print(...) { fprintf(stderr, __VA_ARGS__); fprintf(stderr, "\n"); }
static gboolean verbose = TRUE;
@@ -63,48 +62,6 @@ static struct option longopts[] = {
{ 0, 0, 0, 0 }
};
-#ifdef _WIN32
-BOOLEAN IsHandleRedirected(DWORD handle)
-{
- HANDLE h = GetStdHandle(handle);
- if (h) {
- BY_HANDLE_FILE_INFORMATION fi;
- if (GetFileInformationByHandle(h, &fi)) {
- return TRUE;
- }
- }
- return FALSE;
-}
-
-static void attach_parent_console()
-{
- BOOL outRedirected, errRedirected;
-
- outRedirected = IsHandleRedirected(STD_OUTPUT_HANDLE);
- errRedirected = IsHandleRedirected(STD_ERROR_HANDLE);
-
- if (outRedirected && errRedirected) {
- /* Both standard output and error handles are redirected.
- * There is no point in attaching to parent process console.
- */
- return;
- }
-
- if (AttachConsole(ATTACH_PARENT_PROCESS) == 0) {
- /* Console attach failed. */
- return;
- }
-
- /* Console attach succeeded */
- if (outRedirected == FALSE) {
- freopen("CONOUT$", "w", stdout);
- }
-
- if (errRedirected == FALSE) {
- freopen("CONOUT$", "w", stderr);
- }
-}
-#endif
static void help(const char* binname)
{
diff --git a/extcap/sshdump.c b/extcap/sshdump.c
index c57de0bdd2..da7df908dd 100644
--- a/extcap/sshdump.c
+++ b/extcap/sshdump.c
@@ -68,7 +68,6 @@
#define DEFAULT_CAPTURE_BIN "dumpcap"
#define verbose_print(...) { if (verbose) printf(__VA_ARGS__); }
-#define errmsg_print(...) { fprintf(stderr, __VA_ARGS__); fprintf(stderr, "\n"); }
static gboolean verbose = FALSE;
@@ -544,49 +543,6 @@ static char* concat_filters(const char* extcap_filter, const char* remote_filter
return g_strdup_printf("(%s) and (%s)", extcap_filter, remote_filter);
}
-#ifdef _WIN32
-BOOLEAN IsHandleRedirected(DWORD handle)
-{
- HANDLE h = GetStdHandle(handle);
- if (h) {
- BY_HANDLE_FILE_INFORMATION fi;
- if (GetFileInformationByHandle(h, &fi)) {
- return TRUE;
- }
- }
- return FALSE;
-}
-
-static void attach_parent_console()
-{
- BOOL outRedirected, errRedirected;
-
- outRedirected = IsHandleRedirected(STD_OUTPUT_HANDLE);
- errRedirected = IsHandleRedirected(STD_ERROR_HANDLE);
-
- if (outRedirected && errRedirected) {
- /* Both standard output and error handles are redirected.
- * There is no point in attaching to parent process console.
- */
- return;
- }
-
- if (AttachConsole(ATTACH_PARENT_PROCESS) == 0) {
- /* Console attach failed. */
- return;
- }
-
- /* Console attach succeeded */
- if (outRedirected == FALSE) {
- freopen("CONOUT$", "w", stdout);
- }
-
- if (errRedirected == FALSE) {
- freopen("CONOUT$", "w", stderr);
- }
-}
-#endif
-
int main(int argc, char **argv)
{
int result;