If no "-i" flag is specified to Tethereal when no file is to be read,,
authorguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Sat, 15 Jan 2000 06:05:21 +0000 (06:05 +0000)
committerguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Sat, 15 Jan 2000 06:05:21 +0000 (06:05 +0000)
or to Ethereal when the "-k" flag is specified, i.e. when a capture is
to be started immediately, use "pcap_lookupdev()" to pick an interface,
just as tcpdump does.

git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@1482 f5534014-38df-0310-8fa8-9805f1628bb7

doc/ethereal.pod.template
doc/tethereal.pod.template
gtk/main.c
tethereal.c

index 77bf938c424c08f68e3a4e7daacb0b40f0257ce8..b2b8eb0199fba54db3a037555cc97b3733761589 100644 (file)
@@ -94,14 +94,17 @@ Prints the version and options and exits.
 
 =item -i
 
-Sets the name of the interface to use for live packet capture.  It
-should match one of the names listed in "B<netstat -i>" or "B<ifconfig -a>".
+Sets the name of the network interface to use for live packet capture. 
+It should match one of the names listed in "B<netstat -i>" or
+"B<ifconfig -a>".
 
 =item -k
 
-Starts the capture session immediately; this option requires 
-the B<-i> parameter, specifying the interface on which the capture
-should be done.
+Starts the capture session immediately.  If the B<-i> flag was
+specified, the capture uses the specified interface.  Otherwise,
+B<Ethereal> searches the list of interfaces on the system for the
+lowest-numbered, configured-up interface (excluding loopback
+interfaces); ties are broken by choosing the earliest match.
 
 =item -m
 
index 6de94288757b6d23b9017f49cd4c3d02f9bb3c4d..57eaa4a17fa5444ad1ac36fb56acd612c4fe3caf 100644 (file)
@@ -79,8 +79,12 @@ Prints the version and options and exits.
 
 =item -i
 
-Sets the name of the interface to use for live packet capture.  It
-should match one of the names listed in "B<netstat -i>" or "B<ifconfig -a>".
+Sets the name of the network interface to use for live packet capture. 
+It should match one of the names listed in "B<netstat -i>" or
+"B<ifconfig -a>".  If no interface is specified, B<Ethereal> searches
+the list of interfaces on the system for the lowest-numbered,
+configured-up interface (excluding loopback interfaces); ties are broken
+by choosing the earliest match.
 
 =item -n
 
index 5f17e3e12f060c8dcfc3c4ac73fc78385c7ea055..e65c1024acbc06edcc335b5878755eeb5c6dacf5 100644 (file)
@@ -1,6 +1,6 @@
 /* main.c
  *
- * $Id: main.c,v 1.87 2000/01/15 00:22:51 gram Exp $
+ * $Id: main.c,v 1.88 2000/01/15 06:05:21 guy Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@zing.org>
@@ -1023,6 +1023,7 @@ main(int argc, char *argv[])
 #ifdef HAVE_LIBPCAP
   gboolean             start_capture = FALSE;
   gchar               *save_file = NULL;
+  gchar                err_str[PCAP_ERRBUF_SIZE];
 #else
   gboolean             capture_option_specified = FALSE;
 #endif
@@ -1304,9 +1305,16 @@ main(int argc, char *argv[])
 #endif
 #ifdef HAVE_LIBPCAP
   if (start_capture) {
+    /* We're supposed to do a live capture; did the user specify an interface
+       to use? */
     if (cf.iface == NULL) {
-      fprintf(stderr, "ethereal: \"-k\" flag was specified without \"-i\" flag\n");
-      exit(1);
+      /* No - have libpcap pick one. */
+      cf.iface = pcap_lookupdev(err_str);
+      if (cf.iface == NULL) {
+        /* It couldn't pick one. */
+        fprintf(stderr, "ethereal: %s\n", err_str);
+        exit(2);
+      }
     }
   }
   if (capture_child) {
index 077459de491608eb0322674d7304313f0eb4c3a2..1894f52cff113e5ec475355f5baa3799faa12123 100644 (file)
@@ -1,6 +1,6 @@
 /* tethereal.c
  *
- * $Id: tethereal.c,v 1.4 2000/01/14 23:26:18 nneul Exp $
+ * $Id: tethereal.c,v 1.5 2000/01/15 06:04:59 guy Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@zing.org>
@@ -131,7 +131,7 @@ print_usage(void) {
   fprintf(stderr, "This is GNU %s %s, compiled with %s\n", PACKAGE,
          VERSION, comp_info_str);
 
-  fprintf(stderr, "t%s -i iface [ -vVh ] [ -c count ] [ -f <filter expression> ]\n", PACKAGE);
+  fprintf(stderr, "t%s [ -vVh ] [ -c count ] [ -f <filter expression> ] [ -i iface ]\n", PACKAGE);
   fprintf(stderr, "\t[ -r infile ] [ -R <filter expression> ] [ -s snaplen ]\n");
   fprintf(stderr, "\t[ -t <time stamp format> ] [ -w savefile ]\n");
 }
@@ -147,7 +147,9 @@ main(int argc, char *argv[])
 #endif
   char                *pf_path;
   int                  err;
-#ifndef HAVE_LIBPCAP
+#ifdef HAVE_LIBPCAP
+  gchar                err_str[PCAP_ERRBUF_SIZE];
+#else
   gboolean             capture_option_specified = FALSE;
 #endif
   gchar               *cf_name = NULL, *rfilter = NULL;
@@ -368,14 +370,28 @@ main(int argc, char *argv[])
       exit(2);
     }
     cf_name[0] = '\0';
-#ifdef HAVE_LIBPCAP
   } else {
-    if (!cf.iface) {
-       print_usage();
-       fprintf(stderr, "\nPlease specify an interface with the -i option.\n");
-       exit(1);
+    /* No capture file specified, so we're supposed to do a live capture;
+       do we have support for live captures? */
+#ifdef HAVE_LIBPCAP
+    /* Yes; did the user specify an interface to use? */
+    if (cf.iface == NULL) {
+        /* No - have libpcap pick one. */
+        cf.iface = pcap_lookupdev(err_str);
+        if (cf.iface == NULL) {
+            /* It couldn't pick one. */
+            fprintf(stderr, "tethereal: %s\n", err_str);
+            exit(2);
+        }
+
+        /* Let the user know what interface was chosen. */
+        printf("Capturing on %s\n", cf.iface);
     }
     capture();
+#else
+    /* No - complain. */
+    fprintf(stderr, "This version of Tethereal was not built with support for capturing packets.\n");
+    exit(2);
 #endif
   }