2 * Routines for capture options setting
4 * Wireshark - Network traffic analyzer
5 * By Gerald Combs <gerald@wireshark.org>
6 * Copyright 1998 Gerald Combs
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
36 #include "capture_opts.h"
37 #include "ringbuffer.h"
39 #include <wsutil/clopts_common.h>
40 #include <wsutil/cmdarg_err.h>
41 #include <wsutil/file_util.h>
43 #include "caputils/capture_ifinfo.h"
44 #include "caputils/capture-pcap-util.h"
46 #include "ui/filter_files.h"
48 static gboolean capture_opts_output_to_pipe(const char *save_file, gboolean *is_pipe);
52 capture_opts_init(capture_options *capture_opts)
54 capture_opts->ifaces = g_array_new(FALSE, FALSE, sizeof(interface_options));
55 capture_opts->all_ifaces = g_array_new(FALSE, FALSE, sizeof(interface_t));
56 capture_opts->num_selected = 0;
57 capture_opts->default_options.name = NULL;
58 capture_opts->default_options.descr = NULL;
59 capture_opts->default_options.cfilter = NULL;
60 capture_opts->default_options.has_snaplen = FALSE;
61 capture_opts->default_options.snaplen = WTAP_MAX_PACKET_SIZE_STANDARD;
62 capture_opts->default_options.linktype = -1; /* use interface default */
63 capture_opts->default_options.promisc_mode = TRUE;
64 capture_opts->default_options.if_type = IF_WIRED;
66 capture_opts->default_options.extcap = NULL;
67 capture_opts->default_options.extcap_fifo = NULL;
68 capture_opts->default_options.extcap_args = NULL;
69 capture_opts->default_options.extcap_userdata = NULL;
70 capture_opts->default_options.extcap_pid = INVALID_EXTCAP_PID;
72 capture_opts->default_options.extcap_pipe_h = INVALID_HANDLE_VALUE;
73 capture_opts->default_options.extcap_control_in_h = INVALID_HANDLE_VALUE;
74 capture_opts->default_options.extcap_control_out_h = INVALID_HANDLE_VALUE;
76 capture_opts->default_options.extcap_control_in = NULL;
77 capture_opts->default_options.extcap_control_out = NULL;
79 #ifdef CAN_SET_CAPTURE_BUFFER_SIZE
80 capture_opts->default_options.buffer_size = DEFAULT_CAPTURE_BUFFER_SIZE;
82 capture_opts->default_options.monitor_mode = FALSE;
83 #ifdef HAVE_PCAP_REMOTE
84 capture_opts->default_options.src_type = CAPTURE_IFLOCAL;
85 capture_opts->default_options.remote_host = NULL;
86 capture_opts->default_options.remote_port = NULL;
87 capture_opts->default_options.auth_type = CAPTURE_AUTH_NULL;
88 capture_opts->default_options.auth_username = NULL;
89 capture_opts->default_options.auth_password = NULL;
90 capture_opts->default_options.datatx_udp = FALSE;
91 capture_opts->default_options.nocap_rpcap = TRUE;
92 capture_opts->default_options.nocap_local = FALSE;
94 #ifdef HAVE_PCAP_SETSAMPLING
95 capture_opts->default_options.sampling_method = CAPTURE_SAMP_NONE;
96 capture_opts->default_options.sampling_param = 0;
98 capture_opts->default_options.timestamp_type = NULL;
99 capture_opts->saving_to_file = FALSE;
100 capture_opts->save_file = NULL;
101 capture_opts->group_read_access = FALSE;
102 #ifdef PCAP_NG_DEFAULT
103 capture_opts->use_pcapng = TRUE; /* Save as pcap-ng by default */
105 capture_opts->use_pcapng = FALSE; /* Save as pcap by default */
107 capture_opts->real_time_mode = TRUE;
108 capture_opts->show_info = TRUE;
109 capture_opts->restart = FALSE;
110 capture_opts->orig_save_file = NULL;
112 capture_opts->multi_files_on = FALSE;
113 capture_opts->has_file_duration = FALSE;
114 capture_opts->file_duration = 60; /* 1 min */
115 capture_opts->has_file_interval = FALSE;
116 capture_opts->file_interval = 60; /* 1 min */
117 capture_opts->has_ring_num_files = FALSE;
118 capture_opts->ring_num_files = RINGBUFFER_MIN_NUM_FILES;
120 capture_opts->has_autostop_files = FALSE;
121 capture_opts->autostop_files = 1;
122 capture_opts->has_autostop_packets = FALSE;
123 capture_opts->autostop_packets = 0;
124 capture_opts->has_autostop_filesize = FALSE;
125 capture_opts->autostop_filesize = 1000; /* 1 MB */
126 capture_opts->has_autostop_duration = FALSE;
127 capture_opts->autostop_duration = 60; /* 1 min */
128 capture_opts->capture_comment = NULL;
130 capture_opts->output_to_pipe = FALSE;
131 capture_opts->capture_child = FALSE;
135 capture_opts_cleanup(capture_options *capture_opts)
140 if (capture_opts->ifaces) {
141 g_array_free(capture_opts->ifaces, TRUE);
142 capture_opts->ifaces = NULL;
144 if (capture_opts->all_ifaces) {
145 g_array_free(capture_opts->all_ifaces, TRUE);
146 capture_opts->all_ifaces = NULL;
150 /* log content of capture_opts */
152 capture_opts_log(const char *log_domain, GLogLevelFlags log_level, capture_options *capture_opts) {
155 g_log(log_domain, log_level, "CAPTURE OPTIONS :");
157 for (i = 0; i < capture_opts->ifaces->len; i++) {
158 interface_options interface_opts;
160 interface_opts = g_array_index(capture_opts->ifaces, interface_options, i);
161 g_log(log_domain, log_level, "Interface name[%02d] : %s", i, interface_opts.name ? interface_opts.name : "(unspecified)");
162 g_log(log_domain, log_level, "Interface description[%02d] : %s", i, interface_opts.descr ? interface_opts.descr : "(unspecified)");
163 g_log(log_domain, log_level, "Console display name[%02d]: %s", i, interface_opts.console_display_name ? interface_opts.console_display_name : "(unspecified)");
164 g_log(log_domain, log_level, "Capture filter[%02d] : %s", i, interface_opts.cfilter ? interface_opts.cfilter : "(unspecified)");
165 g_log(log_domain, log_level, "Snap length[%02d] (%u) : %d", i, interface_opts.has_snaplen, interface_opts.snaplen);
166 g_log(log_domain, log_level, "Link Type[%02d] : %d", i, interface_opts.linktype);
167 g_log(log_domain, log_level, "Promiscuous Mode[%02d]: %s", i, interface_opts.promisc_mode?"TRUE":"FALSE");
169 g_log(log_domain, log_level, "Extcap[%02d] : %s", i, interface_opts.extcap ? interface_opts.extcap : "(unspecified)");
170 g_log(log_domain, log_level, "Extcap FIFO[%02d] : %s", i, interface_opts.extcap_fifo ? interface_opts.extcap_fifo : "(unspecified)");
171 g_log(log_domain, log_level, "Extcap PID[%02d] : %d", i, interface_opts.extcap_pid);
173 #ifdef CAN_SET_CAPTURE_BUFFER_SIZE
174 g_log(log_domain, log_level, "Buffer size[%02d] : %d (MB)", i, interface_opts.buffer_size);
176 g_log(log_domain, log_level, "Monitor Mode[%02d] : %s", i, interface_opts.monitor_mode?"TRUE":"FALSE");
177 #ifdef HAVE_PCAP_REMOTE
178 g_log(log_domain, log_level, "Capture source[%02d] : %s", i,
179 interface_opts.src_type == CAPTURE_IFLOCAL ? "Local interface" :
180 interface_opts.src_type == CAPTURE_IFREMOTE ? "Remote interface" :
182 if (interface_opts.src_type == CAPTURE_IFREMOTE) {
183 g_log(log_domain, log_level, "Remote host[%02d] : %s", i, interface_opts.remote_host ? interface_opts.remote_host : "(unspecified)");
184 g_log(log_domain, log_level, "Remote port[%02d] : %s", i, interface_opts.remote_port ? interface_opts.remote_port : "(unspecified)");
186 g_log(log_domain, log_level, "Authentication[%02d] : %s", i,
187 interface_opts.auth_type == CAPTURE_AUTH_NULL ? "Null" :
188 interface_opts.auth_type == CAPTURE_AUTH_PWD ? "By username/password" :
190 if (interface_opts.auth_type == CAPTURE_AUTH_PWD) {
191 g_log(log_domain, log_level, "Auth username[%02d] : %s", i, interface_opts.auth_username ? interface_opts.auth_username : "(unspecified)");
192 g_log(log_domain, log_level, "Auth password[%02d] : <hidden>", i);
194 g_log(log_domain, log_level, "UDP data tfer[%02d] : %u", i, interface_opts.datatx_udp);
195 g_log(log_domain, log_level, "No cap. RPCAP[%02d] : %u", i, interface_opts.nocap_rpcap);
196 g_log(log_domain, log_level, "No cap. local[%02d] : %u", i, interface_opts.nocap_local);
198 #ifdef HAVE_PCAP_SETSAMPLING
199 g_log(log_domain, log_level, "Sampling meth.[%02d] : %d", i, interface_opts.sampling_method);
200 g_log(log_domain, log_level, "Sampling param.[%02d] : %d", i, interface_opts.sampling_param);
202 g_log(log_domain, log_level, "Timestamp type [%02d] : %s", i, interface_opts.timestamp_type);
204 g_log(log_domain, log_level, "Interface name[df] : %s", capture_opts->default_options.name ? capture_opts->default_options.name : "(unspecified)");
205 g_log(log_domain, log_level, "Interface Descr[df] : %s", capture_opts->default_options.descr ? capture_opts->default_options.descr : "(unspecified)");
206 g_log(log_domain, log_level, "Capture filter[df] : %s", capture_opts->default_options.cfilter ? capture_opts->default_options.cfilter : "(unspecified)");
207 g_log(log_domain, log_level, "Snap length[df] (%u) : %d", capture_opts->default_options.has_snaplen, capture_opts->default_options.snaplen);
208 g_log(log_domain, log_level, "Link Type[df] : %d", capture_opts->default_options.linktype);
209 g_log(log_domain, log_level, "Promiscuous Mode[df]: %s", capture_opts->default_options.promisc_mode?"TRUE":"FALSE");
211 g_log(log_domain, log_level, "Extcap[df] : %s", capture_opts->default_options.extcap ? capture_opts->default_options.extcap : "(unspecified)");
212 g_log(log_domain, log_level, "Extcap FIFO[df] : %s", capture_opts->default_options.extcap_fifo ? capture_opts->default_options.extcap_fifo : "(unspecified)");
214 #ifdef CAN_SET_CAPTURE_BUFFER_SIZE
215 g_log(log_domain, log_level, "Buffer size[df] : %d (MB)", capture_opts->default_options.buffer_size);
217 g_log(log_domain, log_level, "Monitor Mode[df] : %s", capture_opts->default_options.monitor_mode?"TRUE":"FALSE");
218 #ifdef HAVE_PCAP_REMOTE
219 g_log(log_domain, log_level, "Capture source[df] : %s",
220 capture_opts->default_options.src_type == CAPTURE_IFLOCAL ? "Local interface" :
221 capture_opts->default_options.src_type == CAPTURE_IFREMOTE ? "Remote interface" :
223 if (capture_opts->default_options.src_type == CAPTURE_IFREMOTE) {
224 g_log(log_domain, log_level, "Remote host[df] : %s", capture_opts->default_options.remote_host ? capture_opts->default_options.remote_host : "(unspecified)");
225 g_log(log_domain, log_level, "Remote port[df] : %s", capture_opts->default_options.remote_port ? capture_opts->default_options.remote_port : "(unspecified)");
227 g_log(log_domain, log_level, "Authentication[df] : %s",
228 capture_opts->default_options.auth_type == CAPTURE_AUTH_NULL ? "Null" :
229 capture_opts->default_options.auth_type == CAPTURE_AUTH_PWD ? "By username/password" :
231 if (capture_opts->default_options.auth_type == CAPTURE_AUTH_PWD) {
232 g_log(log_domain, log_level, "Auth username[df] : %s", capture_opts->default_options.auth_username ? capture_opts->default_options.auth_username : "(unspecified)");
233 g_log(log_domain, log_level, "Auth password[df] : <hidden>");
235 g_log(log_domain, log_level, "UDP data tfer[df] : %u", capture_opts->default_options.datatx_udp);
236 g_log(log_domain, log_level, "No cap. RPCAP[df] : %u", capture_opts->default_options.nocap_rpcap);
237 g_log(log_domain, log_level, "No cap. local[df] : %u", capture_opts->default_options.nocap_local);
239 #ifdef HAVE_PCAP_SETSAMPLING
240 g_log(log_domain, log_level, "Sampling meth. [df] : %d", capture_opts->default_options.sampling_method);
241 g_log(log_domain, log_level, "Sampling param.[df] : %d", capture_opts->default_options.sampling_param);
243 g_log(log_domain, log_level, "Timestamp type [df] : %s", capture_opts->default_options.timestamp_type ? capture_opts->default_options.timestamp_type : "(unspecified)");
244 g_log(log_domain, log_level, "SavingToFile : %u", capture_opts->saving_to_file);
245 g_log(log_domain, log_level, "SaveFile : %s", (capture_opts->save_file) ? capture_opts->save_file : "");
246 g_log(log_domain, log_level, "GroupReadAccess : %u", capture_opts->group_read_access);
247 g_log(log_domain, log_level, "Fileformat : %s", (capture_opts->use_pcapng) ? "PCAPNG" : "PCAP");
248 g_log(log_domain, log_level, "RealTimeMode : %u", capture_opts->real_time_mode);
249 g_log(log_domain, log_level, "ShowInfo : %u", capture_opts->show_info);
251 g_log(log_domain, log_level, "MultiFilesOn : %u", capture_opts->multi_files_on);
252 g_log(log_domain, log_level, "FileDuration (%u) : %u", capture_opts->has_file_duration, capture_opts->file_duration);
253 g_log(log_domain, log_level, "FileInterval (%u) : %u", capture_opts->has_file_interval, capture_opts->file_interval);
254 g_log(log_domain, log_level, "RingNumFiles (%u) : %u", capture_opts->has_ring_num_files, capture_opts->ring_num_files);
256 g_log(log_domain, log_level, "AutostopFiles (%u) : %u", capture_opts->has_autostop_files, capture_opts->autostop_files);
257 g_log(log_domain, log_level, "AutostopPackets (%u) : %u", capture_opts->has_autostop_packets, capture_opts->autostop_packets);
258 g_log(log_domain, log_level, "AutostopFilesize(%u) : %u (KB)", capture_opts->has_autostop_filesize, capture_opts->autostop_filesize);
259 g_log(log_domain, log_level, "AutostopDuration(%u) : %u", capture_opts->has_autostop_duration, capture_opts->autostop_duration);
263 * Given a string of the form "<autostop criterion>:<value>", as might appear
264 * as an argument to a "-a" option, parse it and set the criterion in
265 * question. Return an indication of whether it succeeded or failed
269 set_autostop_criterion(capture_options *capture_opts, const char *autostoparg)
273 colonp = strchr(autostoparg, ':');
281 * Skip over any white space (there probably won't be any, but
282 * as we allow it in the preferences file, we might as well
285 while (g_ascii_isspace(*p))
289 * Put the colon back, so if our caller uses, in an
290 * error message, the string they passed us, the message
296 if (strcmp(autostoparg,"duration") == 0) {
297 capture_opts->has_autostop_duration = TRUE;
298 capture_opts->autostop_duration = get_positive_int(p,"autostop duration");
299 } else if (strcmp(autostoparg,"filesize") == 0) {
300 capture_opts->has_autostop_filesize = TRUE;
301 capture_opts->autostop_filesize = get_nonzero_guint32(p,"autostop filesize");
302 } else if (strcmp(autostoparg,"files") == 0) {
303 capture_opts->multi_files_on = TRUE;
304 capture_opts->has_autostop_files = TRUE;
305 capture_opts->autostop_files = get_positive_int(p,"autostop files");
309 *colonp = ':'; /* put the colon back */
313 static gboolean get_filter_arguments(capture_options* capture_opts, const char* arg)
317 char* filter_exp = NULL;
319 colonp = strchr(arg, ':');
324 if (strcmp(arg, "predef") == 0) {
327 filterItem = get_filter_list_first(CFILTER_LIST);
328 while (filterItem != NULL) {
329 filter_def *filterDef;
331 filterDef = (filter_def*)filterItem->data;
332 if (strcmp(val, filterDef->name) == 0) {
333 filter_exp = g_strdup(filterDef->strval);
336 filterItem = filterItem->next;
341 if (filter_exp == NULL) {
342 /* No filter expression found yet; fallback to previous implemention
343 and assume the arg contains a filter expression */
345 *colonp = ':'; /* restore colon */
347 filter_exp = g_strdup(arg);
350 if (capture_opts->ifaces->len > 0) {
351 interface_options interface_opts;
353 interface_opts = g_array_index(capture_opts->ifaces, interface_options, capture_opts->ifaces->len - 1);
354 capture_opts->ifaces = g_array_remove_index(capture_opts->ifaces, capture_opts->ifaces->len - 1);
355 g_free(interface_opts.cfilter);
356 interface_opts.cfilter = filter_exp;
357 g_array_append_val(capture_opts->ifaces, interface_opts);
361 g_free(capture_opts->default_options.cfilter);
362 capture_opts->default_options.cfilter = filter_exp;
368 * Given a string of the form "<ring buffer file>:<duration>", as might appear
369 * as an argument to a "-b" option, parse it and set the arguments in
370 * question. Return an indication of whether it succeeded or failed
374 get_ring_arguments(capture_options *capture_opts, const char *arg)
376 gchar *p = NULL, *colonp;
378 colonp = strchr(arg, ':');
386 * Skip over any white space (there probably won't be any, but
387 * as we allow it in the preferences file, we might as well
390 while (g_ascii_isspace(*p))
394 * Put the colon back, so if our caller uses, in an
395 * error message, the string they passed us, the message
402 if (strcmp(arg,"files") == 0) {
403 capture_opts->has_ring_num_files = TRUE;
404 capture_opts->ring_num_files = get_nonzero_guint32(p, "number of ring buffer files");
405 } else if (strcmp(arg,"filesize") == 0) {
406 capture_opts->has_autostop_filesize = TRUE;
407 capture_opts->autostop_filesize = get_nonzero_guint32(p, "ring buffer filesize");
408 } else if (strcmp(arg,"duration") == 0) {
409 capture_opts->has_file_duration = TRUE;
410 capture_opts->file_duration = get_positive_int(p, "ring buffer duration");
411 } else if (strcmp(arg,"interval") == 0) {
412 capture_opts->has_file_interval = TRUE;
413 capture_opts->file_interval = get_positive_int(p, "ring buffer interval");
416 *colonp = ':'; /* put the colon back */
420 #ifdef HAVE_PCAP_SETSAMPLING
422 * Given a string of the form "<sampling type>:<value>", as might appear
423 * as an argument to a "-m" option, parse it and set the arguments in
424 * question. Return an indication of whether it succeeded or failed
428 get_sampling_arguments(capture_options *capture_opts, const char *arg)
430 gchar *p = NULL, *colonp;
432 colonp = strchr(arg, ':');
439 while (g_ascii_isspace(*p))
446 if (strcmp(arg, "count") == 0) {
447 if (capture_opts->ifaces->len > 0) {
448 interface_options interface_opts;
450 interface_opts = g_array_index(capture_opts->ifaces, interface_options, capture_opts->ifaces->len - 1);
451 capture_opts->ifaces = g_array_remove_index(capture_opts->ifaces, capture_opts->ifaces->len - 1);
452 interface_opts.sampling_method = CAPTURE_SAMP_BY_COUNT;
453 interface_opts.sampling_param = get_positive_int(p, "sampling count");
454 g_array_append_val(capture_opts->ifaces, interface_opts);
456 capture_opts->default_options.sampling_method = CAPTURE_SAMP_BY_COUNT;
457 capture_opts->default_options.sampling_param = get_positive_int(p, "sampling count");
459 } else if (strcmp(arg, "timer") == 0) {
460 if (capture_opts->ifaces->len > 0) {
461 interface_options interface_opts;
463 interface_opts = g_array_index(capture_opts->ifaces, interface_options, capture_opts->ifaces->len - 1);
464 capture_opts->ifaces = g_array_remove_index(capture_opts->ifaces, capture_opts->ifaces->len - 1);
465 interface_opts.sampling_method = CAPTURE_SAMP_BY_TIMER;
466 interface_opts.sampling_param = get_positive_int(p, "sampling timer");
467 g_array_append_val(capture_opts->ifaces, interface_opts);
469 capture_opts->default_options.sampling_method = CAPTURE_SAMP_BY_TIMER;
470 capture_opts->default_options.sampling_param = get_positive_int(p, "sampling timer");
478 #ifdef HAVE_PCAP_REMOTE
480 * Given a string of the form "<username>:<password>", as might appear
481 * as an argument to a "-A" option, parse it and set the arguments in
482 * question. Return an indication of whether it succeeded or failed
486 get_auth_arguments(capture_options *capture_opts, const char *arg)
488 gchar *p = NULL, *colonp;
490 colonp = strchr(arg, ':');
497 while (g_ascii_isspace(*p))
500 if (capture_opts->ifaces->len > 0) {
501 interface_options interface_opts;
503 interface_opts = g_array_index(capture_opts->ifaces, interface_options, capture_opts->ifaces->len - 1);
504 capture_opts->ifaces = g_array_remove_index(capture_opts->ifaces, capture_opts->ifaces->len - 1);
505 interface_opts.auth_type = CAPTURE_AUTH_PWD;
506 interface_opts.auth_username = g_strdup(arg);
507 interface_opts.auth_password = g_strdup(p);
508 g_array_append_val(capture_opts->ifaces, interface_opts);
510 capture_opts->default_options.auth_type = CAPTURE_AUTH_PWD;
511 capture_opts->default_options.auth_username = g_strdup(arg);
512 capture_opts->default_options.auth_password = g_strdup(p);
520 capture_opts_add_iface_opt(capture_options *capture_opts, const char *optarg_str_p)
528 interface_options interface_opts;
531 * If the argument is a number, treat it as an index into the list
532 * of adapters, as printed by "tshark -D".
534 * This should be OK on UNIX systems, as interfaces shouldn't have
535 * names that begin with digits. It can be useful on Windows, where
536 * more than one interface can have the same name.
538 adapter_index = strtol(optarg_str_p, &p, 10);
539 if (p != NULL && *p == '\0') {
540 if (adapter_index < 0) {
541 cmdarg_err("The specified adapter index is a negative number");
544 if (adapter_index > INT_MAX) {
545 cmdarg_err("The specified adapter index is too large (greater than %d)",
549 if (adapter_index == 0) {
550 cmdarg_err("There is no interface with that adapter index");
553 if_list = capture_interface_list(&err, &err_str, NULL);
554 if (if_list == NULL) {
556 cmdarg_err("There are no interfaces on which a capture can be done");
558 cmdarg_err("%s", err_str);
563 if_info = (if_info_t *)g_list_nth_data(if_list, (int)(adapter_index - 1));
564 if (if_info == NULL) {
565 cmdarg_err("There is no interface with that adapter index");
568 interface_opts.name = g_strdup(if_info->name);
569 if (if_info->friendly_name != NULL) {
571 * We have a friendly name for the interface, so display that
572 * instead of the interface name/guid.
574 * XXX - on UN*X, the interface name is not quite so ugly,
575 * and might be more familiar to users; display them both?
577 interface_opts.console_display_name = g_strdup(if_info->friendly_name);
579 /* fallback to the interface name */
580 interface_opts.console_display_name = g_strdup(if_info->name);
582 interface_opts.if_type = if_info->type;
584 interface_opts.extcap = g_strdup(if_info->extcap);
586 free_interface_list(if_list);
587 } else if (capture_opts->capture_child) {
588 /* In Wireshark capture child mode, thus proper device name is supplied. */
589 /* No need for trying to match it for friendly names. */
590 interface_opts.name = g_strdup(optarg_str_p);
591 interface_opts.console_display_name = g_strdup(optarg_str_p);
592 interface_opts.if_type = capture_opts->default_options.if_type;
594 interface_opts.extcap = g_strdup(capture_opts->default_options.extcap);
598 * Retrieve the interface list so that we can search for the
599 * specified option amongst both the interface names and the
600 * friendly names and so that we find the friendly name even
601 * if an interface name was specified.
603 * If we can't get the list, just use the specified option as
604 * the interface name, so that the user can try specifying an
605 * interface explicitly for testing purposes.
607 if_list = capture_interface_list(&err, NULL, NULL);
608 if (if_list != NULL) {
609 /* try and do an exact match (case insensitive) */
614 for (if_entry = g_list_first(if_list); if_entry != NULL;
615 if_entry = g_list_next(if_entry))
617 if_info = (if_info_t *)if_entry->data;
618 /* exact name check */
619 if (g_ascii_strcasecmp(if_info->name, optarg_str_p) == 0) {
620 /* exact match on the interface name, use that for displaying etc */
621 interface_opts.name = g_strdup(if_info->name);
623 if (if_info->friendly_name != NULL) {
625 * If we have a friendly name, use that for the
626 * console display name, as it is the basis for
627 * the auto generated temp filename.
629 interface_opts.console_display_name = g_strdup(if_info->friendly_name);
631 interface_opts.console_display_name = g_strdup(if_info->name);
633 interface_opts.if_type = if_info->type;
635 interface_opts.extcap = g_strdup(if_info->extcap);
641 /* exact friendly name check */
642 if (if_info->friendly_name != NULL &&
643 g_ascii_strcasecmp(if_info->friendly_name, optarg_str_p) == 0) {
644 /* exact match - use the friendly name for display */
645 interface_opts.name = g_strdup(if_info->name);
646 interface_opts.console_display_name = g_strdup(if_info->friendly_name);
647 interface_opts.if_type = if_info->type;
649 interface_opts.extcap = g_strdup(if_info->extcap);
656 /* didn't find, attempt a case insensitive prefix match of the friendly name*/
658 size_t prefix_length;
660 prefix_length = strlen(optarg_str_p);
661 for (if_entry = g_list_first(if_list); if_entry != NULL;
662 if_entry = g_list_next(if_entry))
664 if_info = (if_info_t *)if_entry->data;
666 if (if_info->friendly_name != NULL &&
667 g_ascii_strncasecmp(if_info->friendly_name, optarg_str_p, prefix_length) == 0) {
668 /* prefix match - use the friendly name for display */
669 interface_opts.name = g_strdup(if_info->name);
670 interface_opts.console_display_name = g_strdup(if_info->friendly_name);
671 interface_opts.if_type = if_info->type;
673 interface_opts.extcap = g_strdup(if_info->extcap);
682 * We didn't find the interface in the list; just use
683 * the specified name, so that, for example, if an
684 * interface doesn't show up in the list for some
685 * reason, the user can try specifying it explicitly
686 * for testing purposes.
688 interface_opts.name = g_strdup(optarg_str_p);
689 interface_opts.console_display_name = g_strdup(optarg_str_p);
690 interface_opts.if_type = capture_opts->default_options.if_type;
692 interface_opts.extcap = g_strdup(capture_opts->default_options.extcap);
695 free_interface_list(if_list);
697 interface_opts.name = g_strdup(optarg_str_p);
698 interface_opts.console_display_name = g_strdup(optarg_str_p);
699 interface_opts.if_type = capture_opts->default_options.if_type;
701 interface_opts.extcap = g_strdup(capture_opts->default_options.extcap);
706 /* We don't set iface_descr here because doing so requires
707 * capture_ui_utils.c which requires epan/prefs.c which is
708 * probably a bit too much dependency for here...
710 interface_opts.descr = g_strdup(capture_opts->default_options.descr);
711 interface_opts.cfilter = g_strdup(capture_opts->default_options.cfilter);
712 interface_opts.snaplen = capture_opts->default_options.snaplen;
713 interface_opts.has_snaplen = capture_opts->default_options.has_snaplen;
714 interface_opts.linktype = capture_opts->default_options.linktype;
715 interface_opts.promisc_mode = capture_opts->default_options.promisc_mode;
717 interface_opts.extcap_fifo = g_strdup(capture_opts->default_options.extcap_fifo);
718 interface_opts.extcap_args = NULL;
719 interface_opts.extcap_pid = INVALID_EXTCAP_PID;
720 interface_opts.extcap_userdata = NULL;
722 interface_opts.extcap_pipe_h = INVALID_HANDLE_VALUE;
723 interface_opts.extcap_control_in_h = INVALID_HANDLE_VALUE;
724 interface_opts.extcap_control_out_h = INVALID_HANDLE_VALUE;
726 interface_opts.extcap_control_in = g_strdup(capture_opts->default_options.extcap_control_in);
727 interface_opts.extcap_control_out = g_strdup(capture_opts->default_options.extcap_control_out);
729 #ifdef CAN_SET_CAPTURE_BUFFER_SIZE
730 interface_opts.buffer_size = capture_opts->default_options.buffer_size;
732 interface_opts.monitor_mode = capture_opts->default_options.monitor_mode;
733 #ifdef HAVE_PCAP_REMOTE
734 interface_opts.src_type = capture_opts->default_options.src_type;
735 interface_opts.remote_host = g_strdup(capture_opts->default_options.remote_host);
736 interface_opts.remote_port = g_strdup(capture_opts->default_options.remote_port);
737 interface_opts.auth_type = capture_opts->default_options.auth_type;
738 interface_opts.auth_username = g_strdup(capture_opts->default_options.auth_username);
739 interface_opts.auth_password = g_strdup(capture_opts->default_options.auth_password);
740 interface_opts.datatx_udp = capture_opts->default_options.datatx_udp;
741 interface_opts.nocap_rpcap = capture_opts->default_options.nocap_rpcap;
742 interface_opts.nocap_local = capture_opts->default_options.nocap_local;
744 #ifdef HAVE_PCAP_SETSAMPLING
745 interface_opts.sampling_method = capture_opts->default_options.sampling_method;
746 interface_opts.sampling_param = capture_opts->default_options.sampling_param;
748 interface_opts.timestamp_type = capture_opts->default_options.timestamp_type;
750 g_array_append_val(capture_opts->ifaces, interface_opts);
757 capture_opts_add_opt(capture_options *capture_opts, int opt, const char *optarg_str_p, gboolean *start_capture)
762 case LONGOPT_NUM_CAP_COMMENT: /* capture comment */
763 if (capture_opts->capture_comment) {
764 cmdarg_err("--capture-comment can be set only once per file");
767 capture_opts->capture_comment = g_strdup(optarg_str_p);
769 case 'a': /* autostop criteria */
770 if (set_autostop_criterion(capture_opts, optarg_str_p) == FALSE) {
771 cmdarg_err("Invalid or unknown -a flag \"%s\"", optarg_str_p);
775 #ifdef HAVE_PCAP_REMOTE
777 if (get_auth_arguments(capture_opts, optarg_str_p) == FALSE) {
778 cmdarg_err("Invalid or unknown -A arg \"%s\"", optarg_str_p);
783 case 'b': /* Ringbuffer option */
784 capture_opts->multi_files_on = TRUE;
785 if (get_ring_arguments(capture_opts, optarg_str_p) == FALSE) {
786 cmdarg_err("Invalid or unknown -b arg \"%s\"", optarg_str_p);
790 #ifdef CAN_SET_CAPTURE_BUFFER_SIZE
791 case 'B': /* Buffer size */
792 if (capture_opts->ifaces->len > 0) {
793 interface_options interface_opts;
795 interface_opts = g_array_index(capture_opts->ifaces, interface_options, capture_opts->ifaces->len - 1);
796 capture_opts->ifaces = g_array_remove_index(capture_opts->ifaces, capture_opts->ifaces->len - 1);
797 interface_opts.buffer_size = get_positive_int(optarg_str_p, "buffer size");
798 g_array_append_val(capture_opts->ifaces, interface_opts);
800 capture_opts->default_options.buffer_size = get_positive_int(optarg_str_p, "buffer size");
804 case 'c': /* Capture n packets */
805 capture_opts->has_autostop_packets = TRUE;
806 capture_opts->autostop_packets = get_positive_int(optarg_str_p, "packet count");
808 case 'f': /* capture filter */
809 get_filter_arguments(capture_opts, optarg_str_p);
811 case 'g': /* enable group read access on the capture file(s) */
812 capture_opts->group_read_access = TRUE;
814 case 'H': /* Hide capture info dialog box */
815 capture_opts->show_info = FALSE;
817 case LONGOPT_SET_TSTAMP_TYPE: /* Set capture time stamp type */
818 if (capture_opts->ifaces->len > 0) {
819 interface_options interface_opts;
821 interface_opts = g_array_index(capture_opts->ifaces, interface_options, capture_opts->ifaces->len - 1);
822 capture_opts->ifaces = g_array_remove_index(capture_opts->ifaces, capture_opts->ifaces->len - 1);
823 g_free(interface_opts.timestamp_type);
824 interface_opts.timestamp_type = g_strdup(optarg_str_p);
825 g_array_append_val(capture_opts->ifaces, interface_opts);
827 g_free(capture_opts->default_options.timestamp_type);
828 capture_opts->default_options.timestamp_type = g_strdup(optarg_str_p);
831 case 'i': /* Use interface x */
832 status = capture_opts_add_iface_opt(capture_opts, optarg_str_p);
837 #ifdef HAVE_PCAP_CREATE
838 case 'I': /* Capture in monitor mode */
839 if (capture_opts->ifaces->len > 0) {
840 interface_options interface_opts;
842 interface_opts = g_array_index(capture_opts->ifaces, interface_options, capture_opts->ifaces->len - 1);
843 capture_opts->ifaces = g_array_remove_index(capture_opts->ifaces, capture_opts->ifaces->len - 1);
844 interface_opts.monitor_mode = TRUE;
845 g_array_append_val(capture_opts->ifaces, interface_opts);
847 capture_opts->default_options.monitor_mode = TRUE;
851 case 'k': /* Start capture immediately */
852 *start_capture = TRUE;
854 /*case 'l':*/ /* Automatic scrolling in live capture mode */
855 #ifdef HAVE_PCAP_SETSAMPLING
857 if (get_sampling_arguments(capture_opts, optarg_str_p) == FALSE) {
858 cmdarg_err("Invalid or unknown -m arg \"%s\"", optarg_str_p);
863 case 'n': /* Use pcapng format */
864 capture_opts->use_pcapng = TRUE;
866 case 'p': /* Don't capture in promiscuous mode */
867 if (capture_opts->ifaces->len > 0) {
868 interface_options interface_opts;
870 interface_opts = g_array_index(capture_opts->ifaces, interface_options, capture_opts->ifaces->len - 1);
871 capture_opts->ifaces = g_array_remove_index(capture_opts->ifaces, capture_opts->ifaces->len - 1);
872 interface_opts.promisc_mode = FALSE;
873 g_array_append_val(capture_opts->ifaces, interface_opts);
875 capture_opts->default_options.promisc_mode = FALSE;
878 case 'P': /* Use pcap format */
879 capture_opts->use_pcapng = FALSE;
881 #ifdef HAVE_PCAP_REMOTE
883 if (capture_opts->ifaces->len > 0) {
884 interface_options interface_opts;
886 interface_opts = g_array_index(capture_opts->ifaces, interface_options, capture_opts->ifaces->len - 1);
887 capture_opts->ifaces = g_array_remove_index(capture_opts->ifaces, capture_opts->ifaces->len - 1);
888 interface_opts.nocap_rpcap = FALSE;
889 g_array_append_val(capture_opts->ifaces, interface_opts);
891 capture_opts->default_options.nocap_rpcap = FALSE;
895 case 's': /* Set the snapshot (capture) length */
896 snaplen = get_natural_int(optarg_str_p, "snapshot length");
898 * Make a snapshot length of 0 equivalent to the maximum packet
899 * length, mirroring what tcpdump does.
902 snaplen = WTAP_MAX_PACKET_SIZE_STANDARD;
903 if (capture_opts->ifaces->len > 0) {
904 interface_options interface_opts;
906 interface_opts = g_array_index(capture_opts->ifaces, interface_options, capture_opts->ifaces->len - 1);
907 capture_opts->ifaces = g_array_remove_index(capture_opts->ifaces, capture_opts->ifaces->len - 1);
908 interface_opts.has_snaplen = TRUE;
909 interface_opts.snaplen = snaplen;
910 g_array_append_val(capture_opts->ifaces, interface_opts);
912 capture_opts->default_options.snaplen = snaplen;
913 capture_opts->default_options.has_snaplen = TRUE;
916 case 'S': /* "Real-Time" mode: used for following file ala tail -f */
917 capture_opts->real_time_mode = TRUE;
919 #ifdef HAVE_PCAP_REMOTE
921 if (capture_opts->ifaces->len > 0) {
922 interface_options interface_opts;
924 interface_opts = g_array_index(capture_opts->ifaces, interface_options, capture_opts->ifaces->len - 1);
925 capture_opts->ifaces = g_array_remove_index(capture_opts->ifaces, capture_opts->ifaces->len - 1);
926 interface_opts.datatx_udp = TRUE;
927 g_array_append_val(capture_opts->ifaces, interface_opts);
929 capture_opts->default_options.datatx_udp = TRUE;
933 case 'w': /* Write to capture file x */
934 capture_opts->saving_to_file = TRUE;
935 g_free(capture_opts->save_file);
936 capture_opts->save_file = g_strdup(optarg_str_p);
937 status = capture_opts_output_to_pipe(capture_opts->save_file, &capture_opts->output_to_pipe);
939 case 'y': /* Set the pcap data link type */
940 if (capture_opts->ifaces->len > 0) {
941 interface_options interface_opts;
943 interface_opts = g_array_index(capture_opts->ifaces, interface_options, capture_opts->ifaces->len - 1);
944 capture_opts->ifaces = g_array_remove_index(capture_opts->ifaces, capture_opts->ifaces->len - 1);
945 interface_opts.linktype = linktype_name_to_val(optarg_str_p);
946 if (interface_opts.linktype == -1) {
947 cmdarg_err("The specified data link type \"%s\" isn't valid",
951 g_array_append_val(capture_opts->ifaces, interface_opts);
953 capture_opts->default_options.linktype = linktype_name_to_val(optarg_str_p);
954 if (capture_opts->default_options.linktype == -1) {
955 cmdarg_err("The specified data link type \"%s\" isn't valid",
962 /* the caller is responsible to send us only the right opt's */
963 g_assert_not_reached();
970 capture_opts_print_if_capabilities(if_capabilities_t *caps, char *name, int queries)
972 GList *lt_entry, *ts_entry;
974 if (queries & CAPS_QUERY_LINK_TYPES) {
975 if (caps->can_set_rfmon)
976 printf("Data link types of interface %s when %sin monitor mode (use option -y to set):\n",
977 name, queries & CAPS_MONITOR_MODE ? "" : "not ");
979 printf("Data link types of interface %s (use option -y to set):\n", name);
980 for (lt_entry = caps->data_link_types; lt_entry != NULL;
981 lt_entry = g_list_next(lt_entry)) {
982 data_link_info_t *data_link_info = (data_link_info_t *)lt_entry->data;
983 printf(" %s", data_link_info->name);
984 if (data_link_info->description != NULL)
985 printf(" (%s)", data_link_info->description);
987 printf(" (not supported)");
992 if (queries & CAPS_QUERY_TIMESTAMP_TYPES) {
993 printf("Timestamp types of the interface (use option --time-stamp-type to set):\n");
994 for (ts_entry = caps->timestamp_types; ts_entry != NULL;
995 ts_entry = g_list_next(ts_entry)) {
996 timestamp_info_t *timestamp = (timestamp_info_t *)ts_entry->data;
997 printf(" %s", timestamp->name);
998 if (timestamp->description != NULL)
999 printf(" (%s)", timestamp->description);
1007 /* Print an ASCII-formatted list of interfaces. */
1009 capture_opts_print_interfaces(GList *if_list)
1015 i = 1; /* Interface id number */
1016 for (if_entry = g_list_first(if_list); if_entry != NULL;
1017 if_entry = g_list_next(if_entry)) {
1018 if_info = (if_info_t *)if_entry->data;
1019 printf("%d. %s", i++, if_info->name);
1021 /* Print the interface friendly name, if it exists;
1022 if not fall back to vendor description, if it exists. */
1023 if (if_info->friendly_name != NULL){
1024 printf(" (%s)", if_info->friendly_name);
1026 if (if_info->vendor_description != NULL)
1027 printf(" (%s)", if_info->vendor_description);
1035 capture_opts_trim_snaplen(capture_options *capture_opts, int snaplen_min)
1038 interface_options interface_opts;
1040 if (capture_opts->ifaces->len > 0) {
1041 for (i = 0; i < capture_opts->ifaces->len; i++) {
1042 interface_opts = g_array_index(capture_opts->ifaces, interface_options, 0);
1043 capture_opts->ifaces = g_array_remove_index(capture_opts->ifaces, 0);
1044 if (interface_opts.snaplen < 1)
1045 interface_opts.snaplen = WTAP_MAX_PACKET_SIZE_STANDARD;
1046 else if (interface_opts.snaplen < snaplen_min)
1047 interface_opts.snaplen = snaplen_min;
1048 g_array_append_val(capture_opts->ifaces, interface_opts);
1051 if (capture_opts->default_options.snaplen < 1)
1052 capture_opts->default_options.snaplen = WTAP_MAX_PACKET_SIZE_STANDARD;
1053 else if (capture_opts->default_options.snaplen < snaplen_min)
1054 capture_opts->default_options.snaplen = snaplen_min;
1060 capture_opts_trim_ring_num_files(capture_options *capture_opts)
1062 /* Check the value range of the ring_num_files parameter */
1063 if (capture_opts->ring_num_files > RINGBUFFER_MAX_NUM_FILES) {
1064 cmdarg_err("Too many ring buffer files (%u). Reducing to %u.\n", capture_opts->ring_num_files, RINGBUFFER_MAX_NUM_FILES);
1065 capture_opts->ring_num_files = RINGBUFFER_MAX_NUM_FILES;
1066 } else if (capture_opts->ring_num_files > RINGBUFFER_WARN_NUM_FILES) {
1067 cmdarg_err("%u is a lot of ring buffer files.\n", capture_opts->ring_num_files);
1069 #if RINGBUFFER_MIN_NUM_FILES > 0
1070 else if (capture_opts->ring_num_files < RINGBUFFER_MIN_NUM_FILES)
1071 cmdarg_err("Too few ring buffer files (%u). Increasing to %u.\n", capture_opts->ring_num_files, RINGBUFFER_MIN_NUM_FILES);
1072 capture_opts->ring_num_files = RINGBUFFER_MIN_NUM_FILES;
1077 * If no interface was specified explicitly, pick a default.
1080 capture_opts_default_iface_if_necessary(capture_options *capture_opts,
1081 const char *capture_device)
1085 /* Did the user specify an interface to use? */
1086 if (capture_opts->num_selected != 0 || capture_opts->ifaces->len != 0) {
1087 /* yes they did, return immediately - nothing further to do here */
1091 /* No - is a default specified in the preferences file? */
1092 if (capture_device != NULL) {
1094 status = capture_opts_add_iface_opt(capture_opts, capture_device);
1097 /* No default in preferences file, just pick the first interface from the list of interfaces. */
1098 return capture_opts_add_iface_opt(capture_opts, "1");
1102 #define S_IFIFO _S_IFIFO
1105 #define S_ISFIFO(mode) (((mode) & S_IFMT) == S_IFIFO)
1108 /* copied from filesystem.c */
1110 capture_opts_test_for_fifo(const char *path)
1114 if (ws_stat64(path, &statb) < 0)
1117 if (S_ISFIFO(statb.st_mode))
1124 capture_opts_output_to_pipe(const char *save_file, gboolean *is_pipe)
1130 if (save_file != NULL) {
1131 /* We're writing to a capture file. */
1132 if (strcmp(save_file, "-") == 0) {
1133 /* Writing to stdout. */
1134 /* XXX - should we check whether it's a pipe? It's arguably
1135 silly to do "-w - >output_file" rather than "-w output_file",
1136 but by not checking we might be violating the Principle Of
1137 Least Astonishment. */
1140 /* not writing to stdout, test for a FIFO (aka named pipe) */
1141 err = capture_opts_test_for_fifo(save_file);
1144 case ENOENT: /* it doesn't exist, so we'll be creating it,
1145 and it won't be a FIFO */
1146 case 0: /* found it, but it's not a FIFO */
1149 case ESPIPE: /* it is a FIFO */
1153 default: /* couldn't stat it */
1154 break; /* ignore: later attempt to open */
1155 /* will generate a nice msg */
1164 capture_opts_del_iface(capture_options *capture_opts, guint if_index)
1166 interface_options interface_opts;
1168 interface_opts = g_array_index(capture_opts->ifaces, interface_options, if_index);
1169 /* XXX - check if found? */
1171 g_free(interface_opts.name);
1172 g_free(interface_opts.descr);
1173 if (interface_opts.console_display_name != NULL)
1174 g_free(interface_opts.console_display_name);
1175 g_free(interface_opts.cfilter);
1176 g_free(interface_opts.timestamp_type);
1178 g_free(interface_opts.extcap);
1179 g_free(interface_opts.extcap_fifo);
1180 if (interface_opts.extcap_args)
1181 g_hash_table_unref(interface_opts.extcap_args);
1182 if (interface_opts.extcap_pid != INVALID_EXTCAP_PID)
1183 g_spawn_close_pid(interface_opts.extcap_pid);
1184 g_free(interface_opts.extcap_userdata);
1185 g_free(interface_opts.extcap_control_in);
1186 g_free(interface_opts.extcap_control_out);
1188 #ifdef HAVE_PCAP_REMOTE
1189 if (interface_opts.src_type == CAPTURE_IFREMOTE) {
1190 g_free(interface_opts.remote_host);
1191 g_free(interface_opts.remote_port);
1192 g_free(interface_opts.auth_username);
1193 g_free(interface_opts.auth_password);
1196 capture_opts->ifaces = g_array_remove_index(capture_opts->ifaces, if_index);
1202 * Add all non-hidden selected interfaces in the "all interfaces" list
1203 * to the list of interfaces for the capture.
1206 collect_ifaces(capture_options *capture_opts)
1210 interface_options interface_opts;
1212 /* Empty out the existing list of interfaces. */
1213 for (i = capture_opts->ifaces->len; i != 0; i--)
1214 capture_opts_del_iface(capture_opts, i-1);
1216 /* Now fill the list up again. */
1217 for (i = 0; i < capture_opts->all_ifaces->len; i++) {
1218 device = g_array_index(capture_opts->all_ifaces, interface_t, i);
1219 if (!device.hidden && device.selected) {
1220 interface_opts.name = g_strdup(device.name);
1221 interface_opts.descr = g_strdup(device.display_name);
1222 interface_opts.console_display_name = g_strdup(device.name);
1223 interface_opts.linktype = device.active_dlt;
1224 interface_opts.cfilter = g_strdup(device.cfilter);
1225 interface_opts.timestamp_type = g_strdup(device.timestamp_type);
1226 interface_opts.snaplen = device.snaplen;
1227 interface_opts.has_snaplen = device.has_snaplen;
1228 interface_opts.promisc_mode = device.pmode;
1229 interface_opts.if_type = device.if_info.type;
1231 interface_opts.extcap = g_strdup(device.if_info.extcap);
1232 interface_opts.extcap_fifo = NULL;
1233 interface_opts.extcap_userdata = NULL;
1234 interface_opts.extcap_args = device.external_cap_args_settings;
1235 interface_opts.extcap_pid = INVALID_EXTCAP_PID;
1236 if (interface_opts.extcap_args)
1237 g_hash_table_ref(interface_opts.extcap_args);
1238 interface_opts.extcap_userdata = NULL;
1240 interface_opts.extcap_pipe_h = INVALID_HANDLE_VALUE;
1241 interface_opts.extcap_control_in_h = INVALID_HANDLE_VALUE;
1242 interface_opts.extcap_control_out_h = INVALID_HANDLE_VALUE;
1244 interface_opts.extcap_control_in = NULL;
1245 interface_opts.extcap_control_out = NULL;
1247 #ifdef CAN_SET_CAPTURE_BUFFER_SIZE
1248 interface_opts.buffer_size = device.buffer;
1250 #ifdef HAVE_PCAP_CREATE
1251 interface_opts.monitor_mode = device.monitor_mode_enabled;
1253 #ifdef HAVE_PCAP_REMOTE
1254 interface_opts.src_type = CAPTURE_IFREMOTE;
1255 interface_opts.remote_host = g_strdup(device.remote_opts.remote_host_opts.remote_host);
1256 interface_opts.remote_port = g_strdup(device.remote_opts.remote_host_opts.remote_port);
1257 interface_opts.auth_type = device.remote_opts.remote_host_opts.auth_type;
1258 interface_opts.auth_username = g_strdup(device.remote_opts.remote_host_opts.auth_username);
1259 interface_opts.auth_password = g_strdup(device.remote_opts.remote_host_opts.auth_password);
1260 interface_opts.datatx_udp = device.remote_opts.remote_host_opts.datatx_udp;
1261 interface_opts.nocap_rpcap = device.remote_opts.remote_host_opts.nocap_rpcap;
1262 interface_opts.nocap_local = device.remote_opts.remote_host_opts.nocap_local;
1264 #ifdef HAVE_PCAP_SETSAMPLING
1265 interface_opts.sampling_method = device.remote_opts.sampling_method;
1266 interface_opts.sampling_param = device.remote_opts.sampling_param;
1268 g_array_append_val(capture_opts->ifaces, interface_opts);
1276 capture_opts_free_interface_t_links(gpointer elem, gpointer unused _U_)
1278 link_row* e = (link_row*)elem;
1285 capture_opts_free_interface_t_addrs(gpointer elem, gpointer unused _U_)
1291 capture_opts_free_interface_t(interface_t *device)
1293 if (device != NULL) {
1294 g_free(device->name);
1295 g_free(device->display_name);
1296 g_free(device->friendly_name);
1297 g_free(device->addresses);
1298 g_free(device->cfilter);
1299 g_free(device->timestamp_type);
1300 g_list_foreach(device->links,
1301 capture_opts_free_interface_t_links, NULL);
1302 g_list_free(device->links);
1303 #ifdef HAVE_PCAP_REMOTE
1304 g_free(device->remote_opts.remote_host_opts.remote_host);
1305 g_free(device->remote_opts.remote_host_opts.remote_port);
1306 g_free(device->remote_opts.remote_host_opts.auth_username);
1307 g_free(device->remote_opts.remote_host_opts.auth_password);
1309 g_free(device->if_info.name);
1310 g_free(device->if_info.friendly_name);
1311 g_free(device->if_info.vendor_description);
1312 g_slist_foreach(device->if_info.addrs,
1313 capture_opts_free_interface_t_addrs, NULL);
1314 g_slist_free(device->if_info.addrs);
1316 g_free(device->if_info.extcap);
1321 #endif /* HAVE_LIBPCAP */
1324 * Editor modelines - http://www.wireshark.org/tools/modelines.html
1329 * indent-tabs-mode: nil
1332 * vi: set shiftwidth=4 tabstop=8 expandtab:
1333 * :indentSize=4:tabSize=8:noTabs=true: