]> The Tcpdump Group git mirrors - tcpdump/commitdiff
make pcap_setdirection() call conditional, GH #252
authorDenis Ovsienko <[email protected]>
Tue, 15 Oct 2013 11:01:28 +0000 (15:01 +0400)
committerDenis Ovsienko <[email protected]>
Tue, 15 Oct 2013 11:01:28 +0000 (15:01 +0400)
pcap_setdirection() succeeds only for particular combination of
platform, interface type and direction. Calling it on each invocation
(with PCAP_D_INOUT by default) was wrong: some interfaces are two-way,
others are one-way, and pcap_setdirection() has its own idea what it
supports and what doesn't. In particular, it was impossible to do any
capture on nflog interface in Linux since commit df7d24f. Now the
function is only called on -P flag.

tcpdump.c

index 1145d1982c932e979887d32a025d534c008c07ec..2a4e17c8f0e24096af2c9ee03e955e34be202e1d 100644 (file)
--- a/tcpdump.c
+++ b/tcpdump.c
@@ -106,7 +106,7 @@ static int Lflag;                   /* list available data link types and exit */
 static int Jflag;                      /* list available time stamp types */
 #endif
 #ifdef HAVE_PCAP_SETDIRECTION
-int Pflag = PCAP_D_INOUT;      /* Restrict captured packet by sent/receive direction */
+int Pflag = -1;        /* Restrict captured packet by sent/receive direction */
 #endif
 static char *zflag = NULL;             /* compress each savefile using a specified command (like gzip or bzip2) */
 
@@ -1334,10 +1334,12 @@ main(int argc, char **argv)
                                    pcap_statustostr(status));
                }
 #ifdef HAVE_PCAP_SETDIRECTION
-               status = pcap_setdirection(pd, Pflag);
-               if (status != 0)
-                       error("%s: pcap_set_direction failed: %s",
-                           device,  pcap_geterr(pd));
+               if (Pflag != -1) {
+                       status = pcap_setdirection(pd, Pflag);
+                       if (status != 0)
+                               error("%s: pcap_setdirection() failed: %s",
+                                     device,  pcap_geterr(pd));
+               }
 #endif
 #else
                *ebuf = '\0';