aboutsummaryrefslogtreecommitdiffstats
path: root/gg_sniff/pcap.c
diff options
context:
space:
mode:
authorLaurent Ghigonis <laurent@p1sec.com>2013-06-05 13:05:52 +0200
committerLaurent Ghigonis <laurent@p1sec.com>2013-06-05 13:05:52 +0200
commit96dca2aca065b1e60be88d2b7c553f7769df4e5e (patch)
tree94a71909b9cc4be5c6610a0eff78df34455e129e /gg_sniff/pcap.c
parentgg_sniff: update README to match reality and talk about filters (diff)
downloadglouglou-96dca2aca065b1e60be88d2b7c553f7769df4e5e.tar.xz
glouglou-96dca2aca065b1e60be88d2b7c553f7769df4e5e.zip
gg_sniff: add -f <libpcap filter>
Diffstat (limited to '')
-rw-r--r--gg_sniff/pcap.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/gg_sniff/pcap.c b/gg_sniff/pcap.c
index 72b9133..ac27b33 100644
--- a/gg_sniff/pcap.c
+++ b/gg_sniff/pcap.c
@@ -98,7 +98,7 @@ static struct _cap_t _cap;
int
ggsniff_pcap_init(struct event_base *ev_base, struct gg_client *ggcli,
- struct ggnet *net, char *iface, int active)
+ struct ggnet *net, char *iface, int active, char *filter)
{
char errbuf[PCAP_ERRBUF_SIZE];
struct bpf_program bprog;
@@ -114,9 +114,11 @@ ggsniff_pcap_init(struct event_base *ev_base, struct gg_client *ggcli,
err(1, "capture: pcap_open_live failed on interface %s\n"
"with snaplen %d : %s",
iface, PCAP_SNAPLEN, errbuf);
- if (pcap_compile(pcap, &bprog, PCAP_FILTER, 0, 0) < 0)
+ if (!filter)
+ filter = strndup(PCAP_FILTER, 256);
+ if (pcap_compile(pcap, &bprog, filter, 0, 0) < 0)
err(1, "capture: pcap_compile failed with filter %s : %s",
- PCAP_FILTER, pcap_geterr(pcap));
+ filter, pcap_geterr(pcap));
if (pcap_setfilter(pcap, &bprog) < 0)
err(1, "capture: pcap_setfilter failed : %s",
pcap_geterr(pcap));