aboutsummaryrefslogtreecommitdiffstats
path: root/gg_sniff/pcap.c
diff options
context:
space:
mode:
Diffstat (limited to 'gg_sniff/pcap.c')
-rw-r--r--gg_sniff/pcap.c24
1 files changed, 13 insertions, 11 deletions
diff --git a/gg_sniff/pcap.c b/gg_sniff/pcap.c
index fc5b978..7456e67 100644
--- a/gg_sniff/pcap.c
+++ b/gg_sniff/pcap.c
@@ -99,7 +99,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;
@@ -115,9 +115,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));
@@ -284,7 +286,7 @@ my_pcap_open_live(const char *dev, int slen, int promisc, int to_ms,
static void
cb_pcap(int fd, short why, void *data)
{
- gg_log_tmp("cb_pcap");
+ //gg_log_tmp("cb_pcap");
pcap_dispatch(_cap.pcap, PCAP_COUNT, _cap.handler, NULL);
/* reschedule */
@@ -492,7 +494,7 @@ ip_handle(struct ip *ip, const u_char *pend, u_int wirelen)
* if this isn't the first frag, we're missing the
* next level protocol header.
*/
- gg_log_tmp("user: got a fragmented ip packet !");
+ gg_log_debug("user: got a fragmented ip packet !");
}
pkt.ver = PACKET_VERSION;
@@ -547,16 +549,16 @@ ether_handle(struct ether_header *ether, const u_char *pend, u_int wirelen)
ether_type = ntohs(ether->ether_type);
if (ether_type <= ETHERMTU)
- gg_log_tmp("llc packet !");
+ gg_log_debug("llc packet !");
else {
switch (ether_type) {
case ETHERTYPE_IP:
- gg_log_tmp("loop family AF_LINK IP");
+ gg_log_debug("loop family AF_LINK IP");
ip = (struct ip *)((u_char *)ether + sizeof(struct ether_header));
ip_handle(ip, pend, wirelen);
break;
default:
- gg_log_tmp("loop non ip packet !");
+ gg_log_debug("loop non ip packet !");
break;
}
}
@@ -630,7 +632,7 @@ phandler_sll(u_char *user, const struct pcap_pkthdr *h, const u_char *p)
ep = (struct ether_header *)((u_char *)p + SLL_HDR_LEN);
ether_handle(ep, pend, len);
default:
- gg_log_tmp("unknown family %x !", family);
+ gg_log_debug("unknown family %x !", family);
break;
}
} else {
@@ -667,7 +669,7 @@ phandler_loop(u_char *user, const struct pcap_pkthdr *h, const u_char *p)
family = ntohl(family);
switch (family) {
case AF_INET:
- gg_log_tmp("loop family AF_INET");
+ gg_log_debug("loop family AF_INET");
ip = (struct ip *)(p + NULL_HDRLEN);
ip_handle(ip, pend, len);
break;
@@ -676,7 +678,7 @@ phandler_loop(u_char *user, const struct pcap_pkthdr *h, const u_char *p)
ether_handle(ep, pend, len);
break;
default:
- gg_log_tmp("unknown family %x !", family);
+ gg_log_debug("unknown family %x !", family);
break;
}
}