X-Git-Url: http://git.samba.org/samba.git/?p=obnox%2Fwireshark%2Fwip.git;a=blobdiff_plain;f=capture_opts.c;h=793477c99770639500bff7c227d2ac847a6847e9;hp=657c91f41b211728805441cb1b31afa63c01cd2d;hb=f1d0c6be4d0e47de4ae263413f95c1da8da7eda5;hpb=f6dc1193d50ec175ed08a6544ab2aff905981099 diff --git a/capture_opts.c b/capture_opts.c index 657c91f41b..793477c997 100644 --- a/capture_opts.c +++ b/capture_opts.c @@ -35,30 +35,6 @@ #include #endif -#ifdef HAVE_SYS_TYPES_H -# include -#endif - -#ifdef HAVE_NETINET_IN_H -#include -#endif - -#ifdef HAVE_ARPA_INET_H -#include -#endif - -#ifdef HAVE_SYS_SOCKET_H -#include /* needed to define AF_ values on UNIX */ -#endif - -#ifdef HAVE_WINSOCK2_H -#include /* needed to define AF_ values on Windows */ -#endif - -#ifdef NEED_INET_V6DEFS_H -# include "inet_v6defs.h" -#endif - #include #include @@ -66,6 +42,7 @@ #include "capture_opts.h" #include "ringbuffer.h" #include "clopts_common.h" +#include "console_io.h" #include "cmdarg_err.h" #include "capture_ifinfo.h" @@ -97,16 +74,18 @@ capture_opts_init(capture_options *capture_opts, void *cf) capture_opts->sampling_param = 0; #endif #endif -#ifdef _WIN32 +#if defined(_WIN32) || defined(HAVE_PCAP_CREATE) capture_opts->buffer_size = 1; /* 1 MB */ #endif capture_opts->has_snaplen = FALSE; capture_opts->snaplen = WTAP_MAX_PACKET_SIZE; /* snapshot length - default is infinite, in effect */ capture_opts->promisc_mode = TRUE; /* promiscuous mode is the default */ + capture_opts->monitor_mode = FALSE; capture_opts->linktype = -1; /* the default linktype */ capture_opts->saving_to_file = FALSE; capture_opts->save_file = NULL; + capture_opts->group_read_access = FALSE; capture_opts->use_pcapng = FALSE; /* the default is pcap */ capture_opts->real_time_mode = TRUE; capture_opts->show_info = TRUE; @@ -173,7 +152,7 @@ capture_opts_log(const char *log_domain, GLogLevelFlags log_level, capture_optio g_log(log_domain, log_level, "No capture RPCAP : %u", capture_opts->nocap_rpcap); g_log(log_domain, log_level, "No capture local : %u", capture_opts->nocap_local); #endif -#ifdef _WIN32 +#if defined(_WIN32) || defined(HAVE_PCAP_CREATE) g_log(log_domain, log_level, "BufferSize : %u (MB)", capture_opts->buffer_size); #endif g_log(log_domain, log_level, "SnapLen (%u): %u", capture_opts->has_snaplen, capture_opts->snaplen); @@ -181,6 +160,7 @@ capture_opts_log(const char *log_domain, GLogLevelFlags log_level, capture_optio g_log(log_domain, log_level, "LinkType : %d", capture_opts->linktype); g_log(log_domain, log_level, "SavingToFile : %u", capture_opts->saving_to_file); g_log(log_domain, log_level, "SaveFile : %s", (capture_opts->save_file) ? capture_opts->save_file : ""); + g_log(log_domain, log_level, "GroupReadAccess : %u", capture_opts->group_read_access); g_log(log_domain, log_level, "Fileformat : %s", (capture_opts->use_pcapng) ? "PCAPNG" : "PCAP"); g_log(log_domain, log_level, "RealTimeMode : %u", capture_opts->real_time_mode); g_log(log_domain, log_level, "ShowInfo : %u", capture_opts->show_info); @@ -289,7 +269,7 @@ get_ring_arguments(capture_options *capture_opts, const char *arg) if (strcmp(arg,"files") == 0) { capture_opts->has_ring_num_files = TRUE; - capture_opts->ring_num_files = get_natural_int(p, "number of ring buffer files"); + capture_opts->ring_num_files = get_positive_int(p, "number of ring buffer files"); } else if (strcmp(arg,"filesize") == 0) { capture_opts->has_autostop_filesize = TRUE; capture_opts->autostop_filesize = get_positive_int(p, "ring buffer filesize"); @@ -464,7 +444,7 @@ capture_opts_add_opt(capture_options *capture_opts, int opt, const char *optarg_ return 1; } break; -#ifdef _WIN32 +#if defined(_WIN32) || defined(HAVE_PCAP_CREATE) case 'B': /* Buffer size */ capture_opts->buffer_size = get_positive_int(optarg_str_p, "buffer size"); break; @@ -491,6 +471,11 @@ capture_opts_add_opt(capture_options *capture_opts, int opt, const char *optarg_ return status; } break; +#ifdef HAVE_PCAP_CREATE + case 'I': /* Capture in monitor mode */ + capture_opts->monitor_mode = TRUE; + break; +#endif case 'k': /* Start capture immediately */ *start_capture = TRUE; break; @@ -547,6 +532,9 @@ capture_opts_add_opt(capture_options *capture_opts, int opt, const char *optarg_ #endif status = capture_opts_output_to_pipe(capture_opts->save_file, &capture_opts->output_to_pipe); return status; + case 'g': /* enable group read access on the capture file(s) */ + capture_opts->group_read_access = TRUE; + break; case 'y': /* Set the pcap data link type */ capture_opts->linktype = linktype_name_to_val(optarg_str_p); if (capture_opts->linktype == -1) { @@ -563,87 +551,37 @@ capture_opts_add_opt(capture_options *capture_opts, int opt, const char *optarg_ return 0; } -/* - * If you change the output format of this function, you MUST update - * capture_sync.c:sync_linktype_list_open() accordingly! - */ -int -capture_opts_list_link_layer_types(capture_options *capture_opts, gboolean machine_readable) +void +capture_opts_print_if_capabilities(if_capabilities_t *caps, + gboolean monitor_mode) { - gchar *err_str; - const gchar *desc_str; - GList *lt_list, *lt_entry; + GList *lt_entry; data_link_info_t *data_link_info; - /* Get the list of link-layer types for the capture device. */ - lt_list = get_pcap_linktype_list(capture_opts->iface, &err_str); - if (lt_list == NULL) { - if (err_str != NULL) { - cmdarg_err("The list of data link types for the capture device \"%s\" could not be obtained (%s)." - "Please check to make sure you have sufficient permissions, and that\n" - "you have the proper interface or pipe specified.\n", capture_opts->iface, err_str); - g_free(err_str); - } else - cmdarg_err("The capture device \"%s\" has no data link types.", capture_opts->iface); - return 2; - } - if (machine_readable) { /* tab-separated values to stdout */ - for (lt_entry = lt_list; lt_entry != NULL; lt_entry = g_list_next(lt_entry)) { - data_link_info = (data_link_info_t *)lt_entry->data; - if (data_link_info->description != NULL) - desc_str = data_link_info->description; - else - desc_str = "(not supported)"; - printf("%d\t%s\t%s\n", data_link_info->dlt, data_link_info->name, - desc_str); - } - } else { - cmdarg_err_cont("Data link types (use option -y to set):"); - for (lt_entry = lt_list; lt_entry != NULL; - lt_entry = g_list_next(lt_entry)) { - data_link_info = (data_link_info_t *)lt_entry->data; - cmdarg_err_cont(" %s", data_link_info->name); - if (data_link_info->description != NULL) - cmdarg_err_cont(" (%s)", data_link_info->description); - else - cmdarg_err_cont(" (not supported)"); - putchar('\n'); - } + if (caps->can_set_rfmon) + fprintf_stderr("Data link types when %sin monitor mode (use option -y to set):\n", + monitor_mode ? "" : "not "); + else + fprintf_stderr("Data link types (use option -y to set):\n"); + for (lt_entry = caps->data_link_types; lt_entry != NULL; + lt_entry = g_list_next(lt_entry)) { + data_link_info = (data_link_info_t *)lt_entry->data; + fprintf_stderr(" %s", data_link_info->name); + if (data_link_info->description != NULL) + fprintf_stderr(" (%s)", data_link_info->description); + else + fprintf_stderr(" (not supported)"); + fprintf_stderr("\n"); } - free_pcap_linktype_list(lt_list); - - return 0; } -/* Return an ASCII-formatted list of interfaces. */ -#define ADDRSTRLEN 46 /* Covers IPv4 & IPv6 */ -int -capture_opts_list_interfaces(gboolean machine_readable) +/* Print an ASCII-formatted list of interfaces. */ +void +capture_opts_print_interfaces(GList *if_list) { - GList *if_list; + int i; GList *if_entry; if_info_t *if_info; - int err; - gchar *err_str; - int i; - GSList *addr; - if_addr_t *if_addr; - char addr_str[ADDRSTRLEN]; - - if_list = capture_interface_list(&err, &err_str); - if (if_list == NULL) { - switch (err) { - case CANT_GET_INTERFACE_LIST: - cmdarg_err("%s", err_str); - g_free(err_str); - break; - - case NO_INTERFACES_FOUND: - cmdarg_err("There are no interfaces on which a capture can be done"); - break; - } - return err; - } i = 1; /* Interface id number */ for (if_entry = g_list_first(if_list); if_entry != NULL; @@ -651,61 +589,11 @@ capture_opts_list_interfaces(gboolean machine_readable) if_info = (if_info_t *)if_entry->data; printf("%d. %s", i++, if_info->name); - if (!machine_readable) { - /* Add the description if it exists */ - if (if_info->description != NULL) - printf(" (%s)", if_info->description); - } else { - /* - * Add the contents of the if_entry struct in a parseable format. - * Each if_entry element is tab-separated. Addresses are comma- - * separated. - */ - /* XXX - Make sure our description doesn't contain a tab */ - if (if_info->description != NULL) - printf("\t%s\t", if_info->description); - else - printf("\t\t"); - - for(addr = g_slist_nth(if_info->addrs, 0); addr != NULL; - addr = g_slist_next(addr)) { - if (addr != g_slist_nth(if_info->addrs, 0)) - printf(","); - - if_addr = (if_addr_t *)addr->data; - switch(if_addr->ifat_type) { - case IF_AT_IPv4: - if (inet_ntop(AF_INET, &if_addr->addr.ip4_addr, addr_str, - ADDRSTRLEN)) { - printf("%s", addr_str); - } else { - printf(""); - } - break; - case IF_AT_IPv6: - if (inet_ntop(AF_INET6, &if_addr->addr.ip6_addr, - addr_str, ADDRSTRLEN)) { - printf("%s", addr_str); - } else { - printf(""); - } - break; - default: - printf("", if_addr->ifat_type); - } - } - - if (if_info->loopback) - printf("\tloopback"); - else - printf("\tnetwork"); - - } - printf("\n"); + /* Print the description if it exists */ + if (if_info->description != NULL) + printf(" (%s)", if_info->description); + printf("\n"); } - free_interface_list(if_list); - - return 0; } @@ -721,10 +609,15 @@ void capture_opts_trim_snaplen(capture_options *capture_opts, int snaplen_min) void capture_opts_trim_ring_num_files(capture_options *capture_opts) { /* Check the value range of the ring_num_files parameter */ - if (capture_opts->ring_num_files > RINGBUFFER_MAX_NUM_FILES) + if (capture_opts->ring_num_files > RINGBUFFER_MAX_NUM_FILES) { + cmdarg_err("Too many ring buffer files (%u). Reducing to %u.\n", capture_opts->ring_num_files, RINGBUFFER_MAX_NUM_FILES); capture_opts->ring_num_files = RINGBUFFER_MAX_NUM_FILES; + } else if (capture_opts->ring_num_files > RINGBUFFER_WARN_NUM_FILES) { + cmdarg_err("%u is a lot of ring buffer files.\n", capture_opts->ring_num_files); + } #if RINGBUFFER_MIN_NUM_FILES > 0 else if (capture_opts->ring_num_files < RINGBUFFER_MIN_NUM_FILES) + cmdarg_err("Too few ring buffer files (%u). Increasing to %u.\n", capture_opts->ring_num_files, RINGBUFFER_MIN_NUM_FILES); capture_opts->ring_num_files = RINGBUFFER_MIN_NUM_FILES; #endif }