summaryrefslogtreecommitdiff
path: root/trigcap.c
diff options
context:
space:
mode:
authorGerald Combs <gerald@wireshark.org>2008-05-12 19:41:32 +0000
committerGerald Combs <gerald@wireshark.org>2008-05-12 19:41:32 +0000
commit20186d494784548f6b8189f139138426fba51c1a (patch)
treeb5c65a87718fe010866d1b2419f7eaa40d25c538 /trigcap.c
parent27ccd63ce7385d6f85e4bacd98e589871ea5a1b6 (diff)
downloadwireshark-20186d494784548f6b8189f139138426fba51c1a.tar.gz
If we have pcap_open, call it instead of pcap_open_live, otherwise we might
crash. The changes to trigcap.c haven't been tested, but _should_ work. svn path=/trunk/; revision=25279
Diffstat (limited to 'trigcap.c')
-rw-r--r--trigcap.c58
1 files changed, 33 insertions, 25 deletions
diff --git a/trigcap.c b/trigcap.c
index 8571cabea6..020ce3561e 100644
--- a/trigcap.c
+++ b/trigcap.c
@@ -48,7 +48,7 @@ static void panic(int err, const char* fmt, ...) {
static void dprintf(int lev, const char* fmt, ...) {
va_list ap;
-
+
va_start(ap,fmt);
if (lev <= debug_level) {
vfprintf(stderr,fmt,ap);
@@ -71,13 +71,13 @@ static void usage(int err) {
" -d increase deug level\n"
" -h prints this message\n"
;
-
+
panic(err,usage_str);
}
static void listener_handler(u_char* u, const struct pcap_pkthdr * ph, const u_char* buf) {
char errbuf[PCAP_ERRBUF_SIZE];
-
+
dprintf(2,"listener handler invoked dumping=%d\n",dumping);
if (dumping) {
@@ -89,11 +89,11 @@ static void listener_handler(u_char* u, const struct pcap_pkthdr * ph, const u_c
}
dprintf(2,"apply stop filter to listener\n");
-
+
if (pcap_setnonblock(listener, 1, errbuf) < 0) {
panic(24,"could not set listener in non blocking mode: %s\n",errbuf);
}
-
+
dprintf(2,"listener -> non_blocking\n");
dumping = 1;
}
@@ -126,7 +126,7 @@ int main(int argc, char** argv) {
pcap_t* capturer = NULL;
pcap_dumper_t* dumper = NULL;
int opt;
-
+
while ((opt = getopt(argc, argv, "i:w:s:b:e:f:phdq")) != -1) {
switch (opt) {
case 'i':
@@ -169,7 +169,7 @@ int main(int argc, char** argv) {
break;
}
}
-
+
dprintf(1,"starting with:\n interface: %s\n snaplen: %d\n promisc: %d"
"\n outfile: %s\n capture filter: %s\n start: %s\n stop: %s\n debug level: %d\n",
interface ? interface : "to be choosen",
@@ -180,19 +180,23 @@ int main(int argc, char** argv) {
start_filter_str ? start_filter_str : "** missing **",
stop_filter_str ? stop_filter_str : "** missing **",
debug_level);
-
+
if (! ( start_filter_str && stop_filter_str && outfile ) ) {
usage(10);
}
-
+
if (! interface) {
interface = pcap_lookupdev(errbuf);
if (!interface) {
panic(11, "could not obtain an interface: %s\n",errbuf);
}
}
-
- if ( ! ( listener = pcap_open_live(interface, snaplen, promisc, 1, errbuf) )) {
+
+#ifdef HAVE_PCAP_OPEN
+ if ( ! ( capturer = pcap_open(interface, snaplen, promisc, 1, NULL, errbuf) )) {
+#else
+ if ( ! ( capturer = pcap_open_live(interface, snaplen, promisc, 1, errbuf) )) {
+#endif
panic(12,"could not open interface '%s' for listener: %s\n",interface,errbuf);
}
@@ -206,14 +210,18 @@ int main(int argc, char** argv) {
if (pcap_compile(listener, &stop_filter, stop_filter_str, 1, 0) < 0) {
panic(14,"could not compile stop filter: %s\n",pcap_geterr(listener));
- }
+ }
dprintf(2,"compiled stop filter %s\n",stop_filter_str);
+#ifdef HAVE_PCAP_OPEN
+ if ( ! ( capturer = pcap_open(interface, snaplen, promisc, 1, NULL, errbuf) )) {
+#else
if ( ! ( capturer = pcap_open_live(interface, snaplen, promisc, 1, errbuf) )) {
+#endif
panic(15,"could not open interface '%s' for capturer: %s\n",interface, errbuf);
}
-
+
dprintf(1,"opened capturer (%s,%d,%d)\n",interface,snaplen, promisc);
if (capture_filter_str) {
@@ -223,7 +231,7 @@ int main(int argc, char** argv) {
if (pcap_setfilter(capturer, &capture_filter) < 0) {
panic(17,"could not apply start filter to capturer: %s\n",pcap_geterr(capturer));
}
-
+
dprintf(2,"compiled and set capture filter (%s)\n",capture_filter_str);
}
@@ -232,22 +240,22 @@ int main(int argc, char** argv) {
}
dprintf(2,"set start filter on listener\n");
-
+
if (pcap_setnonblock(listener, 0, errbuf) < 0) {
panic(19,"could not set listener in blocking mode: %s\n",errbuf);
}
dprintf(2,"listener -> blocking\n");
-
+
if (pcap_setnonblock(capturer, 1, errbuf) < 0) {
panic(20,"could not set capturer in non blocking mode: %s\n",errbuf);
}
dprintf(2,"capturer -> non_blocking\n");
-
+
if (! (dumper = pcap_dump_open(listener,outfile)) ) {
panic(21,"open dumper file '%s': %s\n",outfile,pcap_geterr(listener));
}
dprintf(2,"opened dumper file '%s'\n",outfile);
-
+
signal(SIGINT, sig_int);
#ifdef SIGQUIT
signal(SIGQUIT, sig_int);
@@ -258,29 +266,29 @@ int main(int argc, char** argv) {
#ifdef SIGSTOP
signal(SIGSTOP, sig_int);
#endif
-
+
keep_going = 1;
dumping = 0;
-
+
do {
if (pcap_dispatch(listener, -1, listener_handler, NULL) < 0 ) {
panic(22,"pcap_dispatch(listener) failed: %s\n",pcap_geterr(listener));
}
-
+
if (pcap_dispatch(capturer, -1, capture_handler, (void*)dumper) < 0 ) {
panic(23,"pcap_dispatch(capturer) failed: %s\n",pcap_geterr(capturer));
}
} while(keep_going);
-
+
if (!quiet) {
printf("%d packets captured\n",captured);
}
-
+
dprintf(1,"done!\n");
-
+
pcap_dump_close(dumper);
pcap_close(listener);
pcap_close(capturer);
-
+
return 0;
}