If no "-i" flag is specified to Tethereal when no file is to be read,,

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.

svn path=/trunk/; revision=1482
This commit is contained in:
Guy Harris 2000-01-15 06:05:21 +00:00
parent 8a1ecc5d83
commit 278b21900a
4 changed files with 49 additions and 18 deletions

View 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

View 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

View 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) {

View 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
}