diff options
author | Dario Lombardo <lomato@gmail.com> | 2016-02-22 16:28:15 +0100 |
---|---|---|
committer | Roland Knall <rknall@gmail.com> | 2016-02-26 10:02:59 +0000 |
commit | 298012359b52a9bf1ca22e0d1bedf23ec3e7680f (patch) | |
tree | a45d34417930edf1b3a9299bac31efdf7f71ef2b /extcap/extcap-base.c | |
parent | 3b9306e91b397755785b6b85be10594b2bfaf740 (diff) | |
download | wireshark-298012359b52a9bf1ca22e0d1bedf23ec3e7680f.tar.gz wireshark-298012359b52a9bf1ca22e0d1bedf23ec3e7680f.tar.bz2 wireshark-298012359b52a9bf1ca22e0d1bedf23ec3e7680f.zip |
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>
Diffstat (limited to 'extcap/extcap-base.c')
-rw-r--r-- | extcap/extcap-base.c | 85 |
1 files changed, 85 insertions, 0 deletions
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: + */ |