forked from osmocom/wireshark
extcap: Create unique pipe names for each interface
On Windows the pipe names does not get random characters appended. Add the interface name and pipe type to make it unique. This partly fixes the issue with capturing from multiple extcap interfaces on Windows. Ping-Bug: 13653 Ping-Bug: 13833 Change-Id: I4290b37cf789bf77608993682a803aca29513d28 Reviewed-on: https://code.wireshark.org/review/23158 Petri-Dish: Stig Bjørlykke <stig@bjorlykke.org> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Anders Broman <a.broman58@gmail.com>
This commit is contained in:
parent
5574b78dae
commit
4540195025
|
@ -526,19 +526,12 @@ sync_pipe_start(capture_options *capture_opts, capture_session *cap_session, inf
|
|||
#else
|
||||
si.dwFlags = STARTF_USESTDHANDLES|STARTF_USESHOWWINDOW;
|
||||
si.wShowWindow = SW_HIDE; /* this hides the console window */
|
||||
#if defined(_WIN32)
|
||||
/* needs first a check if NULL *
|
||||
* otherwise wouldn't work with non extcap interfaces */
|
||||
if(interface_opts.extcap_fifo != NULL)
|
||||
{
|
||||
if(strncmp(interface_opts.extcap_fifo,"\\\\.\\pipe\\",9)== 0)
|
||||
{
|
||||
si.hStdInput = extcap_get_win32_handle();
|
||||
}
|
||||
}
|
||||
#ifdef HAVE_EXTCAP
|
||||
if(interface_opts.extcap_pipe_h != INVALID_HANDLE_VALUE)
|
||||
si.hStdInput = interface_opts.extcap_pipe_h;
|
||||
else
|
||||
#endif
|
||||
si.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
|
||||
si.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
|
||||
|
||||
si.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
si.hStdError = sync_pipe_write;
|
||||
|
|
|
@ -68,6 +68,9 @@ capture_opts_init(capture_options *capture_opts)
|
|||
capture_opts->default_options.extcap_args = NULL;
|
||||
capture_opts->default_options.extcap_userdata = NULL;
|
||||
capture_opts->default_options.extcap_pid = INVALID_EXTCAP_PID;
|
||||
#ifdef _WIN32
|
||||
capture_opts->default_options.extcap_pipe_h = INVALID_HANDLE_VALUE;
|
||||
#endif
|
||||
capture_opts->default_options.extcap_control_in = NULL;
|
||||
capture_opts->default_options.extcap_control_out = NULL;
|
||||
#endif
|
||||
|
@ -713,6 +716,9 @@ capture_opts_add_iface_opt(capture_options *capture_opts, const char *optarg_str
|
|||
interface_opts.extcap_args = NULL;
|
||||
interface_opts.extcap_pid = INVALID_EXTCAP_PID;
|
||||
interface_opts.extcap_userdata = NULL;
|
||||
#ifdef _WIN32
|
||||
interface_opts.extcap_pipe_h = INVALID_HANDLE_VALUE;
|
||||
#endif
|
||||
interface_opts.extcap_control_in = g_strdup(capture_opts->default_options.extcap_control_in);
|
||||
interface_opts.extcap_control_out = g_strdup(capture_opts->default_options.extcap_control_out);
|
||||
#endif
|
||||
|
@ -1226,6 +1232,9 @@ collect_ifaces(capture_options *capture_opts)
|
|||
if (interface_opts.extcap_args)
|
||||
g_hash_table_ref(interface_opts.extcap_args);
|
||||
interface_opts.extcap_userdata = NULL;
|
||||
#ifdef _WIN32
|
||||
interface_opts.extcap_pipe_h = INVALID_HANDLE_VALUE;
|
||||
#endif
|
||||
interface_opts.extcap_control_in = NULL;
|
||||
interface_opts.extcap_control_out = NULL;
|
||||
#endif
|
||||
|
|
|
@ -36,6 +36,10 @@
|
|||
|
||||
#include <caputils/capture_ifinfo.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
@ -232,6 +236,9 @@ typedef struct interface_options_tag {
|
|||
GPid extcap_pid; /* pid of running process or INVALID_EXTCAP_PID */
|
||||
gpointer extcap_userdata;
|
||||
guint extcap_child_watch;
|
||||
#ifdef _WIN32
|
||||
HANDLE extcap_pipe_h;
|
||||
#endif
|
||||
gchar *extcap_control_in;
|
||||
gchar *extcap_control_out;
|
||||
#endif
|
||||
|
|
44
extcap.c
44
extcap.c
|
@ -63,7 +63,7 @@
|
|||
#include "extcap_spawn.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
static HANDLE pipe_h = NULL;
|
||||
static HANDLE pipe_h = INVALID_HANDLE_VALUE;
|
||||
#endif
|
||||
|
||||
static void extcap_child_watch_cb(GPid pid, gint status, gpointer user_data);
|
||||
|
@ -1032,13 +1032,14 @@ void extcap_if_cleanup(capture_options *capture_opts, gchar **errormsg)
|
|||
"Extcap [%s] - Cleaning up fifo: %s; PID: %d", interface_opts.name,
|
||||
interface_opts.extcap_fifo, interface_opts.extcap_pid);
|
||||
#ifdef _WIN32
|
||||
if (pipe_h)
|
||||
if (interface_opts.extcap_pipe_h != INVALID_HANDLE_VALUE)
|
||||
{
|
||||
g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG,
|
||||
"Extcap [%s] - Closing pipe", interface_opts.name);
|
||||
FlushFileBuffers(pipe_h);
|
||||
DisconnectNamedPipe(pipe_h);
|
||||
CloseHandle(pipe_h);
|
||||
FlushFileBuffers(interface_opts.extcap_pipe_h);
|
||||
DisconnectNamedPipe(interface_opts.extcap_pipe_h);
|
||||
CloseHandle(interface_opts.extcap_pipe_h);
|
||||
interface_opts.extcap_pipe_h = INVALID_HANDLE_VALUE;
|
||||
}
|
||||
#else
|
||||
if (interface_opts.extcap_fifo != NULL && file_exists(interface_opts.extcap_fifo))
|
||||
|
@ -1353,15 +1354,21 @@ extcap_init_interfaces(capture_options *capture_opts)
|
|||
/* create control pipes if having toolbar */
|
||||
if (extcap_has_toolbar(interface_opts.name))
|
||||
{
|
||||
extcap_create_pipe(&interface_opts.extcap_control_in);
|
||||
extcap_create_pipe(&interface_opts.extcap_control_out);
|
||||
extcap_create_pipe(interface_opts.name, &interface_opts.extcap_control_in,
|
||||
EXTCAP_CONTROL_IN_PREFIX);
|
||||
extcap_create_pipe(interface_opts.name, &interface_opts.extcap_control_out,
|
||||
EXTCAP_CONTROL_OUT_PREFIX);
|
||||
}
|
||||
|
||||
/* create pipe for fifo */
|
||||
if (!extcap_create_pipe(&interface_opts.extcap_fifo))
|
||||
if (!extcap_create_pipe(interface_opts.name, &interface_opts.extcap_fifo,
|
||||
EXTCAP_PIPE_PREFIX))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
#ifdef _WIN32
|
||||
interface_opts.extcap_pipe_h = pipe_h;
|
||||
#endif
|
||||
|
||||
/* Create extcap call */
|
||||
args = extcap_prepare_arguments(interface_opts);
|
||||
|
@ -1396,9 +1403,8 @@ extcap_init_interfaces(capture_options *capture_opts)
|
|||
*/
|
||||
if (pid != INVALID_EXTCAP_PID)
|
||||
{
|
||||
extcap_wait_for_pipe(pipe_h, pid);
|
||||
extcap_wait_for_pipe(interface_opts.extcap_pipe_h, pid);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
interface_opts.extcap_userdata = (gpointer) userdata;
|
||||
|
@ -1410,16 +1416,7 @@ extcap_init_interfaces(capture_options *capture_opts)
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
/* called by capture_sync to get the CreatNamedPipe handle*/
|
||||
HANDLE
|
||||
extcap_get_win32_handle()
|
||||
{
|
||||
return pipe_h;
|
||||
}
|
||||
#endif
|
||||
|
||||
gboolean extcap_create_pipe(char **fifo)
|
||||
gboolean extcap_create_pipe(const gchar *ifname, gchar **fifo, const gchar *pipe_prefix)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
gchar timestr[ 14 + 1 ];
|
||||
|
@ -1435,7 +1432,7 @@ gboolean extcap_create_pipe(char **fifo)
|
|||
* so we won't get a null pointer back from localtime().
|
||||
*/
|
||||
strftime(timestr, sizeof(timestr), "%Y%m%d%H%M%S", localtime(¤t_time));
|
||||
pipename = g_strconcat("\\\\.\\pipe\\", EXTCAP_PIPE_PREFIX, "_", timestr, NULL);
|
||||
pipename = g_strconcat("\\\\.\\pipe\\", pipe_prefix, "_", ifname, "_", timestr, NULL);
|
||||
|
||||
/* Security struct to enable Inheritable HANDLE */
|
||||
memset(&security, 0, sizeof(SECURITY_ATTRIBUTES));
|
||||
|
@ -1466,10 +1463,13 @@ gboolean extcap_create_pipe(char **fifo)
|
|||
gchar *temp_name = NULL;
|
||||
int fd = 0;
|
||||
|
||||
if ((fd = create_tempfile(&temp_name, EXTCAP_PIPE_PREFIX, NULL)) < 0)
|
||||
gchar *pfx = g_strconcat(pipe_prefix, "_", ifname, NULL);
|
||||
if ((fd = create_tempfile(&temp_name, pfx, NULL)) < 0)
|
||||
{
|
||||
g_free(pfx);
|
||||
return FALSE;
|
||||
}
|
||||
g_free(pfx);
|
||||
|
||||
ws_close(fd);
|
||||
|
||||
|
|
10
extcap.h
10
extcap.h
|
@ -29,7 +29,6 @@
|
|||
#include <glib.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#include <wsutil/unicode-utils.h>
|
||||
#endif
|
||||
|
||||
|
@ -41,6 +40,8 @@
|
|||
|
||||
/* Prefix for the pipe interfaces */
|
||||
#define EXTCAP_PIPE_PREFIX "wireshark_extcap"
|
||||
#define EXTCAP_CONTROL_IN_PREFIX "wireshark_control_in"
|
||||
#define EXTCAP_CONTROL_OUT_PREFIX "wireshark_control_out"
|
||||
|
||||
#define EXTCAP_ARGUMENT_CONFIG "--extcap-config"
|
||||
#define EXTCAP_ARGUMENT_LIST_INTERFACES "--extcap-interfaces"
|
||||
|
@ -138,16 +139,11 @@ extcap_has_configuration(const char * ifname, gboolean is_required);
|
|||
gboolean
|
||||
extcap_has_toolbar(const char *ifname);
|
||||
|
||||
#ifdef WIN32
|
||||
HANDLE
|
||||
extcap_get_win32_handle();
|
||||
#endif
|
||||
|
||||
gboolean
|
||||
extcap_init_interfaces(capture_options * capture_opts);
|
||||
|
||||
gboolean
|
||||
extcap_create_pipe(char ** fifo);
|
||||
extcap_create_pipe(const gchar *ifname, gchar **fifo, const gchar *pipe_prefix);
|
||||
|
||||
/* Clean up all if related stuff */
|
||||
void
|
||||
|
|
Loading…
Reference in New Issue