|
| 1 | +# Live Capture Library Example |
| 2 | + |
| 3 | +This is an example of using the Suricata library to capture live |
| 4 | +traffic from a network interface with custom packet handling and |
| 5 | +threading. |
| 6 | + |
| 7 | +## Building In Tree |
| 8 | + |
| 9 | +The Suricata build system has created a Makefile that should allow you |
| 10 | +to build this application in-tree on most supported platforms. To |
| 11 | +build simply run: |
| 12 | + |
| 13 | +``` |
| 14 | +make |
| 15 | +``` |
| 16 | + |
| 17 | +## Running |
| 18 | + |
| 19 | +``` |
| 20 | +./live -i eth0 -l . |
| 21 | +``` |
| 22 | + |
| 23 | +This example requires at least one `-i` option to specify the network |
| 24 | +interface to capture from. You can specify multiple interfaces to |
| 25 | +capture from multiple sources simultaneously - a separate worker thread |
| 26 | +will be created for each interface: |
| 27 | + |
| 28 | +``` |
| 29 | +./live -i eth0 -i eth1 -l . |
| 30 | +``` |
| 31 | + |
| 32 | +Any additional arguments are passed directly to Suricata as command |
| 33 | +line arguments. |
| 34 | + |
| 35 | +**Note:** Live packet capture typically requires root privileges or |
| 36 | +appropriate capabilities (e.g., CAP_NET_RAW on Linux). |
| 37 | + |
| 38 | +Example with common options: |
| 39 | +``` |
| 40 | +sudo ./live -i eth0 -- -l . -S rules.rules |
| 41 | +``` |
| 42 | + |
| 43 | +Example capturing from multiple interfaces: |
| 44 | +``` |
| 45 | +sudo ./live -i eth0 -i wlan0 -- -i eth1 -l . -S rules.rules |
| 46 | +``` |
| 47 | + |
| 48 | +The example supports up to 16 interfaces simultaneously. |
| 49 | + |
| 50 | +## Building Out of Tree |
| 51 | + |
| 52 | +A Makefile.example has also been generated to use as an example on how |
| 53 | +to build against the library in a standalone application. |
| 54 | + |
| 55 | +First build and install the Suricata library including: |
| 56 | + |
| 57 | +``` |
| 58 | +make install-library |
| 59 | +make install-headers |
| 60 | +``` |
| 61 | + |
| 62 | +Then run: |
| 63 | + |
| 64 | +``` |
| 65 | +make -f Makefile.example |
| 66 | +``` |
| 67 | + |
| 68 | +If you installed to a non-standard location, you need to ensure that |
| 69 | +`libsuricata-config` is in your path, for example: |
| 70 | + |
| 71 | +``` |
| 72 | +PATH=/opt/suricata/bin:$PATH make -f Makefile.example |
| 73 | +``` |
0 commit comments