/* Defines BPF extensions for Npcap */
#include <npcap-bpf.h>
#endif
- #ifdef INET6
#if defined(__MINGW32__) && defined(DEFINE_ADDITIONAL_IPV6_STUFF)
/* IPv6 address */
struct in6_addr
};
#endif /* EAI_ADDRFAMILY */
#endif /* defined(__MINGW32__) && defined(DEFINE_ADDITIONAL_IPV6_STUFF) */
- #endif /* INET6 */
#else /* _WIN32 */
#include <netdb.h> /* for "struct addrinfo" */
#endif /* _WIN32 */
*/
struct addrinfo *ai;
- /*
- * Another thing that's allocated is the result of pcap_ether_aton();
- * it must be freed with free(). This variable points to any
- * address that would need to be freed.
- */
- u_char *e;
-
/*
* Various code constructs need to know the layout of the packet.
* These values give the necessary offsets from the beginning
static struct block *gen_llc_linktype(compiler_state_t *, bpf_u_int32);
static struct block *gen_hostop(compiler_state_t *, bpf_u_int32, bpf_u_int32,
int, u_int, u_int);
-#ifdef INET6
static struct block *gen_hostop6(compiler_state_t *, struct in6_addr *,
struct in6_addr *, int, u_int, u_int);
-#endif
static struct block *gen_ahostop(compiler_state_t *, const uint8_t, int);
static struct block *gen_wlanhostop(compiler_state_t *, const u_char *, int);
static unsigned char is_mac48_linktype(const int);
static struct block *gen_mac48host(compiler_state_t *, const u_char *,
const u_char, const char *);
+static struct block *gen_mac48host_byname(compiler_state_t *, const char *,
+ const u_char, const char *);
static struct block *gen_dnhostop(compiler_state_t *, bpf_u_int32, int);
static struct block *gen_mpls_linktype(compiler_state_t *, bpf_u_int32);
static struct block *gen_host(compiler_state_t *, bpf_u_int32, bpf_u_int32,
int, int, int);
-#ifdef INET6
static struct block *gen_host6(compiler_state_t *, struct in6_addr *,
struct in6_addr *, int, int, int);
-#endif
-#ifndef INET6
-static struct block *gen_gateway(compiler_state_t *, const u_char *,
+static struct block *gen_gateway(compiler_state_t *, const char *,
struct addrinfo *, int);
-#endif
static struct block *gen_ip_proto(compiler_state_t *, const uint8_t);
static struct block *gen_ip6_proto(compiler_state_t *, const uint8_t);
static struct block *gen_ipfrag(compiler_state_t *);
initchunks(&cstate);
cstate.no_optimize = 0;
-#ifdef INET6
cstate.ai = NULL;
-#endif
- cstate.e = NULL;
cstate.ic.root = NULL;
cstate.ic.cur_mark = 0;
cstate.bpf_pcap = p;
goto quit;
}
if (pcap_parse(scanner, &cstate) != 0) {
-#ifdef INET6
if (cstate.ai != NULL)
freeaddrinfo(cstate.ai);
-#endif
- if (cstate.e != NULL)
- free(cstate.e);
rc = PCAP_ERROR;
goto quit;
}
return gen_mcmp(cstate, OR_LINKPL, offset, BPF_W, addr, mask);
}
-#ifdef INET6
static struct block *
gen_hostop6(compiler_state_t *cstate, struct in6_addr *addr,
struct in6_addr *mask, int dir, u_int src_off, u_int dst_off)
}
return b1 ? b1 : gen_true(cstate);
}
-#endif
/*
* Like gen_mac48host(), but for DLT_IEEE802_11 (802.11 wireless LAN) and
/*NOTREACHED*/
}
-#ifdef INET6
static struct block *
gen_host6(compiler_state_t *cstate, struct in6_addr *addr,
struct in6_addr *mask, int proto, int dir, int type)
type == Q_NET ? "ip6 net" : "ip6 host");
/*NOTREACHED*/
}
-#endif
static unsigned char
is_mac48_linktype(const int linktype)
return b0;
}
-#ifndef INET6
+static struct block *
+gen_mac48host_byname(compiler_state_t *cstate, const char *name,
+ const u_char dir, const char *context)
+{
+ if (! is_mac48_linktype(cstate->linktype))
+ fail_kw_on_dlt(cstate, context);
+
+ u_char *eaddrp = pcap_ether_hostton(name);
+ if (eaddrp == NULL)
+ bpf_error(cstate, ERRSTR_UNKNOWN_MAC48HOST, name);
+ u_char eaddr[6];
+ memcpy(eaddr, eaddrp, sizeof(eaddr));
+ free(eaddrp);
+
+ return gen_mac48host(cstate, eaddr, dir, context);
+}
+
/*
* This primitive is non-directional by design, so the grammar does not allow
* to qualify it with a direction.
*/
static struct block *
-gen_gateway(compiler_state_t *cstate, const u_char *eaddr,
+gen_gateway(compiler_state_t *cstate, const char *name,
struct addrinfo *alist, int proto)
{
struct block *b0, *b1, *tmp;
case Q_IP:
case Q_ARP:
case Q_RARP:
- b0 = gen_mac48host(cstate, eaddr, Q_OR, "gateway");
+ b0 = gen_mac48host_byname(cstate, name, Q_OR, "gateway");
b1 = NULL;
for (ai = alist; ai != NULL; ai = ai->ai_next) {
/*
bpf_error(cstate, ERRSTR_INVALID_QUAL, pqkw(proto), "gateway");
/*NOTREACHED*/
}
-#endif
static struct block *
gen_proto_abbrev_internal(compiler_state_t *cstate, int proto)
struct addrinfo hints, *res, *ai;
int error;
struct sockaddr_in *in4;
-#ifdef INET6
struct sockaddr_in6 *in6;
-#endif
int port = -1;
/*
port = ntohs(in4->sin_port);
break;
}
-#ifdef INET6
if (ai->ai_addr->sa_family == AF_INET6) {
in6 = (struct sockaddr_in6 *)ai->ai_addr;
port = ntohs(in6->sin6_port);
break;
}
-#endif
}
}
freeaddrinfo(res);
int proto = q.proto;
int dir = q.dir;
int tproto;
- u_char *eaddrp;
- u_char eaddr[6];
bpf_u_int32 mask, addr;
struct addrinfo *res, *res0;
struct sockaddr_in *sin4;
-#ifdef INET6
int tproto6;
struct sockaddr_in6 *sin6;
struct in6_addr mask128;
-#endif /*INET6*/
struct block *b, *tmp;
int port, real_proto;
bpf_u_int32 port1, port2;
case Q_DEFAULT:
case Q_HOST:
if (proto == Q_LINK) {
- const char *context = "link host NAME";
- if (! is_mac48_linktype(cstate->linktype))
- fail_kw_on_dlt(cstate, context);
- eaddrp = pcap_ether_hostton(name);
- if (eaddrp == NULL)
- bpf_error(cstate, ERRSTR_UNKNOWN_MAC48HOST, name);
- memcpy(eaddr, eaddrp, sizeof(eaddr));
- free(eaddrp);
- return gen_mac48host(cstate, eaddr, q.dir, context);
+ return gen_mac48host_byname(cstate, name, q.dir, "link host NAME");
} else if (proto == Q_DECNET) {
/*
* A long time ago on Ultrix libpcap supported
*/
bpf_error(cstate, "invalid DECnet address '%s'", name);
} else {
-#ifdef INET6
memset(&mask128, 0xff, sizeof(mask128));
-#endif
res0 = res = pcap_nametoaddrinfo(name);
if (res == NULL)
bpf_error(cstate, "unknown host '%s'", name);
cstate->ai = res;
b = tmp = NULL;
tproto = proto;
-#ifdef INET6
tproto6 = proto;
-#endif
if (cstate->off_linktype.constant_part == OFFSET_NOT_SET &&
tproto == Q_DEFAULT) {
tproto = Q_IP;
-#ifdef INET6
tproto6 = Q_IPV6;
-#endif
}
for (res = res0; res; res = res->ai_next) {
switch (res->ai_family) {
case AF_INET:
-#ifdef INET6
if (tproto == Q_IPV6)
continue;
-#endif
sin4 = (struct sockaddr_in *)
res->ai_addr;
tmp = gen_host(cstate, ntohl(sin4->sin_addr.s_addr),
0xffffffff, tproto, dir, q.addr);
break;
-#ifdef INET6
case AF_INET6:
if (tproto6 == Q_IP)
continue;
tmp = gen_host6(cstate, &sin6->sin6_addr,
&mask128, tproto6, dir, q.addr);
break;
-#endif
default:
continue;
}
return b;
case Q_GATEWAY:
-#ifndef INET6
- if (! is_mac48_linktype(cstate->linktype))
- fail_kw_on_dlt(cstate, "gateway");
- eaddrp = pcap_ether_hostton(name);
- if (eaddrp == NULL)
- bpf_error(cstate, ERRSTR_UNKNOWN_MAC48HOST, name);
- memcpy(eaddr, eaddrp, sizeof(eaddr));
- free(eaddrp);
-
res = pcap_nametoaddrinfo(name);
cstate->ai = res;
if (res == NULL)
bpf_error(cstate, "unknown host '%s'", name);
- b = gen_gateway(cstate, eaddr, res, proto);
+ b = gen_gateway(cstate, name, res, proto);
cstate->ai = NULL;
freeaddrinfo(res);
if (b == NULL)
bpf_error(cstate, "unknown host '%s'", name);
return b;
-#else
- bpf_error(cstate, "'gateway' not supported in this configuration");
-#endif /*INET6*/
case Q_PROTO:
real_proto = lookup_proto(cstate, name, proto);
/*NOTREACHED*/
}
-#ifdef INET6
struct block *
gen_mcode6(compiler_state_t *cstate, const char *s, bpf_u_int32 masklen,
struct qual q)
/*NOTREACHED*/
}
}
-#endif /*INET6*/
struct block *
gen_ecode(compiler_state_t *cstate, const char *s, struct qual q)
if (setjmp(cstate->top_ctx))
return (NULL);
- if ((q.addr == Q_HOST || q.addr == Q_DEFAULT) && q.proto == Q_LINK) {
- const char *context = "link host XX:XX:XX:XX:XX:XX";
- if (! is_mac48_linktype(cstate->linktype))
- fail_kw_on_dlt(cstate, context);
- cstate->e = pcap_ether_aton(s);
- if (cstate->e == NULL)
- bpf_error(cstate, "malloc");
- struct block *b = gen_mac48host(cstate, cstate->e, q.dir, context);
- free(cstate->e);
- cstate->e = NULL;
- return (b);
- }
- bpf_error(cstate, "ethernet address used in non-ether expression");
- /*NOTREACHED*/
+ const char *context = "link host XX:XX:XX:XX:XX:XX";
+
+ if (! ((q.addr == Q_HOST || q.addr == Q_DEFAULT) && q.proto == Q_LINK))
+ bpf_error(cstate, "ethernet address used in non-ether expression");
+ if (! is_mac48_linktype(cstate->linktype))
+ fail_kw_on_dlt(cstate, context);
+
+ u_char *eaddrp = pcap_ether_aton(s);
+ if (eaddrp == NULL)
+ bpf_error(cstate, "malloc");
+ u_char eaddr[6];
+ memcpy(eaddr, eaddrp, sizeof(eaddr));
+ free(eaddrp);
+
+ return gen_mac48host(cstate, eaddr, q.dir, context);
}
void