]> The Tcpdump Group git mirrors - libpcap/blobdiff - tests/filtertest.c
Dump BPF tree representation transformations using dot language in bpf_optimize().
[libpcap] / tests / filtertest.c
index a56d1e49e9236192b35df432e07a3b6b0b1d8a5b..e5ebcb72ad8f732d3f336453b80cc98672e37126 100644 (file)
@@ -57,6 +57,9 @@ static void error(const char *, ...)
 extern int optind;
 extern int opterr;
 extern char *optarg;
+#ifdef BDEBUG
+int dflag;
+#endif
 
 /*
  * On Windows, we need to open the file in binary mode, so that
@@ -161,7 +164,9 @@ main(int argc, char **argv)
 {
        char *cp;
        int op;
+#ifndef BDEBUG
        int dflag;
+#endif
        char *infile;
        int Oflag;
        long snaplen;
@@ -175,7 +180,15 @@ main(int argc, char **argv)
        if(wsockinit() != 0) return 1;
 #endif /* WIN32 */
 
+#ifndef BDEBUG
        dflag = 1;
+#else
+       /* if optimizer debugging is enabled, output DOT graph
+        * `dflag=4' is equivalent to -dddd to follow -d/-dd/-ddd
+     * convention in tcpdump command line
+        */
+       dflag = 4;
+#endif
        infile = NULL;
        Oflag = 1;
        snaplen = 68;
@@ -249,6 +262,16 @@ main(int argc, char **argv)
 
        if (pcap_compile(pd, &fcode, cmdbuf, Oflag, netmask) < 0)
                error("%s", pcap_geterr(pd));
+#ifdef BDEBUG
+       // replace line feed with space
+       for (cp = cmdbuf; *cp != '\0'; ++cp) {
+               if (*cp == '\r' || *cp == '\n') {
+                       *cp = ' ';
+               }
+       }
+       // only show machine code if BDEBUG defined, since dflag > 3
+       printf("machine codes for filter: %s\n", cmdbuf);
+#endif
        bpf_dump(&fcode, dflag);
        pcap_close(pd);
        exit(0);