If a filter isn't specified, don't try to do any filtering
If pcap_lookupnet fails, just assume the netmask is 0xffffff00 that's all we really wanted from it anyway. --HG-- extra : convert_revision : ac0a390ddb7a6b0a4e4c6d2885bfa7bd059faf36
This commit is contained in:
parent
c7d6745b07
commit
03ef1a0c09
1 changed files with 13 additions and 9 deletions
|
@ -200,7 +200,7 @@ main(int argc, char *argv[])
|
||||||
int bufsize = 2000;
|
int bufsize = 2000;
|
||||||
bool listening = false;
|
bool listening = false;
|
||||||
char *device = NULL;
|
char *device = NULL;
|
||||||
char *filter = "";
|
char *filter = NULL;
|
||||||
char c;
|
char c;
|
||||||
int daemon = false;
|
int daemon = false;
|
||||||
string host;
|
string host;
|
||||||
|
@ -274,16 +274,20 @@ main(int argc, char *argv[])
|
||||||
if (pcap == NULL)
|
if (pcap == NULL)
|
||||||
panic("pcap_open_live failed: %s\n", errbuf);
|
panic("pcap_open_live failed: %s\n", errbuf);
|
||||||
|
|
||||||
bpf_program program;
|
if (filter) {
|
||||||
bpf_u_int32 localnet, netmask;
|
bpf_program program;
|
||||||
if (pcap_lookupnet(device, &localnet, &netmask, errbuf) == -1)
|
bpf_u_int32 localnet, netmask;
|
||||||
panic("pcap_lookupnet failed: %s\n", errbuf);
|
if (pcap_lookupnet(device, &localnet, &netmask, errbuf) == -1) {
|
||||||
|
DPRINTF("pcap_lookupnet failed: %s\n", errbuf);
|
||||||
|
netmask = 0xffffff00;
|
||||||
|
}
|
||||||
|
|
||||||
if (pcap_compile(pcap, &program, filter, 1, netmask) == -1)
|
if (pcap_compile(pcap, &program, filter, 1, netmask) == -1)
|
||||||
panic("pcap_compile failed, invalid filter:\n%s\n", filter);
|
panic("pcap_compile failed, invalid filter:\n%s\n", filter);
|
||||||
|
|
||||||
if (pcap_setfilter(pcap, &program) == -1)
|
if (pcap_setfilter(pcap, &program) == -1)
|
||||||
panic("pcap_setfilter failed\n");
|
panic("pcap_setfilter failed\n");
|
||||||
|
}
|
||||||
|
|
||||||
eth_t *ethernet = eth_open(device);
|
eth_t *ethernet = eth_open(device);
|
||||||
if (!ethernet)
|
if (!ethernet)
|
||||||
|
|
Loading…
Reference in a new issue