dect
/
libpcap
Archived
13
0
Fork 0

When generating code for "ip broadcast", treat a netmask of 0xffffffff

(255.255.255.255) be an indication that the netmask is unknown, and
return an error.  Document that as the way to tell pcap_compile() that
the netmask is unknown.  Have filtertest default to that as the netmask,
and add a -m flag to let you specify the netmask.
This commit is contained in:
Guy Harris 2009-12-01 19:07:11 -08:00
parent 8b52a90cd9
commit 74b2de364f
3 changed files with 24 additions and 6 deletions

View File

@ -39,6 +39,7 @@ static const char rcsid[] _U_ =
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <arpa/inet.h>
#include <sys/types.h>
#include <sys/stat.h>
@ -165,6 +166,7 @@ main(int argc, char **argv)
int Oflag;
long snaplen;
int dlt;
bpf_u_int32 netmask = 0xffffffff;
char *cmdbuf;
pcap_t *pd;
struct bpf_program fcode;
@ -184,7 +186,7 @@ main(int argc, char **argv)
program_name = argv[0];
opterr = 0;
while ((op = getopt(argc, argv, "dF:Os:")) != -1) {
while ((op = getopt(argc, argv, "dF:m:Os:")) != -1) {
switch (op) {
case 'd':
@ -199,6 +201,16 @@ main(int argc, char **argv)
Oflag = 0;
break;
case 'm': {
in_addr_t addr;
addr = inet_addr(optarg);
if (addr == INADDR_NONE)
error("invalid netmask %s", optarg);
netmask = addr;
break;
}
case 's': {
char *end;
@ -235,7 +247,7 @@ main(int argc, char **argv)
if (pd == NULL)
error("Can't open fake pcap_t");
if (pcap_compile(pd, &fcode, cmdbuf, Oflag, 0) < 0)
if (pcap_compile(pd, &fcode, cmdbuf, Oflag, netmask) < 0)
error("%s", pcap_geterr(pd));
bpf_dump(&fcode, dflag);
pcap_close(pd);
@ -248,7 +260,7 @@ usage(void)
(void)fprintf(stderr, "%s, with %s\n", program_name,
pcap_lib_version());
(void)fprintf(stderr,
"Usage: %s [-dO] [ -F file ] [ -s snaplen ] dlt [ expression ]\n",
"Usage: %s [-dO] [ -F file ] [ -m netmask] [ -s snaplen ] dlt [ expression ]\n",
program_name);
exit(1);
}

View File

@ -7118,6 +7118,12 @@ gen_broadcast(proto)
break;
case Q_IP:
/*
* We treat a netmask of 0xffffffff as an indication
* that we don't know the netmask, and fail.
*/
if (netmask == 0xffffffff)
bpf_error("netmask not known, so 'ip broadcast' not supported");
b0 = gen_linktype(ETHERTYPE_IP);
hostmask = ~netmask;
b1 = gen_mcmp(OR_NET, 16, BPF_W, (bpf_int32)0, hostmask);

View File

@ -54,9 +54,9 @@ captured; it is used only when checking for IPv4 broadcast addresses in
the filter program. If the netmask of the network on which packets are
being captured isn't known to the program, or if packets are being
captured on the Linux "any" pseudo-interface that can capture on more
than one network, a value of 0 can be supplied; tests for IPv4 broadcast
addreses won't be done correctly, but all other tests in the filter
program will be OK.
than one network, a value of 0xffffffff can be supplied; tests for
IPv4 broadcast addreses will fail to compile, but all other tests in
the filter program will be OK.
.SH RETURN VALUE
.B pcap_compile()
returns 0 on success and \-1 on failure.