The Styleguide section has been moved to the Wireshark Developer's Guide.
[obnox/wireshark/wip.git] / capture_opts.c
index f69f791f088d4ef15c7ae090116b3b4340023943..793477c99770639500bff7c227d2ac847a6847e9 100644 (file)
 #include <unistd.h>
 #endif
 
-#ifdef HAVE_SYS_TYPES_H
-# include <sys/types.h>
-#endif
-
-#ifdef HAVE_NETINET_IN_H
-#include <netinet/in.h>
-#endif
-
-#ifdef HAVE_ARPA_INET_H
-#include <arpa/inet.h>
-#endif
-
-#ifdef HAVE_SYS_SOCKET_H
-#include <sys/socket.h>         /* needed to define AF_ values on UNIX */
-#endif
-
-#ifdef HAVE_WINSOCK2_H
-#include <winsock2.h>           /* needed to define AF_ values on Windows */
-#endif
-
-#ifdef NEED_INET_V6DEFS_H
-# include "inet_v6defs.h"
-#endif
-
 #include <glib.h>
 
 #include <epan/packet.h>
@@ -105,12 +81,11 @@ capture_opts_init(capture_options *capture_opts, void *cf)
   capture_opts->snaplen                 = WTAP_MAX_PACKET_SIZE; /* snapshot length - default is
                                                                    infinite, in effect */
   capture_opts->promisc_mode            = TRUE;             /* promiscuous mode is the default */
-#ifdef HAVE_PCAP_CREATE
   capture_opts->monitor_mode            = FALSE;
-#endif
   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;
@@ -185,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);
@@ -293,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");
@@ -556,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) {
@@ -573,13 +552,18 @@ capture_opts_add_opt(capture_options *capture_opts, int opt, const char *optarg_
 }
 
 void
-capture_opts_print_link_layer_types(GList *lt_list)
+capture_opts_print_if_capabilities(if_capabilities_t *caps,
+                                   gboolean monitor_mode)
 {
     GList *lt_entry;
     data_link_info_t *data_link_info;
 
-    fprintf_stderr("Data link types (use option -y to set):\n");
-    for (lt_entry = lt_list; lt_entry != NULL;
+    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);
@@ -591,35 +575,13 @@ capture_opts_print_link_layer_types(GList *lt_list)
     }
 }
 
-/* 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;
@@ -627,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("<unknown IPv4>");
-                    }
-                    break;
-                case IF_AT_IPv6:
-                    if (inet_ntop(AF_INET6, &if_addr->addr.ip6_addr,
-                                addr_str, ADDRSTRLEN)) {
-                        printf("%s", addr_str);
-                    } else {
-                        printf("<unknown IPv6>");
-                    }
-                    break;
-                default:
-                    printf("<type unknown %u>", 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;
 }
 
 
@@ -697,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
 }