*/
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 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);
static struct block *gen_host6(compiler_state_t *, struct in6_addr *,
struct in6_addr *, int, int, int);
-static struct block *gen_gateway(compiler_state_t *, const u_char *,
+static struct block *gen_gateway(compiler_state_t *, const char *,
struct addrinfo *, int);
static struct block *gen_ip_proto(compiler_state_t *, const uint8_t);
static struct block *gen_ip6_proto(compiler_state_t *, const uint8_t);
initchunks(&cstate);
cstate.no_optimize = 0;
cstate.ai = NULL;
- cstate.e = NULL;
cstate.ic.root = NULL;
cstate.ic.cur_mark = 0;
cstate.bpf_pcap = p;
if (pcap_parse(scanner, &cstate) != 0) {
if (cstate.ai != NULL)
freeaddrinfo(cstate.ai);
- if (cstate.e != NULL)
- free(cstate.e);
rc = PCAP_ERROR;
goto quit;
}
return b0;
}
+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) {
/*
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;
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
return b;
case Q_GATEWAY:
- 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)
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