the-tcpdump-group/libpcap — pull request #318 by solofox (2013-09-01 02:41:29+00:00)
Title: Using DOT graph to show BPF optimization process

I have written a tool to show BPF optimization process using DOT graph. DOT is a graph language from graphviz package.

following the guide in tests/visopts.py:
```
solofox@slab:~/projects/libpcap$ tests/visopts.py -h

This program parse the output from pcap_compile() to visualize the CFG after
each optimize phase.

Usage guide:
1. Enable optimizier debugging code when configure libpcap,
and build libpcap & filtertest
./configure --enable-optimizer-dbg
make
make filtertest
2. Run filtertest to compile BPF expression, save to output a.txt
./filtertest EN10MB host 192.168.1.1 > a.txt
3. Send a.txt to this program's standard input
cat a.txt | tests/visopts.py
4. Step 2&3 can be merged:
./filtertest EN10MB host 192.168.1.1 | tests/visopts.py
5. The standard output is something like this:
generated files under directory: /tmp/visopts-W9ekBw
the directory will be removed when this programs finished.
open this link: http://localhost:39062/expr1.html
6. Using open link at the 3rd line `http://localhost:39062/expr1.html'

Note:
1. CFG graph is translated to SVG document, expr1.html embeded them as external
document. If you open expr1.html as local file using file:// protocol, some
browsers will deny such requests so the web pages will not shown properly.
For chrome, you can run it using following command to avoid this:
chromium --disable-web-security
That's why this program start a localhost http server.
2. expr1.html use jquery from http://ajax.googleapis.com, so you need internet
access to show the web page.

```

attach the snapshot for web for 'tcp[tcpflags]&tcp-syn != 0 or tcp[tcpflags]&tcp-fin != 0 or tcp[tcpflags]&tcp-rst != 0' optimization process, showing the CFG before and after 1st optimizaiton:
```
solofox@slab:~/projects/libpcap$ ./build/filtertest EN10MB 'tcp[tcpflags]&tcp-syn != 0 or tcp[tcpflags]&tcp-fin != 0 or tcp[tcpflags]&tcp-rst != 0' | tests/visopts.py
generated files under directory: /tmp/visopts-2h2ItY
the directory will be removed when this programs finished.
open this link: http://localhost:35144/expr1.html
```

![web-snapshot](https://f.cloud.github.com/assets/3327392/1063387/bfdd00e8-12af-11e3-96ad-8855bae8ad6b.png)