aboutsummaryrefslogtreecommitdiffstats
path: root/gg_sniff/gg_sniff.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/gg_sniff.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 'gg_sniff/gg_sniff.c')
-rw-r--r--gg_sniff/gg_sniff.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/gg_sniff/gg_sniff.c b/gg_sniff/gg_sniff.c
index cd2d2c5..8ee6de1 100644
--- a/gg_sniff/gg_sniff.c
+++ b/gg_sniff/gg_sniff.c
@@ -39,7 +39,7 @@ usage(void)
{
extern char *__progname;
- fprintf(stderr, "usage: %s [-hv] [-i interface] [ip [port]]\n", __progname);
+ fprintf(stderr, "usage: %s [-hv] [-f filter] [-i interface] [ip [port]]\n", __progname);
exit(1);
}
@@ -60,6 +60,7 @@ main(int argc, char **argv)
struct event *ev_sigint, *ev_sigterm, *ev_sigchld, *ev_sighup;
char ggserv_ip[30] = "127.0.0.1";
char *iface = NULL;
+ char *filter = NULL;
int ggserv_port = GLOUGLOU_PROBE_DEFAULT_PORT;
int pcap_init = 0;
int loglevel = 0;
@@ -70,11 +71,14 @@ main(int argc, char **argv)
if (geteuid() != 0)
errx(1, "must be root");
- while ((op = getopt(argc, argv, "ahi:v")) != -1) {
+ while ((op = getopt(argc, argv, "af:hi:v")) != -1) {
switch (op) {
case 'a':
active = 1;
break;
+ case 'f':
+ filter = strndup(optarg, 256);
+ break;
case 'h':
usage();
/* NOTREACHED */
@@ -90,8 +94,8 @@ main(int argc, char **argv)
}
}
switch (argc - optind) {
- case 2: ggserv_port = atoi(argv[3]);
- case 1: strncpy(ggserv_ip, argv[2], sizeof(ggserv_ip));
+ case 2: ggserv_port = atoi(argv[optind+1]);
+ case 1: strncpy(ggserv_ip, argv[optind], sizeof(ggserv_ip));
case 0:
break;
default:
@@ -110,7 +114,7 @@ main(int argc, char **argv)
ggcli = gg_client_connect(_ev_base, ggserv_ip, ggserv_port, NULL, NULL, NULL);
if (!ggcli)
goto quit;
- pcap_init = ggsniff_pcap_init(_ev_base, ggcli, net, iface, active);
+ pcap_init = ggsniff_pcap_init(_ev_base, ggcli, net, iface, active, filter);
if (!pcap_init)
goto quit;