3 * Routines for extcap external capture
4 * Copyright 2013, Mike Ryan <mikeryan@lacklustre.net>
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
36 /* Include for unlink */
43 #include <epan/prefs.h>
44 #include <epan/prefs-int.h>
46 #include <wsutil/file_util.h>
47 #include <wsutil/filesystem.h>
48 #include <wsutil/tempfile.h>
50 #include "capture_opts.h"
55 #include "extcap_parser.h"
58 static HANDLE pipe_h = NULL;
61 /* internal container, for all the extcap interfaces that have been found.
62 * will be resetted by every call to extcap_interface_list() and is being
63 * used in extcap_get_if_* as well as extcap_init_interfaces to ensure,
64 * that only extcap interfaces are being given to underlying extcap programs
66 static GHashTable *ifaces = NULL;
68 /* internal container, for all the extcap executables that have been found.
69 * will be resetted by every call to extcap_interface_list() and is being
70 * used for printing information about all extcap interfaces found
72 static GHashTable *tools = NULL;
74 /* Callback definition for extcap_foreach */
75 typedef gboolean (*extcap_cb_t)(const gchar *extcap, const gchar *ifname, gchar *output, void *data,
78 /* #define ARG_DEBUG */
80 static void extcap_debug_arguments ( extcap_arg *arg_iter );
84 extcap_if_exists(const gchar *ifname)
86 if ( !ifname || !ifaces )
89 if ( g_hash_table_lookup(ifaces, ifname) )
96 extcap_if_exists_for_extcap(const gchar *ifname, const gchar *extcap)
98 gchar *entry = (gchar *)g_hash_table_lookup(ifaces, ifname);
100 if ( entry && strcmp(entry, extcap) == 0 )
107 extcap_if_executable(const gchar *ifname)
109 return (gchar *)g_hash_table_lookup(ifaces, ifname);
113 extcap_if_add(const gchar *ifname, const gchar *extcap)
115 if ( !g_hash_table_lookup(ifaces, ifname) )
116 g_hash_table_insert(ifaces, g_strdup(ifname), g_strdup(extcap));
120 extcap_tool_add(const gchar *extcap, const extcap_interface *interface)
124 if ( !extcap || !interface )
127 toolname = g_path_get_basename(extcap);
129 if ( !g_hash_table_lookup(tools, toolname) ) {
130 extcap_info * store = (extcap_info *)g_new0(extcap_info, 1);
131 store->version = g_strdup(interface->version);
132 store->full_path = g_strdup(extcap);
133 store->basename = g_strdup(toolname);
135 g_hash_table_insert(tools, g_strdup(toolname), store);
141 /* Note: args does not need to be NULL-terminated. */
142 static void extcap_foreach(gint argc, gchar **args, extcap_cb_t cb,
143 void *cb_data, char **err_str, const char * ifname _U_) {
144 const char *dirname = get_extcap_dir();
151 gchar **dll_search_envp;
157 argv = (gchar **) g_malloc0(sizeof(gchar *) * (argc + 2));
161 * Make sure executables can find dependent DLLs and that they're *our*
162 * DLLs: https://msdn.microsoft.com/en-us/library/windows/desktop/ms682586.aspx
163 * Alternatively we could create a simple wrapper exe similar to Create
164 * Hidden Process (http://www.commandline.co.uk/chp/).
166 dll_search_envp = g_get_environ();
167 progfile_dir = g_strdup_printf("%s;%s", get_progfile_dir(), g_environ_getenv(dll_search_envp, "Path"));
168 dll_search_envp = g_environ_setenv(dll_search_envp, "Path", progfile_dir, TRUE);
169 g_free(progfile_dir);
172 if ((dir = g_dir_open(dirname, 0, NULL)) != NULL) {
173 GString *extcap_path = NULL;
175 extcap_path = g_string_new("");
176 while (keep_going && (file = g_dir_read_name(dir)) != NULL ) {
177 gchar *command_output = NULL;
178 gboolean status = FALSE;
179 gint exit_status = 0;
182 /* full path to extcap binary */
184 g_string_printf(extcap_path, "%s\\%s", dirname, file);
185 envp = dll_search_envp;
187 g_string_printf(extcap_path, "%s/%s", dirname, file);
189 if ( extcap_if_exists(ifname) && !extcap_if_exists_for_extcap(ifname, extcap_path->str ) )
193 argv[0] = g_strescape(extcap_path->str, NULL);
195 argv[0] = g_strdup(extcap_path->str);
197 for (i = 0; i < argc; ++i)
201 status = g_spawn_sync(dirname, argv, envp,
202 (GSpawnFlags) 0, NULL, NULL,
203 &command_output, NULL, &exit_status, NULL);
205 if (status && exit_status == 0)
206 keep_going = cb(extcap_path->str, ifname, command_output, cb_data, err_str);
209 g_free(command_output);
213 g_string_free(extcap_path, TRUE);
217 g_strfreev(dll_search_envp);
222 static gboolean dlt_cb(const gchar *extcap _U_, const gchar *ifname _U_, gchar *output, void *data,
224 extcap_token_sentence *tokens;
225 extcap_dlt *dlts, *dlt_iter, *next;
226 if_capabilities_t *caps;
227 GList *linktype_list = NULL;
228 data_link_info_t *data_link_info;
230 tokens = extcap_tokenize_sentences(output);
231 extcap_parse_dlts(tokens, &dlts);
233 extcap_free_tokenized_sentence_list(tokens);
235 g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, "Extcap pipe %s ", extcap);
238 * Allocate the interface capabilities structure.
240 caps = (if_capabilities_t *) g_malloc(sizeof *caps);
241 caps->can_set_rfmon = FALSE;
244 while (dlt_iter != NULL ) {
245 g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG,
246 " DLT %d name=\"%s\" display=\"%s\" ", dlt_iter->number,
247 dlt_iter->name, dlt_iter->display);
249 data_link_info = g_new(data_link_info_t, 1);
250 data_link_info->dlt = dlt_iter->number;
251 data_link_info->name = g_strdup(dlt_iter->name);
252 data_link_info->description = g_strdup(dlt_iter->display);
253 linktype_list = g_list_append(linktype_list, data_link_info);
254 dlt_iter = dlt_iter->next_dlt;
257 /* Check to see if we built a list */
258 if (linktype_list != NULL && data != NULL) {
259 caps->data_link_types = linktype_list;
260 *(if_capabilities_t **) data = caps;
263 g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, " returned no DLTs");
264 *err_str = g_strdup("Extcap returned no DLTs");
270 while (dlt_iter != NULL ) {
271 next = dlt_iter->next_dlt;
272 extcap_free_dlt(dlt_iter);
280 extcap_get_if_dlts(const gchar *ifname, char **err_str) {
283 if_capabilities_t *caps = NULL;
288 if ( extcap_if_exists(ifname) )
290 argv[0] = g_strdup(EXTCAP_ARGUMENT_LIST_DLTS);
291 argv[1] = g_strdup(EXTCAP_ARGUMENT_INTERFACE);
292 argv[2] = g_strdup(ifname);
294 extcap_foreach(3, argv, dlt_cb, &caps, err_str, ifname);
296 for (i = 0; i < 3; ++i)
303 static gboolean interfaces_cb(const gchar *extcap, const gchar *ifname _U_, gchar *output, void *data,
304 char **err_str _U_) {
305 GList **il = (GList **) data;
306 extcap_token_sentence *tokens;
307 extcap_interface *interfaces, *int_iter; /*, *next; */
310 tokens = extcap_tokenize_sentences(output);
311 extcap_parse_interfaces(tokens, &interfaces);
313 extcap_free_tokenized_sentence_list(tokens);
315 g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, "Extcap pipe %s ", extcap);
317 int_iter = interfaces;
318 while (int_iter != NULL ) {
319 if ( int_iter->if_type == EXTCAP_SENTENCE_INTERFACE && extcap_if_exists(int_iter->call) )
321 g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_WARNING, "Extcap interface \"%s\" is already provided by \"%s\" ",
322 int_iter->call, (gchar *)extcap_if_executable(int_iter->call) );
323 int_iter = int_iter->next_interface;
327 if ( int_iter->if_type == EXTCAP_SENTENCE_INTERFACE )
328 g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, " Interface [%s] \"%s\" ",
329 int_iter->call, int_iter->display);
330 else if ( int_iter->if_type == EXTCAP_SENTENCE_EXTCAP )
331 g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, " Extcap [%s] ", int_iter->call);
333 if ( int_iter->if_type == EXTCAP_SENTENCE_INTERFACE ) {
334 if_info = g_new0(if_info_t, 1);
335 if_info->name = g_strdup(int_iter->call);
336 if_info->friendly_name = g_strdup(int_iter->display);
338 if_info->type = IF_EXTCAP;
340 if_info->extcap = g_strdup(extcap);
341 *il = g_list_append(*il, if_info);
343 extcap_if_add(int_iter->call, extcap);
346 /* Call for interfaces and tools alike. Multiple calls (because a tool has multiple
347 * interfaces) are handled internally */
348 extcap_tool_add(extcap, int_iter);
350 int_iter = int_iter->next_interface;
352 extcap_free_interface(interfaces);
358 if_info_compare(gconstpointer a, gconstpointer b)
361 if_info_t * if_a = (if_info_t *)a;
362 if_info_t * if_b = (if_info_t *)b;
364 if ( (comp = g_strcmp0(if_a->name, if_b->name)) == 0 )
365 return g_strcmp0(if_a->friendly_name, if_b->friendly_name);
371 extcap_tools_list(void) {
372 if ( tools == NULL || g_hash_table_size(tools) == 0 )
373 extcap_interface_list(NULL);
379 extcap_free_info (gpointer data) {
380 extcap_info * info = (extcap_info *)data;
382 g_free (info->basename);
383 g_free (info->full_path);
384 g_free (info->version);
389 extcap_interface_list(char **err_str) {
397 /* ifaces is used as cache, do not destroy its contents when
398 * returning or no extcap interfaces can be queried for options */
400 ifaces = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
402 g_hash_table_remove_all(ifaces);
405 tools = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, extcap_free_info);
407 g_hash_table_remove_all(tools);
409 argv = g_strdup(EXTCAP_ARGUMENT_LIST_INTERFACES);
411 extcap_foreach(1, &argv, interfaces_cb, &ret, err_str, NULL);
415 return g_list_sort ( ret, if_info_compare );
418 static void extcap_free_arg_elem(gpointer data, gpointer user_data _U_) {
419 extcap_free_arg((extcap_arg *) data);
423 void extcap_register_preferences(void)
425 GList * interfaces = NULL;
427 module_t * dev_module = prefs_find_module("extcap");
432 if ( ! ifaces || g_hash_table_size(ifaces) == 0 )
433 extcap_interface_list(NULL);
435 interfaces = g_hash_table_get_keys(ifaces);
437 while ( interfaces ) {
438 extcap_get_if_configuration((gchar *)interfaces->data);
440 interfaces = g_list_next(interfaces);
444 static void extcap_free_if_configuration(GList *list)
448 for (elem = g_list_first(list); elem; elem = elem->next)
450 if (elem->data != NULL) {
451 /* g_list_free_full() only exists since 2.28. */
452 sl = g_list_first((GList *)elem->data);
453 g_list_foreach(sl, (GFunc)extcap_free_arg_elem, NULL);
460 gchar * extcap_settings_key(const gchar * ifname, const gchar * setting)
462 gchar * setting_nohyphen;
463 gchar * ifname_underscore;
464 gchar * ifname_lower;
466 GRegex * regex = g_regex_new ("(?![a-zA-Z1-9_]).", (GRegexCompileFlags) 0, (GRegexMatchFlags) 0, NULL );
472 g_regex_replace_literal(regex, setting, strlen(setting), 0,
473 "", (GRegexMatchFlags) 0, NULL );
475 g_regex_replace_literal(regex, ifname, strlen(ifname), 0,
476 "_", (GRegexMatchFlags) 0, NULL );
477 ifname_lower = g_utf8_strdown(ifname_underscore, -1);
478 key = g_strconcat(ifname_lower, ".", setting_nohyphen, NULL);
480 g_free(setting_nohyphen);
481 g_free(ifname_underscore);
482 g_free(ifname_lower);
483 g_regex_unref(regex);
488 static gboolean search_cb(const gchar *extcap _U_, const gchar *ifname _U_, gchar *output, void *data,
489 char **err_str _U_) {
490 extcap_token_sentence *tokens = NULL;
491 GList *arguments = NULL;
492 GList **il = (GList **) data;
493 module_t * dev_module = NULL;
495 tokens = extcap_tokenize_sentences(output);
496 arguments = extcap_parse_args(tokens);
498 extcap_free_tokenized_sentence_list(tokens);
501 extcap_debug_arguments ( arguments );
504 dev_module = prefs_find_module("extcap");
507 GList * walker = arguments;
509 while ( walker != NULL ) {
510 extcap_arg * arg = (extcap_arg *)walker->data;
513 struct preference * pref = NULL;
514 gchar * pref_ifname = extcap_settings_key(ifname, arg->call);
516 if ( ( pref = prefs_find_preference(dev_module, pref_ifname) ) == NULL ) {
517 /* Set an initial value */
518 if ( ! arg->storeval && arg->default_complex )
519 arg->storeval = g_strdup(arg->default_complex->_val);
521 prefs_register_string_preference(dev_module, g_strdup(pref_ifname),
522 arg->display, arg->display, (const gchar **)&(arg->storeval));
524 /* Been here before, restore stored value */
525 if (! arg->storeval && pref->varp.string)
526 arg->storeval = g_strdup(*(pref->varp.string));
531 walker = g_list_next(walker);
535 *il = g_list_append(*il, arguments);
537 /* By returning false, extcap_foreach will break on first found */
542 extcap_get_if_configuration(const char * ifname) {
545 gchar **err_str = NULL;
548 if ( extcap_if_exists(ifname) )
550 g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, "Extcap path %s",
553 argv[0] = g_strdup(EXTCAP_ARGUMENT_CONFIG);
554 argv[1] = g_strdup(EXTCAP_ARGUMENT_INTERFACE);
555 argv[2] = g_strdup(ifname);
557 extcap_foreach(3, argv, search_cb, &ret, err_str, ifname);
559 for (i = 0; i < 3; i++)
567 extcap_has_configuration(const char * ifname, gboolean is_required) {
568 GList * arguments = 0;
569 GList * walker = 0, * item = 0;
571 gboolean found = FALSE;
573 arguments = extcap_get_if_configuration((const char *)( ifname ) );
574 walker = g_list_first(arguments);
576 while ( walker != NULL && ! found ) {
577 item = g_list_first((GList *)(walker->data));
578 while ( item != NULL && ! found ) {
579 if ( (extcap_arg *)(item->data) != NULL ) {
580 extcap_arg * arg = (extcap_arg *)(item->data);
581 /* Should required options be present, or any kind of options */
584 else if ( arg->is_required ) {
585 gchar * stored = NULL;
586 gchar * defval = NULL;
588 if ( arg->storeval != NULL )
589 stored = arg->storeval;
591 if ( arg->default_complex != NULL && arg->default_complex->_val != NULL )
592 defval = arg->default_complex->_val;
594 if ( arg->is_required ) {
595 /* If stored and defval is identical and the argument is required,
596 * configuration is needed */
597 if ( defval && stored && g_strcmp0(stored, defval) == 0 )
599 else if ( ! defval && (!stored || strlen(g_strchomp(stored)) <= (size_t)0) )
603 if ( arg->arg_type == EXTCAP_ARG_FILESELECT ) {
604 if ( arg->fileexists && ! ( file_exists(defval) || file_exists(stored) ) )
612 walker = walker->next;
614 extcap_free_if_configuration(arguments);
619 void extcap_cleanup(capture_options * capture_opts) {
620 interface_options interface_opts;
623 for (icnt = 0; icnt < capture_opts->ifaces->len; icnt++) {
624 interface_opts = g_array_index(capture_opts->ifaces, interface_options,
627 /* skip native interfaces */
628 if (interface_opts.if_type != IF_EXTCAP)
631 g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG,
632 "Extcap [%s] - Cleaning up fifo: %s; PID: %d", interface_opts.name,
633 interface_opts.extcap_fifo, interface_opts.extcap_pid);
637 g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG,
638 "Extcap [%s] - Closing pipe", interface_opts.name);
639 FlushFileBuffers(pipe_h);
640 DisconnectNamedPipe(pipe_h);
644 if (interface_opts.extcap_fifo != NULL && file_exists(interface_opts.extcap_fifo))
646 /* the fifo will not be freed here, but with the other capture_opts in capture_sync */
647 ws_unlink(interface_opts.extcap_fifo);
648 interface_opts.extcap_fifo = NULL;
651 /* Maybe the client closed and removed fifo, but ws should check if
652 * pid should be closed */
653 g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG,
654 "Extcap [%s] - Closing spawned PID: %d", interface_opts.name,
655 interface_opts.extcap_pid);
657 if (interface_opts.extcap_pid != INVALID_EXTCAP_PID)
660 TerminateProcess(interface_opts.extcap_pid, 0);
662 g_spawn_close_pid(interface_opts.extcap_pid);
663 interface_opts.extcap_pid = INVALID_EXTCAP_PID;
666 /* Make sure modified interface_opts is saved in capture_opts. */
667 capture_opts->ifaces = g_array_remove_index(capture_opts->ifaces, icnt);
668 g_array_insert_val(capture_opts->ifaces, icnt, interface_opts);
673 extcap_add_arg_and_remove_cb(gpointer key, gpointer value, gpointer data) {
674 GPtrArray *args = (GPtrArray *)data;
678 g_ptr_array_add(args, g_strdup((const gchar*)key));
681 g_ptr_array_add(args, g_strdup((const gchar*)value));
689 static void extcap_child_watch_cb(GPid pid, gint status _U_, gpointer user_data)
692 interface_options interface_opts;
693 capture_options *capture_opts = (capture_options *)user_data;
695 /* Close handle to child process. */
696 g_spawn_close_pid(pid);
698 /* Update extcap_pid in interface options structure. */
699 for (i = 0; i < capture_opts->ifaces->len; i++)
701 interface_opts = g_array_index(capture_opts->ifaces, interface_options, i);
702 if (interface_opts.extcap_pid == pid)
704 interface_opts.extcap_pid = INVALID_EXTCAP_PID;
705 g_source_remove(interface_opts.extcap_child_watch);
706 interface_opts.extcap_child_watch = 0;
708 capture_opts->ifaces = g_array_remove_index(capture_opts->ifaces, i);
709 g_array_insert_val(capture_opts->ifaces, i, interface_opts);
715 /* call mkfifo for each extcap,
716 * returns FALSE if there's an error creating a FIFO */
718 extcap_init_interfaces(capture_options *capture_opts)
721 interface_options interface_opts;
723 for (i = 0; i < capture_opts->ifaces->len; i++)
725 GPtrArray *args = NULL;
726 GPid pid = INVALID_EXTCAP_PID;
730 interface_opts = g_array_index(capture_opts->ifaces, interface_options, i);
732 /* skip native interfaces */
733 if (interface_opts.if_type != IF_EXTCAP )
736 /* create pipe for fifo */
737 if ( ! extcap_create_pipe ( &interface_opts.extcap_fifo ) )
740 /* Create extcap call */
741 args = g_ptr_array_new();
742 #define add_arg(X) g_ptr_array_add(args, g_strdup(X))
744 add_arg(interface_opts.extcap);
745 add_arg(EXTCAP_ARGUMENT_RUN_CAPTURE);
746 add_arg(EXTCAP_ARGUMENT_INTERFACE);
747 add_arg(interface_opts.name);
748 if (interface_opts.cfilter && strlen(interface_opts.cfilter) > 0) {
749 add_arg(EXTCAP_ARGUMENT_CAPTURE_FILTER);
750 add_arg(interface_opts.cfilter);
752 add_arg(EXTCAP_ARGUMENT_RUN_PIPE);
753 add_arg(interface_opts.extcap_fifo);
754 if (interface_opts.extcap_args == NULL || g_hash_table_size(interface_opts.extcap_args) == 0)
756 /* User did not perform interface configuration.
758 * Check if there are any boolean flags that are set by default
759 * and hence their argument should be added.
764 arglist = extcap_get_if_configuration(interface_opts.name);
765 for (elem = g_list_first(arglist); elem; elem = elem->next)
768 extcap_arg *arg_iter;
770 if (elem->data == NULL)
775 arg_list = g_list_first((GList *)elem->data);
776 while (arg_list != NULL) {
777 gchar * stored = NULL, * defval = NULL;
778 /* In case of boolflags only first element in arg_list is relevant. */
779 arg_iter = (extcap_arg*) (arg_list->data);
780 if ( arg_iter->storeval != NULL )
781 stored = arg_iter->storeval;
783 if ( arg_iter->default_complex != NULL && arg_iter->default_complex->_val != NULL )
784 defval = arg_iter->default_complex->_val;
786 /* Different data in storage then set for default */
787 if ( g_strcmp0(stored, defval) != 0 ) {
788 if ( arg_iter->arg_type == EXTCAP_ARG_BOOLFLAG ) {
789 if ( g_strcmp0(stored, "true") == 0 )
790 add_arg(arg_iter->call);
792 gchar * call = g_strconcat(arg_iter->call, " ", stored, NULL);
796 } else if (arg_iter->arg_type == EXTCAP_ARG_BOOLFLAG) {
797 if (extcap_complex_get_bool(arg_iter->default_complex))
798 add_arg(arg_iter->call);
801 arg_list = arg_list->next;
805 extcap_free_if_configuration(arglist);
809 g_hash_table_foreach_remove(interface_opts.extcap_args, extcap_add_arg_and_remove_cb, args);
814 /* Dump commandline parameters sent to extcap. */
815 for (tmp = (gchar **)args->pdata, tmp_i = 0; *tmp && **tmp; ++tmp_i, ++tmp)
817 g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, "argv[%d]: %s", tmp_i, *tmp);
820 /* Wireshark for windows crashes here sometimes *
821 * Access violation reading location 0x... */
822 g_spawn_async(NULL, (gchar **)args->pdata, NULL,
823 (GSpawnFlags) G_SPAWN_DO_NOT_REAP_CHILD, NULL, NULL,
826 g_ptr_array_foreach(args, (GFunc)g_free, NULL);
827 g_ptr_array_free(args, TRUE);
828 interface_opts.extcap_pid = pid;
829 interface_opts.extcap_child_watch =
830 g_child_watch_add(pid, extcap_child_watch_cb, (gpointer)capture_opts);
831 capture_opts->ifaces = g_array_remove_index(capture_opts->ifaces, i);
832 g_array_insert_val(capture_opts->ifaces, i, interface_opts);
835 /* On Windows, wait for extcap to connect to named pipe.
836 * Some extcaps will present UAC screen to user.
837 * 30 second timeout should be reasonable timeout for extcap to
838 * connect to named pipe (including user interaction).
839 * Wait on multiple object in case of extcap termination
840 * without opening pipe.
842 * Minimum supported version of Windows: XP / Server 2003.
844 if (pid != INVALID_EXTCAP_PID)
850 ov.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
852 ConnectNamedPipe(pipe_h, &ov);
853 handles[0] = ov.hEvent;
856 if (GetLastError() == ERROR_PIPE_CONNECTED)
858 g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, "extcap connected to pipe");
862 dw = WaitForMultipleObjects(2, handles, FALSE, 30000);
863 if (dw == WAIT_OBJECT_0)
865 /* ConnectNamedPipe finished. */
868 code = GetLastError();
869 if (code == ERROR_IO_PENDING)
872 if (!GetOverlappedResult(ov.hEvent, &ov, &dummy, TRUE))
874 code = GetLastError();
878 code = ERROR_SUCCESS;
882 g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, "ConnectNamedPipe code: %d", code);
884 else if (dw == (WAIT_OBJECT_0 + 1))
886 /* extcap process terminated. */
887 g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, "extcap terminated without connecting to pipe!");
889 else if (dw == WAIT_TIMEOUT)
891 g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, "extcap didn't connect to pipe within 30 seconds!");
895 g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, "WaitForMultipleObjects returned 0x%08X. Error %d", dw, GetLastError());
899 CloseHandle(ov.hEvent);
908 /* called by capture_sync to get the CreatNamedPipe handle*/
910 extcap_get_win32_handle()
916 gboolean extcap_create_pipe(char ** fifo)
919 gchar timestr[ 14+1 ];
922 gchar *pipename = NULL;
924 SECURITY_ATTRIBUTES security;
925 /* create pipename */
926 current_time = time(NULL);
927 strftime(timestr, sizeof(timestr), "%Y%m%d%H%M%S", localtime(¤t_time));
928 pipename = g_strconcat ( "\\\\.\\pipe\\", EXTCAP_PIPE_PREFIX, "_", timestr, NULL );
930 /* Security struct to enable Inheritable HANDLE */
931 memset(&security, 0, sizeof(SECURITY_ATTRIBUTES));
932 security.nLength = sizeof(SECURITY_ATTRIBUTES);
933 security.bInheritHandle = TRUE;
934 security.lpSecurityDescriptor = NULL;
936 /* create a namedPipe*/
937 pipe_h = CreateNamedPipe(
939 PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED,
940 PIPE_TYPE_MESSAGE| PIPE_READMODE_MESSAGE | PIPE_WAIT,
945 if (pipe_h == INVALID_HANDLE_VALUE)
947 g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG,"\nError creating pipe => (%d)", GetLastError());
952 g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG,"\nWireshark Created pipe =>(%s)",pipename);
953 *fifo = g_strdup(pipename);
956 gchar *temp_name = NULL;
959 if ((fd = create_tempfile(&temp_name, EXTCAP_PIPE_PREFIX)) < 0 )
964 g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG,
965 "Extcap - Creating fifo: %s", temp_name);
967 if ( file_exists(temp_name) )
968 ws_unlink(temp_name);
970 if (mkfifo(temp_name, 0600) == 0)
971 *fifo = g_strdup(temp_name);
978 void extcap_debug_arguments ( extcap_arg *arg_iter )
980 extcap_value *v = NULL;
981 GList *walker = NULL;
983 printf("debug - parser dump\n");
984 while (arg_iter != NULL) {
985 printf("ARG %d call=%s display=\"%s\" type=", arg_iter->arg_num, arg_iter->call, arg_iter->display);
987 switch (arg_iter->arg_type) {
988 case EXTCAP_ARG_INTEGER:
991 case EXTCAP_ARG_UNSIGNED:
992 printf("unsigned\n");
994 case EXTCAP_ARG_LONG:
997 case EXTCAP_ARG_DOUBLE:
1000 case EXTCAP_ARG_BOOLEAN:
1001 printf("boolean\n");
1003 case EXTCAP_ARG_MENU:
1006 case EXTCAP_ARG_RADIO:
1009 case EXTCAP_ARG_SELECTOR:
1010 printf("selctor\n");
1012 case EXTCAP_ARG_STRING:
1013 printf ( "string\n" );
1015 case EXTCAP_ARG_PASSWORD:
1016 printf ( "PASSWORD\n" );
1018 case EXTCAP_ARG_MULTICHECK:
1019 printf ( "unknown\n" );
1021 case EXTCAP_ARG_UNKNOWN:
1022 printf ( "unknown\n" );
1026 if (arg_iter->range_start != NULL && arg_iter->range_end != NULL) {
1027 printf("\tRange: ");
1028 extcap_printf_complex(arg_iter->range_start);
1030 extcap_printf_complex(arg_iter->range_end);
1034 for ( walker = g_list_first ( arg_iter->value_list ); walker; walker = walker->next )
1036 v = (extcap_value *)walker->data;
1039 printf("\tcall=\"%p\" display=\"%p\"\n", v->call, v->display);
1040 printf("\tcall=\"%s\" display=\"%s\"\n", v->call, v->display);
1043 arg_iter = arg_iter->next_arg;
1050 * Editor modelines - http://www.wireshark.org/tools/modelines.html
1055 * indent-tabs-mode: nil
1058 * vi: set shiftwidth=4 tabstop=8 expandtab:
1059 * :indentSize=4:tabSize=8:noTabs=true: