diff --git a/filtertest.c b/filtertest.c index e4ecf2d..a56d1e4 100644 --- a/filtertest.c +++ b/filtertest.c @@ -166,7 +166,7 @@ main(int argc, char **argv) int Oflag; long snaplen; int dlt; - bpf_u_int32 netmask = 0xffffffff; + bpf_u_int32 netmask = PCAP_NETMASK_UNKNOWN; char *cmdbuf; pcap_t *pd; struct bpf_program fcode; diff --git a/gencode.c b/gencode.c index de57876..7c0702e 100644 --- a/gencode.c +++ b/gencode.c @@ -7119,10 +7119,11 @@ gen_broadcast(proto) case Q_IP: /* - * We treat a netmask of 0xffffffff as an indication - * that we don't know the netmask, and fail. + * We treat a netmask of PCAP_NETMASK_UNKNOWN (0xffffffff) + * as an indication that we don't know the netmask, and fail + * in that case. */ - if (netmask == 0xffffffff) + if (netmask == PCAP_NETMASK_UNKNOWN) bpf_error("netmask not known, so 'ip broadcast' not supported"); b0 = gen_linktype(ETHERTYPE_IP); hostmask = ~netmask; diff --git a/pcap/pcap.h b/pcap/pcap.h index f2451ad..5a571c6 100644 --- a/pcap/pcap.h +++ b/pcap/pcap.h @@ -253,6 +253,12 @@ typedef void (*pcap_handler)(u_char *, const struct pcap_pkthdr *, #define PCAP_WARNING 1 /* generic warning code */ #define PCAP_WARNING_PROMISC_NOTSUP 2 /* this device doesn't support promiscuous mode */ +/* + * Value to pass to pcap_compile() as the netmask if you don't know what + * the netmask is. + */ +#define PCAP_NETMASK_UNKNOWN 0xffffffff + char *pcap_lookupdev(char *); int pcap_lookupnet(const char *, bpf_u_int32 *, bpf_u_int32 *, char *); diff --git a/pcap_compile.3pcap.in b/pcap_compile.3pcap.in index 2c101fa..e557fdb 100644 --- a/pcap_compile.3pcap.in +++ b/pcap_compile.3pcap.in @@ -54,8 +54,8 @@ 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 0xffffffff can be supplied; tests for -IPv4 broadcast addreses will fail to compile, but all other tests in +than one network, a value of PCAP_NETMASK_UNKNOWN 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()