Win32: Make extcap utilities console applications.
Switch from using WinMain in extcap to wmain. Change-Id: I54fafad598f5ff74fe84a3ce3e993ac5a31188f7 Reviewed-on: https://code.wireshark.org/review/30094 Reviewed-by: Gerald Combs <gerald@wireshark.org> Petri-Dish: Gerald Combs <gerald@wireshark.org> Tested-by: Petri Dish Buildbot Reviewed-by: Anders Broman <a.broman58@gmail.com>
This commit is contained in:
parent
0efb1c6f6b
commit
aba59e5973
|
@ -4,6 +4,6 @@
|
||||||
# http://editorconfig.org/
|
# http://editorconfig.org/
|
||||||
#
|
#
|
||||||
|
|
||||||
[{extcap-base,randpktdump,ssh-base,sshdump}.[ch]]
|
[{ciscodump,extcap-base,randpktdump,ssh-base,sshdump,udpdump}.[ch]]
|
||||||
indent_style = tab
|
indent_style = tab
|
||||||
indent_size = tab
|
indent_size = tab
|
||||||
|
|
|
@ -96,7 +96,7 @@ if(BUILD_androiddump)
|
||||||
)
|
)
|
||||||
|
|
||||||
set_executable_resources(androiddump "Androiddump")
|
set_executable_resources(androiddump "Androiddump")
|
||||||
add_executable(androiddump WIN32 ${androiddump_FILES})
|
add_executable(androiddump ${androiddump_FILES})
|
||||||
# XXX Shouldn't we add wsutil to androiddump_LIBS instead?
|
# XXX Shouldn't we add wsutil to androiddump_LIBS instead?
|
||||||
set_extcap_executable_properties(androiddump)
|
set_extcap_executable_properties(androiddump)
|
||||||
target_link_libraries(androiddump ${androiddump_LIBS})
|
target_link_libraries(androiddump ${androiddump_LIBS})
|
||||||
|
@ -118,7 +118,7 @@ if(BUILD_sshdump AND LIBSSH_FOUND)
|
||||||
)
|
)
|
||||||
|
|
||||||
set_executable_resources(sshdump "Sshdump")
|
set_executable_resources(sshdump "Sshdump")
|
||||||
add_executable(sshdump WIN32 ${sshdump_FILES})
|
add_executable(sshdump ${sshdump_FILES})
|
||||||
set_extcap_executable_properties(sshdump)
|
set_extcap_executable_properties(sshdump)
|
||||||
target_link_libraries(sshdump ${sshdump_LIBS})
|
target_link_libraries(sshdump ${sshdump_LIBS})
|
||||||
target_include_directories(sshdump PUBLIC ${LIBSSH_INCLUDE_DIR})
|
target_include_directories(sshdump PUBLIC ${LIBSSH_INCLUDE_DIR})
|
||||||
|
@ -143,7 +143,7 @@ if(BUILD_ciscodump AND LIBSSH_FOUND)
|
||||||
)
|
)
|
||||||
|
|
||||||
set_executable_resources(ciscodump "Ciscodump")
|
set_executable_resources(ciscodump "Ciscodump")
|
||||||
add_executable(ciscodump WIN32 ${ciscodump_FILES})
|
add_executable(ciscodump ${ciscodump_FILES})
|
||||||
set_extcap_executable_properties(ciscodump)
|
set_extcap_executable_properties(ciscodump)
|
||||||
target_link_libraries(ciscodump ${ciscodump_LIBS})
|
target_link_libraries(ciscodump ${ciscodump_LIBS})
|
||||||
target_include_directories(ciscodump PUBLIC ${LIBSSH_INCLUDE_DIR})
|
target_include_directories(ciscodump PUBLIC ${LIBSSH_INCLUDE_DIR})
|
||||||
|
@ -167,7 +167,7 @@ if(BUILD_dpauxmon AND HAVE_LIBNL3)
|
||||||
)
|
)
|
||||||
|
|
||||||
set_executable_resources(dpauxmon "dpauxmon")
|
set_executable_resources(dpauxmon "dpauxmon")
|
||||||
add_executable(dpauxmon WIN32 ${dpauxmon_FILES})
|
add_executable(dpauxmon ${dpauxmon_FILES})
|
||||||
set_extcap_executable_properties(dpauxmon)
|
set_extcap_executable_properties(dpauxmon)
|
||||||
target_link_libraries(dpauxmon ${dpauxmon_LIBS})
|
target_link_libraries(dpauxmon ${dpauxmon_LIBS})
|
||||||
target_include_directories(dpauxmon PUBLIC ${NL_INCLUDE_DIR})
|
target_include_directories(dpauxmon PUBLIC ${NL_INCLUDE_DIR})
|
||||||
|
@ -190,7 +190,7 @@ if(BUILD_udpdump)
|
||||||
)
|
)
|
||||||
|
|
||||||
set_executable_resources(udpdump "udpdump")
|
set_executable_resources(udpdump "udpdump")
|
||||||
add_executable(udpdump WIN32 ${udpdump_FILES})
|
add_executable(udpdump ${udpdump_FILES})
|
||||||
set_extcap_executable_properties(udpdump)
|
set_extcap_executable_properties(udpdump)
|
||||||
target_link_libraries(udpdump ${udpdump_LIBS})
|
target_link_libraries(udpdump ${udpdump_LIBS})
|
||||||
install(TARGETS udpdump RUNTIME DESTINATION ${EXTCAP_INSTALL_LIBDIR})
|
install(TARGETS udpdump RUNTIME DESTINATION ${EXTCAP_INSTALL_LIBDIR})
|
||||||
|
@ -212,7 +212,7 @@ if(BUILD_randpktdump)
|
||||||
)
|
)
|
||||||
|
|
||||||
set_executable_resources(randpktdump "randpktdump")
|
set_executable_resources(randpktdump "randpktdump")
|
||||||
add_executable(randpktdump WIN32 ${randpktdump_FILES})
|
add_executable(randpktdump ${randpktdump_FILES})
|
||||||
# XXX Shouldn't we add wsutil to randpktdump_LIBS instead?
|
# XXX Shouldn't we add wsutil to randpktdump_LIBS instead?
|
||||||
set_extcap_executable_properties(randpktdump)
|
set_extcap_executable_properties(randpktdump)
|
||||||
target_link_libraries(randpktdump ${randpktdump_LIBS})
|
target_link_libraries(randpktdump ${randpktdump_LIBS})
|
||||||
|
@ -237,7 +237,7 @@ if(BUILD_sdjournal AND SYSTEMD_FOUND)
|
||||||
)
|
)
|
||||||
|
|
||||||
set_executable_resources(sdjournal "sdjournal")
|
set_executable_resources(sdjournal "sdjournal")
|
||||||
add_executable(sdjournal WIN32 ${sdjournal_FILES})
|
add_executable(sdjournal ${sdjournal_FILES})
|
||||||
set_extcap_executable_properties(sdjournal)
|
set_extcap_executable_properties(sdjournal)
|
||||||
target_link_libraries(sdjournal ${sdjournal_LIBS})
|
target_link_libraries(sdjournal ${sdjournal_LIBS})
|
||||||
install(TARGETS sdjournal RUNTIME DESTINATION ${EXTCAP_INSTALL_LIBDIR})
|
install(TARGETS sdjournal RUNTIME DESTINATION ${EXTCAP_INSTALL_LIBDIR})
|
||||||
|
|
|
@ -2485,7 +2485,7 @@ static int capture_android_tcpdump(char *interface, char *fifo,
|
||||||
return EXIT_CODE_SUCCESS;
|
return EXIT_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int real_main(int argc, char **argv) {
|
||||||
int ret = EXIT_CODE_GENERIC;
|
int ret = EXIT_CODE_GENERIC;
|
||||||
int option_idx = 0;
|
int option_idx = 0;
|
||||||
int result;
|
int result;
|
||||||
|
@ -2512,8 +2512,6 @@ int main(int argc, char **argv) {
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
WSADATA wsaData;
|
WSADATA wsaData;
|
||||||
|
|
||||||
attach_parent_console();
|
|
||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
|
|
||||||
cmdarg_err_init(failure_warning_message, failure_warning_message);
|
cmdarg_err_init(failure_warning_message, failure_warning_message);
|
||||||
|
@ -2753,13 +2751,19 @@ end:
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
int _stdcall
|
int
|
||||||
WinMain (struct HINSTANCE__ *hInstance,
|
wmain(int argc, wchar_t *wc_argv[])
|
||||||
struct HINSTANCE__ *hPrevInstance,
|
|
||||||
char *lpszCmdLine,
|
|
||||||
int nCmdShow)
|
|
||||||
{
|
{
|
||||||
return main(__argc, __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
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -510,7 +510,7 @@ static int list_config(char *interface, unsigned int remote_port)
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int real_main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int result;
|
int result;
|
||||||
int option_idx = 0;
|
int option_idx = 0;
|
||||||
|
@ -530,8 +530,6 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
WSADATA wsaData;
|
WSADATA wsaData;
|
||||||
|
|
||||||
attach_parent_console();
|
|
||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
|
|
||||||
help_url = data_file_url("ciscodump.html");
|
help_url = data_file_url("ciscodump.html");
|
||||||
|
@ -710,13 +708,19 @@ end:
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
int _stdcall
|
int
|
||||||
WinMain (struct HINSTANCE__ *hInstance,
|
wmain(int argc, wchar_t *wc_argv[])
|
||||||
struct HINSTANCE__ *hPrevInstance,
|
|
||||||
char *lpszCmdLine,
|
|
||||||
int nCmdShow)
|
|
||||||
{
|
{
|
||||||
return main(__argc, __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
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -49,53 +49,6 @@ typedef struct _extcap_option {
|
||||||
|
|
||||||
FILE* custom_log = NULL;
|
FILE* custom_log = NULL;
|
||||||
|
|
||||||
#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)) {
|
|
||||||
g_warning("Cannot redirect to stdout.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (errRedirected == FALSE) {
|
|
||||||
if (!freopen("CONOUT$", "w", stderr)) {
|
|
||||||
g_warning("Cannot redirect to strerr.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void extcap_base_register_interface(extcap_parameters * extcap, const char * interface, const char * ifdescription, uint16_t dlt, const char * dltdescription )
|
void extcap_base_register_interface(extcap_parameters * extcap, const char * interface, const char * ifdescription, uint16_t dlt, const char * dltdescription )
|
||||||
{
|
{
|
||||||
extcap_base_register_interface_ext(extcap, interface, ifdescription, dlt, NULL, dltdescription );
|
extcap_base_register_interface_ext(extcap, interface, ifdescription, dlt, NULL, dltdescription );
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include <io.h>
|
#include <io.h>
|
||||||
|
#include <wsutil/unicode-utils.h> // arg_list_utf_16to8
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <wsutil/socket.h>
|
#include <wsutil/socket.h>
|
||||||
|
@ -58,11 +59,6 @@
|
||||||
{ "debug", required_argument, NULL, EXTCAP_OPT_DEBUG}, \
|
{ "debug", required_argument, NULL, EXTCAP_OPT_DEBUG}, \
|
||||||
{ "debug-file", required_argument, NULL, EXTCAP_OPT_DEBUG_FILE}
|
{ "debug-file", required_argument, NULL, EXTCAP_OPT_DEBUG_FILE}
|
||||||
|
|
||||||
#if defined(_WIN32)
|
|
||||||
BOOLEAN IsHandleRedirected(DWORD handle);
|
|
||||||
void attach_parent_console();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef struct _extcap_parameters
|
typedef struct _extcap_parameters
|
||||||
{
|
{
|
||||||
char * exename;
|
char * exename;
|
||||||
|
|
|
@ -119,7 +119,7 @@ static int list_config(char *interface)
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int real_main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int option_idx = 0;
|
int option_idx = 0;
|
||||||
int result;
|
int result;
|
||||||
|
@ -172,10 +172,6 @@ int main(int argc, char *argv[])
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef _WIN32
|
|
||||||
attach_parent_console();
|
|
||||||
#endif /* _WIN32 */
|
|
||||||
|
|
||||||
while ((result = getopt_long(argc, argv, ":", longopts, &option_idx)) != -1) {
|
while ((result = getopt_long(argc, argv, ":", longopts, &option_idx)) != -1) {
|
||||||
switch (result) {
|
switch (result) {
|
||||||
case OPT_VERSION:
|
case OPT_VERSION:
|
||||||
|
@ -323,13 +319,19 @@ end:
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
int _stdcall
|
int
|
||||||
WinMain (struct HINSTANCE__ *hInstance,
|
wmain(int argc, wchar_t *wc_argv[])
|
||||||
struct HINSTANCE__ *hPrevInstance,
|
|
||||||
char *lpszCmdLine,
|
|
||||||
int nCmdShow)
|
|
||||||
{
|
{
|
||||||
return main(__argc, __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
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -324,7 +324,7 @@ static char* concat_filters(const char* extcap_filter, const char* remote_filter
|
||||||
return g_strdup_printf("(%s) and (%s)", extcap_filter, remote_filter);
|
return g_strdup_printf("(%s) and (%s)", extcap_filter, remote_filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int real_main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int result;
|
int result;
|
||||||
int option_idx = 0;
|
int option_idx = 0;
|
||||||
|
@ -347,8 +347,6 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
WSADATA wsaData;
|
WSADATA wsaData;
|
||||||
|
|
||||||
attach_parent_console();
|
|
||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
|
|
||||||
help_url = data_file_url("sshdump.html");
|
help_url = data_file_url("sshdump.html");
|
||||||
|
@ -534,13 +532,19 @@ end:
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
int _stdcall
|
int
|
||||||
WinMain (struct HINSTANCE__ *hInstance,
|
wmain(int argc, wchar_t *wc_argv[])
|
||||||
struct HINSTANCE__ *hPrevInstance,
|
|
||||||
char *lpszCmdLine,
|
|
||||||
int nCmdShow)
|
|
||||||
{
|
{
|
||||||
return main(__argc, __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
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -354,7 +354,7 @@ static void run_listener(const char* fifo, const guint16 port, const char* proto
|
||||||
g_free(buf);
|
g_free(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int real_main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int option_idx = 0;
|
int option_idx = 0;
|
||||||
int result;
|
int result;
|
||||||
|
@ -367,7 +367,6 @@ int main(int argc, char *argv[])
|
||||||
char* port_msg = NULL;
|
char* port_msg = NULL;
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
WSADATA wsaData;
|
WSADATA wsaData;
|
||||||
attach_parent_console();
|
|
||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
|
|
||||||
help_url = data_file_url("udpdump.html");
|
help_url = data_file_url("udpdump.html");
|
||||||
|
@ -477,13 +476,19 @@ end:
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
int _stdcall
|
int
|
||||||
WinMain (struct HINSTANCE__ *hInstance,
|
wmain(int argc, wchar_t *wc_argv[])
|
||||||
struct HINSTANCE__ *hPrevInstance,
|
|
||||||
char *lpszCmdLine,
|
|
||||||
int nCmdShow)
|
|
||||||
{
|
{
|
||||||
return main(__argc, __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
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue