|
| 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 |
| 30 | +``` |
| 31 | + |
| 32 | +Any additional arguments are passed directly to Suricata as command |
| 33 | +line arguments. |
| 34 | + |
| 35 | +Example with common options: |
| 36 | +``` |
| 37 | +sudo ./live -i eth0 -- -l . -S rules.rules |
| 38 | +``` |
| 39 | + |
| 40 | +Example capturing from multiple interfaces: |
| 41 | +``` |
| 42 | +sudo ./live -i eth0 -i wlan0 -- -l . -S rules.rules |
| 43 | +``` |
| 44 | + |
| 45 | +Shutdown: each worker thread may call EngineStop when its capture ends; the |
| 46 | +main loop waits for this signal, performs SuricataShutdown concurrently with |
| 47 | +per-thread SCTmThreadsSlotPacketLoopFinish, then joins all worker threads |
| 48 | +before GlobalsDestroy. |
| 49 | + |
| 50 | +The example supports up to 16 interfaces simultaneously. |
| 51 | + |
| 52 | +## Building Out of Tree |
| 53 | + |
| 54 | +A Makefile.example has also been generated to use as an example on how |
| 55 | +to build against the library in a standalone application. |
| 56 | + |
| 57 | +First build and install the Suricata library including: |
| 58 | + |
| 59 | +``` |
| 60 | +make install-library |
| 61 | +make install-headers |
| 62 | +``` |
| 63 | + |
| 64 | +Then run: |
| 65 | + |
| 66 | +``` |
| 67 | +make -f Makefile.example |
| 68 | +``` |
| 69 | + |
| 70 | +If you installed to a non-standard location, you need to ensure that |
| 71 | +`libsuricata-config` is in your path, for example: |
| 72 | + |
| 73 | +``` |
| 74 | +PATH=/opt/suricata/bin:$PATH make -f Makefile.example |
| 75 | +``` |
0 commit comments