]> The Tcpdump Group git mirrors - libpcap/blobdiff - gencode.c
Clean up signed vs. unsigned, do more error checking in the parser.
[libpcap] / gencode.c
index 296626794b58326f1bad87c356002f4a202cd001..3bb29dcdcbf4167665c42595e4aac349cd8a9245 100644 (file)
--- a/gencode.c
+++ b/gencode.c
@@ -248,6 +248,7 @@ struct chunk {
 struct _compiler_state {
        jmp_buf top_ctx;
        pcap_t *bpf_pcap;
+       int error_set;
 
        struct icode ic;
 
@@ -435,10 +436,22 @@ bpf_set_error(compiler_state_t *cstate, const char *fmt, ...)
 {
        va_list ap;
 
-       va_start(ap, fmt);
-       (void)pcap_vsnprintf(cstate->bpf_pcap->errbuf, PCAP_ERRBUF_SIZE,
-           fmt, ap);
-       va_end(ap);
+       /*
+        * If we've already set an error, don't override it.
+        * The lexical analyzer reports some errors by setting
+        * the error and then returning a LEX_ERROR token, which
+        * is not recognized by any grammar rule, and thus forces
+        * the parse to stop.  We don't want the error reported
+        * by the lexical analyzer to be overwritten by the syntax
+        * error.
+        */
+       if (!cstate->error_set) {
+               va_start(ap, fmt);
+               (void)pcap_vsnprintf(cstate->bpf_pcap->errbuf, PCAP_ERRBUF_SIZE,
+                   fmt, ap);
+               va_end(ap);
+               cstate->error_set = 1;
+       }
 }
 
 /*
@@ -479,21 +492,21 @@ static inline void syntax(compiler_state_t *cstate);
 static void backpatch(struct block *, struct block *);
 static void merge(struct block *, struct block *);
 static struct block *gen_cmp(compiler_state_t *, enum e_offrel, u_int,
-    u_int, bpf_int32);
+    u_int, bpf_u_int32);
 static struct block *gen_cmp_gt(compiler_state_t *, enum e_offrel, u_int,
-    u_int, bpf_int32);
+    u_int, bpf_u_int32);
 static struct block *gen_cmp_ge(compiler_state_t *, enum e_offrel, u_int,
-    u_int, bpf_int32);
+    u_int, bpf_u_int32);
 static struct block *gen_cmp_lt(compiler_state_t *, enum e_offrel, u_int,
-    u_int, bpf_int32);
+    u_int, bpf_u_int32);
 static struct block *gen_cmp_le(compiler_state_t *, enum e_offrel, u_int,
-    u_int, bpf_int32);
+    u_int, bpf_u_int32);
 static struct block *gen_mcmp(compiler_state_t *, enum e_offrel, u_int,
-    u_int, bpf_int32, bpf_u_int32);
+    u_int, bpf_u_int32, bpf_u_int32);
 static struct block *gen_bcmp(compiler_state_t *, enum e_offrel, u_int,
     u_int, const u_char *);
-static struct block *gen_ncmp(compiler_state_t *, enum e_offrel, bpf_u_int32,
-    bpf_u_int32, bpf_u_int32, bpf_u_int32, int, bpf_int32);
+static struct block *gen_ncmp(compiler_state_t *, enum e_offrel, u_int,
+    u_int, bpf_u_int32, int, int, bpf_u_int32);
 static struct slist *gen_load_absoffsetrel(compiler_state_t *, bpf_abs_offset *,
     u_int, u_int);
 static struct slist *gen_load_a(compiler_state_t *, enum e_offrel, u_int,
@@ -502,9 +515,9 @@ static struct slist *gen_loadx_iphdrlen(compiler_state_t *);
 static struct block *gen_uncond(compiler_state_t *, int);
 static inline struct block *gen_true(compiler_state_t *);
 static inline struct block *gen_false(compiler_state_t *);
-static struct block *gen_ether_linktype(compiler_state_t *, int);
-static struct block *gen_ipnet_linktype(compiler_state_t *, int);
-static struct block *gen_linux_sll_linktype(compiler_state_t *, int);
+static struct block *gen_ether_linktype(compiler_state_t *, bpf_u_int32);
+static struct block *gen_ipnet_linktype(compiler_state_t *, bpf_u_int32);
+static struct block *gen_linux_sll_linktype(compiler_state_t *, bpf_u_int32);
 static struct slist *gen_load_prism_llprefixlen(compiler_state_t *);
 static struct slist *gen_load_avs_llprefixlen(compiler_state_t *);
 static struct slist *gen_load_radiotap_llprefixlen(compiler_state_t *);
@@ -512,15 +525,15 @@ static struct slist *gen_load_ppi_llprefixlen(compiler_state_t *);
 static void insert_compute_vloffsets(compiler_state_t *, struct block *);
 static struct slist *gen_abs_offset_varpart(compiler_state_t *,
     bpf_abs_offset *);
-static int ethertype_to_ppptype(int);
-static struct block *gen_linktype(compiler_state_t *, int);
+static bpf_u_int32 ethertype_to_ppptype(bpf_u_int32);
+static struct block *gen_linktype(compiler_state_t *, bpf_u_int32);
 static struct block *gen_snap(compiler_state_t *, bpf_u_int32, bpf_u_int32);
-static struct block *gen_llc_linktype(compiler_state_t *, int);
+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, int, u_int, u_int);
+    int, bpf_u_int32, u_int, u_int);
 #ifdef INET6
 static struct block *gen_hostop6(compiler_state_t *, struct in6_addr *,
-    struct in6_addr *, int, int, u_int, u_int);
+    struct in6_addr *, int, bpf_u_int32, u_int, u_int);
 #endif
 static struct block *gen_ahostop(compiler_state_t *, const u_char *, int);
 static struct block *gen_ehostop(compiler_state_t *, const u_char *, int);
@@ -529,7 +542,7 @@ static struct block *gen_thostop(compiler_state_t *, const u_char *, int);
 static struct block *gen_wlanhostop(compiler_state_t *, const u_char *, int);
 static struct block *gen_ipfchostop(compiler_state_t *, const u_char *, int);
 static struct block *gen_dnhostop(compiler_state_t *, bpf_u_int32, int);
-static struct block *gen_mpls_linktype(compiler_state_t *, 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
@@ -541,23 +554,25 @@ static struct block *gen_gateway(compiler_state_t *, const u_char *,
     struct addrinfo *, int, int);
 #endif
 static struct block *gen_ipfrag(compiler_state_t *);
-static struct block *gen_portatom(compiler_state_t *, int, bpf_int32);
-static struct block *gen_portrangeatom(compiler_state_t *, int, bpf_int32,
-    bpf_int32);
-static struct block *gen_portatom6(compiler_state_t *, int, bpf_int32);
-static struct block *gen_portrangeatom6(compiler_state_t *, int, bpf_int32,
-    bpf_int32);
-struct block *gen_portop(compiler_state_t *, int, int, int);
-static struct block *gen_port(compiler_state_t *, int, int, int);
-struct block *gen_portrangeop(compiler_state_t *, int, int, int, int);
-static struct block *gen_portrange(compiler_state_t *, int, int, int, int);
-struct block *gen_portop6(compiler_state_t *, int, int, int);
-static struct block *gen_port6(compiler_state_t *, int, int, int);
-struct block *gen_portrangeop6(compiler_state_t *, int, int, int, int);
-static struct block *gen_portrange6(compiler_state_t *, int, int, int, int);
+static struct block *gen_portatom(compiler_state_t *, int, bpf_u_int32);
+static struct block *gen_portrangeatom(compiler_state_t *, u_int, bpf_u_int32,
+    bpf_u_int32);
+static struct block *gen_portatom6(compiler_state_t *, int, bpf_u_int32);
+static struct block *gen_portrangeatom6(compiler_state_t *, u_int, bpf_u_int32,
+    bpf_u_int32);
+static struct block *gen_portop(compiler_state_t *, u_int, u_int, int);
+static struct block *gen_port(compiler_state_t *, u_int, int, int);
+static struct block *gen_portrangeop(compiler_state_t *, u_int, u_int,
+    bpf_u_int32, int);
+static struct block *gen_portrange(compiler_state_t *, u_int, u_int, int, int);
+struct block *gen_portop6(compiler_state_t *, u_int, u_int, int);
+static struct block *gen_port6(compiler_state_t *, u_int, int, int);
+static struct block *gen_portrangeop6(compiler_state_t *, u_int, u_int,
+    bpf_u_int32, int);
+static struct block *gen_portrange6(compiler_state_t *, u_int, u_int, int, int);
 static int lookup_proto(compiler_state_t *, const char *, int);
-static struct block *gen_protochain(compiler_state_t *, int, int, int);
-static struct block *gen_proto(compiler_state_t *, int, int, int);
+static struct block *gen_protochain(compiler_state_t *, bpf_u_int32, int);
+static struct block *gen_proto(compiler_state_t *, bpf_u_int32, int, int);
 static struct slist *xfer_to_x(compiler_state_t *, struct arth *);
 static struct slist *xfer_to_a(compiler_state_t *, struct arth *);
 static struct block *gen_mac_multicast(compiler_state_t *, int);
@@ -567,7 +582,7 @@ static struct block *gen_geneve_ll_check(compiler_state_t *cstate);
 
 static struct block *gen_ppi_dlt_check(compiler_state_t *);
 static struct block *gen_atmfield_code_internal(compiler_state_t *, int,
-    bpf_int32, bpf_u_int32, int);
+    bpf_u_int32, int, int);
 static struct block *gen_atmtype_llc(compiler_state_t *);
 static struct block *gen_msg_abbrev(compiler_state_t *, int type);
 
@@ -762,6 +777,7 @@ pcap_compile(pcap_t *p, struct bpf_program *program,
        cstate.ic.root = NULL;
        cstate.ic.cur_mark = 0;
        cstate.bpf_pcap = p;
+       cstate.error_set = 0;
        init_regs(&cstate);
 
        cstate.netmask = mask;
@@ -1013,42 +1029,42 @@ gen_not(struct block *b)
 
 static struct block *
 gen_cmp(compiler_state_t *cstate, enum e_offrel offrel, u_int offset,
-    u_int size, bpf_int32 v)
+    u_int size, bpf_u_int32 v)
 {
        return gen_ncmp(cstate, offrel, offset, size, 0xffffffff, BPF_JEQ, 0, v);
 }
 
 static struct block *
 gen_cmp_gt(compiler_state_t *cstate, enum e_offrel offrel, u_int offset,
-    u_int size, bpf_int32 v)
+    u_int size, bpf_u_int32 v)
 {
        return gen_ncmp(cstate, offrel, offset, size, 0xffffffff, BPF_JGT, 0, v);
 }
 
 static struct block *
 gen_cmp_ge(compiler_state_t *cstate, enum e_offrel offrel, u_int offset,
-    u_int size, bpf_int32 v)
+    u_int size, bpf_u_int32 v)
 {
        return gen_ncmp(cstate, offrel, offset, size, 0xffffffff, BPF_JGE, 0, v);
 }
 
 static struct block *
 gen_cmp_lt(compiler_state_t *cstate, enum e_offrel offrel, u_int offset,
-    u_int size, bpf_int32 v)
+    u_int size, bpf_u_int32 v)
 {
        return gen_ncmp(cstate, offrel, offset, size, 0xffffffff, BPF_JGE, 1, v);
 }
 
 static struct block *
 gen_cmp_le(compiler_state_t *cstate, enum e_offrel offrel, u_int offset,
-    u_int size, bpf_int32 v)
+    u_int size, bpf_u_int32 v)
 {
        return gen_ncmp(cstate, offrel, offset, size, 0xffffffff, BPF_JGT, 1, v);
 }
 
 static struct block *
 gen_mcmp(compiler_state_t *cstate, enum e_offrel offrel, u_int offset,
-    u_int size, bpf_int32 v, bpf_u_int32 mask)
+    u_int size, bpf_u_int32 v, bpf_u_int32 mask)
 {
        return gen_ncmp(cstate, offrel, offset, size, mask, BPF_JEQ, 0, v);
 }
@@ -1059,22 +1075,12 @@ gen_bcmp(compiler_state_t *cstate, enum e_offrel offrel, u_int offset,
 {
        register struct block *b, *tmp;
 
-       /*
-        * XXX - the actual *instructions* do unsigned comparisons on
-        * most platforms, and the load instructions don't do sign
-        * extension, so gen_cmp() should really take an unsigned
-        * value argument.
-        *
-        * As the load instructons also don't do sign-extension, we
-        * fetch the values from the byte array as unsigned.  We don't
-        * want to use the signed versions of the extract calls.
-        */
        b = NULL;
        while (size >= 4) {
                register const u_char *p = &v[size - 4];
 
                tmp = gen_cmp(cstate, offrel, offset + size - 4, BPF_W,
-                   (bpf_int32)EXTRACT_BE_U_4(p));
+                   EXTRACT_BE_U_4(p));
                if (b != NULL)
                        gen_and(b, tmp);
                b = tmp;
@@ -1084,14 +1090,14 @@ gen_bcmp(compiler_state_t *cstate, enum e_offrel offrel, u_int offset,
                register const u_char *p = &v[size - 2];
 
                tmp = gen_cmp(cstate, offrel, offset + size - 2, BPF_H,
-                   (bpf_int32)EXTRACT_BE_U_2(p));
+                   EXTRACT_BE_U_2(p));
                if (b != NULL)
                        gen_and(b, tmp);
                b = tmp;
                size -= 2;
        }
        if (size > 0) {
-               tmp = gen_cmp(cstate, offrel, offset, BPF_B, (bpf_int32)v[0]);
+               tmp = gen_cmp(cstate, offrel, offset, BPF_B, v[0]);
                if (b != NULL)
                        gen_and(b, tmp);
                b = tmp;
@@ -1106,9 +1112,9 @@ gen_bcmp(compiler_state_t *cstate, enum e_offrel offrel, u_int offset,
  * should test the opposite of "jtype".
  */
 static struct block *
-gen_ncmp(compiler_state_t *cstate, enum e_offrel offrel, bpf_u_int32 offset,
-    bpf_u_int32 size, bpf_u_int32 mask, bpf_u_int32 jtype, int reverse,
-    bpf_int32 v)
+gen_ncmp(compiler_state_t *cstate, enum e_offrel offrel, u_int offset,
+    u_int size, bpf_u_int32 mask, int jtype, int reverse,
+    bpf_u_int32 v)
 {
        struct slist *s, *s2;
        struct block *b;
@@ -1955,11 +1961,11 @@ gen_false(compiler_state_t *cstate)
  * the appropriate test.
  */
 static struct block *
-gen_ether_linktype(compiler_state_t *cstate, int proto)
+gen_ether_linktype(compiler_state_t *cstate, bpf_u_int32 ll_proto)
 {
        struct block *b0, *b1;
 
-       switch (proto) {
+       switch (ll_proto) {
 
        case LLCSAP_ISONS:
        case LLCSAP_IP:
@@ -1978,8 +1984,7 @@ gen_ether_linktype(compiler_state_t *cstate, int proto)
                 */
                b0 = gen_cmp_gt(cstate, OR_LINKTYPE, 0, BPF_H, ETHERMTU);
                gen_not(b0);
-               b1 = gen_cmp(cstate, OR_LLC, 0, BPF_H, (bpf_int32)
-                            ((proto << 8) | proto));
+               b1 = gen_cmp(cstate, OR_LLC, 0, BPF_H, (ll_proto << 8) | ll_proto);
                gen_and(b0, b1);
                return b1;
 
@@ -2016,8 +2021,8 @@ gen_ether_linktype(compiler_state_t *cstate, int proto)
                 * This generates code to check both for the
                 * IPX LSAP (Ethernet_802.2) and for Ethernet_802.3.
                 */
-               b0 = gen_cmp(cstate, OR_LLC, 0, BPF_B, (bpf_int32)LLCSAP_IPX);
-               b1 = gen_cmp(cstate, OR_LLC, 0, BPF_H, (bpf_int32)0xFFFF);
+               b0 = gen_cmp(cstate, OR_LLC, 0, BPF_B, LLCSAP_IPX);
+               b1 = gen_cmp(cstate, OR_LLC, 0, BPF_H, 0xFFFF);
                gen_or(b0, b1);
 
                /*
@@ -2047,7 +2052,7 @@ gen_ether_linktype(compiler_state_t *cstate, int proto)
                 * do that before checking for the other frame
                 * types.
                 */
-               b0 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, (bpf_int32)ETHERTYPE_IPX);
+               b0 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, ETHERTYPE_IPX);
                gen_or(b0, b1);
                return b1;
 
@@ -2077,9 +2082,9 @@ gen_ether_linktype(compiler_state_t *cstate, int proto)
                 * 0x000000 (encapsulated Ethernet) and a protocol
                 * type of ETHERTYPE_AARP (Appletalk ARP).
                 */
-               if (proto == ETHERTYPE_ATALK)
+               if (ll_proto == ETHERTYPE_ATALK)
                        b1 = gen_snap(cstate, 0x080007, ETHERTYPE_ATALK);
-               else    /* proto == ETHERTYPE_AARP */
+               else    /* ll_proto == ETHERTYPE_AARP */
                        b1 = gen_snap(cstate, 0x000000, ETHERTYPE_AARP);
                gen_and(b0, b1);
 
@@ -2088,13 +2093,13 @@ gen_ether_linktype(compiler_state_t *cstate, int proto)
                 * phase 1?); we just check for the Ethernet
                 * protocol type.
                 */
-               b0 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, (bpf_int32)proto);
+               b0 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, ll_proto);
 
                gen_or(b0, b1);
                return b1;
 
        default:
-               if (proto <= ETHERMTU) {
+               if (ll_proto <= ETHERMTU) {
                        /*
                         * This is an LLC SAP value, so the frames
                         * that match would be 802.2 frames.
@@ -2105,7 +2110,7 @@ gen_ether_linktype(compiler_state_t *cstate, int proto)
                         */
                        b0 = gen_cmp_gt(cstate, OR_LINKTYPE, 0, BPF_H, ETHERMTU);
                        gen_not(b0);
-                       b1 = gen_cmp(cstate, OR_LINKTYPE, 2, BPF_B, (bpf_int32)proto);
+                       b1 = gen_cmp(cstate, OR_LINKTYPE, 2, BPF_B, ll_proto);
                        gen_and(b0, b1);
                        return b1;
                } else {
@@ -2114,18 +2119,17 @@ gen_ether_linktype(compiler_state_t *cstate, int proto)
                         * the length/type field with it (if
                         * the frame is an 802.2 frame, the length
                         * field will be <= ETHERMTU, and, as
-                        * "proto" is > ETHERMTU, this test
+                        * "ll_proto" is > ETHERMTU, this test
                         * will fail and the frame won't match,
                         * which is what we want).
                         */
-                       return gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H,
-                           (bpf_int32)proto);
+                       return gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, ll_proto);
                }
        }
 }
 
 static struct block *
-gen_loopback_linktype(compiler_state_t *cstate, int proto)
+gen_loopback_linktype(compiler_state_t *cstate, bpf_u_int32 ll_proto)
 {
        /*
         * For DLT_NULL, the link-layer header is a 32-bit word
@@ -2153,10 +2157,10 @@ gen_loopback_linktype(compiler_state_t *cstate, int proto)
                 * code to compare against the result.
                 */
                if (cstate->bpf_pcap->rfile != NULL && cstate->bpf_pcap->swapped)
-                       proto = SWAPLONG(proto);
-               proto = htonl(proto);
+                       ll_proto = SWAPLONG(ll_proto);
+               ll_proto = htonl(ll_proto);
        }
-       return (gen_cmp(cstate, OR_LINKHDR, 0, BPF_W, (bpf_int32)proto));
+       return (gen_cmp(cstate, OR_LINKHDR, 0, BPF_W, ll_proto));
 }
 
 /*
@@ -2164,17 +2168,16 @@ gen_loopback_linktype(compiler_state_t *cstate, int proto)
  * or IPv6 then we have an error.
  */
 static struct block *
-gen_ipnet_linktype(compiler_state_t *cstate, int proto)
+gen_ipnet_linktype(compiler_state_t *cstate, bpf_u_int32 ll_proto)
 {
-       switch (proto) {
+       switch (ll_proto) {
 
        case ETHERTYPE_IP:
-               return gen_cmp(cstate, OR_LINKTYPE, 0, BPF_B, (bpf_int32)IPH_AF_INET);
+               return gen_cmp(cstate, OR_LINKTYPE, 0, BPF_B, IPH_AF_INET);
                /*NOTREACHED*/
 
        case ETHERTYPE_IPV6:
-               return gen_cmp(cstate, OR_LINKTYPE, 0, BPF_B,
-                   (bpf_int32)IPH_AF_INET6);
+               return gen_cmp(cstate, OR_LINKTYPE, 0, BPF_B, IPH_AF_INET6);
                /*NOTREACHED*/
 
        default:
@@ -2187,17 +2190,17 @@ gen_ipnet_linktype(compiler_state_t *cstate, int proto)
 /*
  * Generate code to match a particular packet type.
  *
- * "proto" is an Ethernet type value, if > ETHERMTU, or an LLC SAP
+ * "ll_proto" is an Ethernet type value, if > ETHERMTU, or an LLC SAP
  * value, if <= ETHERMTU.  We use that to determine whether to
  * match the type field or to check the type field for the special
  * LINUX_SLL_P_802_2 value and then do the appropriate test.
  */
 static struct block *
-gen_linux_sll_linktype(compiler_state_t *cstate, int proto)
+gen_linux_sll_linktype(compiler_state_t *cstate, bpf_u_int32 ll_proto)
 {
        struct block *b0, *b1;
 
-       switch (proto) {
+       switch (ll_proto) {
 
        case LLCSAP_ISONS:
        case LLCSAP_IP:
@@ -2215,8 +2218,7 @@ gen_linux_sll_linktype(compiler_state_t *cstate, int proto)
                 * (i.e., other SAP values)?
                 */
                b0 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, LINUX_SLL_P_802_2);
-               b1 = gen_cmp(cstate, OR_LLC, 0, BPF_H, (bpf_int32)
-                            ((proto << 8) | proto));
+               b1 = gen_cmp(cstate, OR_LLC, 0, BPF_H, (ll_proto << 8) | ll_proto);
                gen_and(b0, b1);
                return b1;
 
@@ -2246,7 +2248,7 @@ gen_linux_sll_linktype(compiler_state_t *cstate, int proto)
                 * then put a check for LINUX_SLL_P_802_2 frames
                 * before it.
                 */
-               b0 = gen_cmp(cstate, OR_LLC, 0, BPF_B, (bpf_int32)LLCSAP_IPX);
+               b0 = gen_cmp(cstate, OR_LLC, 0, BPF_B, LLCSAP_IPX);
                b1 = gen_snap(cstate, 0x000000, ETHERTYPE_IPX);
                gen_or(b0, b1);
                b0 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, LINUX_SLL_P_802_2);
@@ -2264,7 +2266,7 @@ gen_linux_sll_linktype(compiler_state_t *cstate, int proto)
                 * do that before checking for the other frame
                 * types.
                 */
-               b0 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, (bpf_int32)ETHERTYPE_IPX);
+               b0 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, ETHERTYPE_IPX);
                gen_or(b0, b1);
                return b1;
 
@@ -2293,9 +2295,9 @@ gen_linux_sll_linktype(compiler_state_t *cstate, int proto)
                 * 0x000000 (encapsulated Ethernet) and a protocol
                 * type of ETHERTYPE_AARP (Appletalk ARP).
                 */
-               if (proto == ETHERTYPE_ATALK)
+               if (ll_proto == ETHERTYPE_ATALK)
                        b1 = gen_snap(cstate, 0x080007, ETHERTYPE_ATALK);
-               else    /* proto == ETHERTYPE_AARP */
+               else    /* ll_proto == ETHERTYPE_AARP */
                        b1 = gen_snap(cstate, 0x000000, ETHERTYPE_AARP);
                gen_and(b0, b1);
 
@@ -2304,13 +2306,13 @@ gen_linux_sll_linktype(compiler_state_t *cstate, int proto)
                 * phase 1?); we just check for the Ethernet
                 * protocol type.
                 */
-               b0 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, (bpf_int32)proto);
+               b0 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, ll_proto);
 
                gen_or(b0, b1);
                return b1;
 
        default:
-               if (proto <= ETHERMTU) {
+               if (ll_proto <= ETHERMTU) {
                        /*
                         * This is an LLC SAP value, so the frames
                         * that match would be 802.2 frames.
@@ -2320,7 +2322,7 @@ gen_linux_sll_linktype(compiler_state_t *cstate, int proto)
                         */
                        b0 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, LINUX_SLL_P_802_2);
                        b1 = gen_cmp(cstate, OR_LINKHDR, cstate->off_linkpl.constant_part, BPF_B,
-                            (bpf_int32)proto);
+                            ll_proto);
                        gen_and(b0, b1);
                        return b1;
                } else {
@@ -2329,11 +2331,11 @@ gen_linux_sll_linktype(compiler_state_t *cstate, int proto)
                         * the length/type field with it (if
                         * the frame is an 802.2 frame, the length
                         * field will be <= ETHERMTU, and, as
-                        * "proto" is > ETHERMTU, this test
+                        * "ll_proto" is > ETHERMTU, this test
                         * will fail and the frame won't match,
                         * which is what we want).
                         */
-                       return gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, (bpf_int32)proto);
+                       return gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, ll_proto);
                }
        }
 }
@@ -3034,33 +3036,33 @@ gen_abs_offset_varpart(compiler_state_t *cstate, bpf_abs_offset *off)
 /*
  * Map an Ethernet type to the equivalent PPP type.
  */
-static int
-ethertype_to_ppptype(int proto)
+static bpf_u_int32
+ethertype_to_ppptype(bpf_u_int32 ll_proto)
 {
-       switch (proto) {
+       switch (ll_proto) {
 
        case ETHERTYPE_IP:
-               proto = PPP_IP;
+               ll_proto = PPP_IP;
                break;
 
        case ETHERTYPE_IPV6:
-               proto = PPP_IPV6;
+               ll_proto = PPP_IPV6;
                break;
 
        case ETHERTYPE_DN:
-               proto = PPP_DECNET;
+               ll_proto = PPP_DECNET;
                break;
 
        case ETHERTYPE_ATALK:
-               proto = PPP_APPLE;
+               ll_proto = PPP_APPLE;
                break;
 
        case ETHERTYPE_NS:
-               proto = PPP_NS;
+               ll_proto = PPP_NS;
                break;
 
        case LLCSAP_ISONS:
-               proto = PPP_OSI;
+               ll_proto = PPP_OSI;
                break;
 
        case LLCSAP_8021D:
@@ -3069,14 +3071,14 @@ ethertype_to_ppptype(int proto)
                 * over PPP are Spanning Tree Protocol
                 * Bridging PDUs.
                 */
-               proto = PPP_BRPDU;
+               ll_proto = PPP_BRPDU;
                break;
 
        case LLCSAP_IPX:
-               proto = PPP_IPX;
+               ll_proto = PPP_IPX;
                break;
        }
-       return (proto);
+       return (ll_proto);
 }
 
 /*
@@ -3132,29 +3134,14 @@ gen_prevlinkhdr_check(compiler_state_t *cstate)
  * value, if <= ETHERMTU.
  */
 static struct block *
-gen_linktype(compiler_state_t *cstate, int proto)
+gen_linktype(compiler_state_t *cstate, bpf_u_int32 ll_proto)
 {
        struct block *b0, *b1, *b2;
        const char *description;
 
        /* are we checking MPLS-encapsulated packets? */
-       if (cstate->label_stack_depth > 0) {
-               switch (proto) {
-               case ETHERTYPE_IP:
-               case PPP_IP:
-                       /* FIXME add other L3 proto IDs */
-                       return gen_mpls_linktype(cstate, Q_IP);
-
-               case ETHERTYPE_IPV6:
-               case PPP_IPV6:
-                       /* FIXME add other L3 proto IDs */
-                       return gen_mpls_linktype(cstate, Q_IPV6);
-
-               default:
-                       bpf_error(cstate, "unsupported protocol over mpls");
-                       /*NOTREACHED*/
-               }
-       }
+       if (cstate->label_stack_depth > 0)
+               return gen_mpls_linktype(cstate, ll_proto);
 
        switch (cstate->linktype) {
 
@@ -3168,21 +3155,21 @@ gen_linktype(compiler_state_t *cstate, int proto)
                else
                        b0 = NULL;
 
-               b1 = gen_ether_linktype(cstate, proto);
+               b1 = gen_ether_linktype(cstate, ll_proto);
                if (b0 != NULL)
                        gen_and(b0, b1);
                return b1;
                /*NOTREACHED*/
 
        case DLT_C_HDLC:
-               switch (proto) {
+               switch (ll_proto) {
 
                case LLCSAP_ISONS:
-                       proto = (proto << 8 | LLCSAP_ISONS);
+                       ll_proto = (ll_proto << 8 | LLCSAP_ISONS);
                        /* fall through */
 
                default:
-                       return gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, (bpf_int32)proto);
+                       return gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, ll_proto);
                        /*NOTREACHED*/
                }
 
@@ -3199,7 +3186,7 @@ gen_linktype(compiler_state_t *cstate, int proto)
                /*
                 * Now check for the specified link-layer type.
                 */
-               b1 = gen_llc_linktype(cstate, proto);
+               b1 = gen_llc_linktype(cstate, ll_proto);
                gen_and(b0, b1);
                return b1;
                /*NOTREACHED*/
@@ -3208,20 +3195,20 @@ gen_linktype(compiler_state_t *cstate, int proto)
                /*
                 * XXX - check for LLC frames.
                 */
-               return gen_llc_linktype(cstate, proto);
+               return gen_llc_linktype(cstate, ll_proto);
                /*NOTREACHED*/
 
        case DLT_IEEE802:
                /*
                 * XXX - check for LLC PDUs, as per IEEE 802.5.
                 */
-               return gen_llc_linktype(cstate, proto);
+               return gen_llc_linktype(cstate, ll_proto);
                /*NOTREACHED*/
 
        case DLT_ATM_RFC1483:
        case DLT_ATM_CLIP:
        case DLT_IP_OVER_FC:
-               return gen_llc_linktype(cstate, proto);
+               return gen_llc_linktype(cstate, ll_proto);
                /*NOTREACHED*/
 
        case DLT_SUNATM:
@@ -3233,13 +3220,13 @@ gen_linktype(compiler_state_t *cstate, int proto)
                 * Check for LLC encapsulation and then check the protocol.
                 */
                b0 = gen_atmfield_code_internal(cstate, A_PROTOTYPE, PT_LLC, BPF_JEQ, 0);
-               b1 = gen_llc_linktype(cstate, proto);
+               b1 = gen_llc_linktype(cstate, ll_proto);
                gen_and(b0, b1);
                return b1;
                /*NOTREACHED*/
 
        case DLT_LINUX_SLL:
-               return gen_linux_sll_linktype(cstate, proto);
+               return gen_linux_sll_linktype(cstate, ll_proto);
                /*NOTREACHED*/
 
        case DLT_SLIP:
@@ -3252,7 +3239,7 @@ gen_linktype(compiler_state_t *cstate, int proto)
                 * XXX - for IPv4, check for a version number of 4, and,
                 * for IPv6, check for a version number of 6?
                 */
-               switch (proto) {
+               switch (ll_proto) {
 
                case ETHERTYPE_IP:
                        /* Check for a version number of 4. */
@@ -3271,7 +3258,7 @@ gen_linktype(compiler_state_t *cstate, int proto)
                /*
                 * Raw IPv4, so no type field.
                 */
-               if (proto == ETHERTYPE_IP)
+               if (ll_proto == ETHERTYPE_IP)
                        return gen_true(cstate);        /* always true */
 
                /* Checking for something other than IPv4; always false */
@@ -3282,7 +3269,7 @@ gen_linktype(compiler_state_t *cstate, int proto)
                /*
                 * Raw IPv6, so no type field.
                 */
-               if (proto == ETHERTYPE_IPV6)
+               if (ll_proto == ETHERTYPE_IPV6)
                        return gen_true(cstate);        /* always true */
 
                /* Checking for something other than IPv6; always false */
@@ -3297,8 +3284,8 @@ gen_linktype(compiler_state_t *cstate, int proto)
                 * We use Ethernet protocol types inside libpcap;
                 * map them to the corresponding PPP protocol types.
                 */
-               proto = ethertype_to_ppptype(proto);
-               return gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, (bpf_int32)proto);
+               return gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H,
+                   ethertype_to_ppptype(ll_proto));
                /*NOTREACHED*/
 
        case DLT_PPP_BSDOS:
@@ -3306,7 +3293,7 @@ gen_linktype(compiler_state_t *cstate, int proto)
                 * We use Ethernet protocol types inside libpcap;
                 * map them to the corresponding PPP protocol types.
                 */
-               switch (proto) {
+               switch (ll_proto) {
 
                case ETHERTYPE_IP:
                        /*
@@ -3321,16 +3308,15 @@ gen_linktype(compiler_state_t *cstate, int proto)
                        return b0;
 
                default:
-                       proto = ethertype_to_ppptype(proto);
                        return gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H,
-                               (bpf_int32)proto);
+                           ethertype_to_ppptype(ll_proto));
                }
                /*NOTREACHED*/
 
        case DLT_NULL:
        case DLT_LOOP:
        case DLT_ENC:
-               switch (proto) {
+               switch (ll_proto) {
 
                case ETHERTYPE_IP:
                        return (gen_loopback_linktype(cstate, AF_INET));
@@ -3411,12 +3397,12 @@ gen_linktype(compiler_state_t *cstate, int proto)
                 * af field is host byte order in contrast to the rest of
                 * the packet.
                 */
-               if (proto == ETHERTYPE_IP)
+               if (ll_proto == ETHERTYPE_IP)
                        return (gen_cmp(cstate, OR_LINKHDR, offsetof(struct pfloghdr, af),
-                           BPF_B, (bpf_int32)AF_INET));
-               else if (proto == ETHERTYPE_IPV6)
+                           BPF_B, AF_INET));
+               else if (ll_proto == ETHERTYPE_IPV6)
                        return (gen_cmp(cstate, OR_LINKHDR, offsetof(struct pfloghdr, af),
-                           BPF_B, (bpf_int32)AF_INET6));
+                           BPF_B, AF_INET6));
                else
                        return gen_false(cstate);
                /*NOTREACHED*/
@@ -3428,43 +3414,43 @@ gen_linktype(compiler_state_t *cstate, int proto)
                 * XXX should we check for first fragment if the protocol
                 * uses PHDS?
                 */
-               switch (proto) {
+               switch (ll_proto) {
 
                default:
                        return gen_false(cstate);
 
                case ETHERTYPE_IPV6:
                        return (gen_cmp(cstate, OR_LINKTYPE, 0, BPF_B,
-                               (bpf_int32)ARCTYPE_INET6));
+                               ARCTYPE_INET6));
 
                case ETHERTYPE_IP:
                        b0 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_B,
-                                    (bpf_int32)ARCTYPE_IP);
+                           ARCTYPE_IP);
                        b1 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_B,
-                                    (bpf_int32)ARCTYPE_IP_OLD);
+                           ARCTYPE_IP_OLD);
                        gen_or(b0, b1);
                        return (b1);
 
                case ETHERTYPE_ARP:
                        b0 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_B,
-                                    (bpf_int32)ARCTYPE_ARP);
+                           ARCTYPE_ARP);
                        b1 = gen_cmp(cstate, OR_LINKTYPE, 0, BPF_B,
-                                    (bpf_int32)ARCTYPE_ARP_OLD);
+                           ARCTYPE_ARP_OLD);
                        gen_or(b0, b1);
                        return (b1);
 
                case ETHERTYPE_REVARP:
                        return (gen_cmp(cstate, OR_LINKTYPE, 0, BPF_B,
-                                       (bpf_int32)ARCTYPE_REVARP));
+                           ARCTYPE_REVARP));
 
                case ETHERTYPE_ATALK:
                        return (gen_cmp(cstate, OR_LINKTYPE, 0, BPF_B,
-                                       (bpf_int32)ARCTYPE_ATALK));
+                           ARCTYPE_ATALK));
                }
                /*NOTREACHED*/
 
        case DLT_LTALK:
-               switch (proto) {
+               switch (ll_proto) {
                case ETHERTYPE_ATALK:
                        return gen_true(cstate);
                default:
@@ -3477,7 +3463,7 @@ gen_linktype(compiler_state_t *cstate, int proto)
                 * XXX - assumes a 2-byte Frame Relay header with
                 * DLCI and flags.  What if the address is longer?
                 */
-               switch (proto) {
+               switch (ll_proto) {
 
                case ETHERTYPE_IP:
                        /*
@@ -3554,7 +3540,7 @@ gen_linktype(compiler_state_t *cstate, int proto)
                return gen_mcmp(cstate, OR_LINKHDR, 0, BPF_W, 0x55FF0000, 0xffff0000);
 
        case DLT_IPNET:
-               return gen_ipnet_linktype(cstate, proto);
+               return gen_ipnet_linktype(cstate, ll_proto);
 
        case DLT_LINUX_IRDA:
                bpf_error(cstate, "IrDA link-layer type filtering not implemented");
@@ -3630,7 +3616,7 @@ gen_linktype(compiler_state_t *cstate, int proto)
                         * it's not, it needs to be handled specially
                         * above.)
                         */
-                       return gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, (bpf_int32)proto);
+                       return gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, ll_proto);
                        /*NOTREACHED */
                } else {
                        /*
@@ -3694,7 +3680,7 @@ gen_llc_internal(compiler_state_t *cstate)
                 * Now check for the purported DSAP and SSAP not being
                 * 0xFF, to rule out NetWare-over-802.3.
                 */
-               b1 = gen_cmp(cstate, OR_LLC, 0, BPF_H, (bpf_int32)0xFFFF);
+               b1 = gen_cmp(cstate, OR_LLC, 0, BPF_H, 0xFFFF);
                gen_not(b1);
                gen_and(b0, b1);
                return b1;
@@ -3905,12 +3891,12 @@ gen_llc_u_subtype(compiler_state_t *cstate, bpf_u_int32 subtype)
  * protocol ID in a SNAP header.
  */
 static struct block *
-gen_llc_linktype(compiler_state_t *cstate, int proto)
+gen_llc_linktype(compiler_state_t *cstate, bpf_u_int32 ll_proto)
 {
        /*
         * XXX - handle token-ring variable-length header.
         */
-       switch (proto) {
+       switch (ll_proto) {
 
        case LLCSAP_IP:
        case LLCSAP_ISONS:
@@ -3921,15 +3907,14 @@ gen_llc_linktype(compiler_state_t *cstate, int proto)
                 * DSAP, as we do for other SAP values?
                 */
                return gen_cmp(cstate, OR_LLC, 0, BPF_H, (bpf_u_int32)
-                            ((proto << 8) | proto));
+                            ((ll_proto << 8) | ll_proto));
 
        case LLCSAP_IPX:
                /*
                 * XXX - are there ever SNAP frames for IPX on
                 * non-Ethernet 802.x networks?
                 */
-               return gen_cmp(cstate, OR_LLC, 0, BPF_B,
-                   (bpf_int32)LLCSAP_IPX);
+               return gen_cmp(cstate, OR_LLC, 0, BPF_B, LLCSAP_IPX);
 
        case ETHERTYPE_ATALK:
                /*
@@ -3948,12 +3933,12 @@ gen_llc_linktype(compiler_state_t *cstate, int proto)
                 * XXX - we don't have to check for IPX 802.3
                 * here, but should we check for the IPX Ethertype?
                 */
-               if (proto <= ETHERMTU) {
+               if (ll_proto <= ETHERMTU) {
                        /*
                         * This is an LLC SAP value, so check
                         * the DSAP.
                         */
-                       return gen_cmp(cstate, OR_LLC, 0, BPF_B, (bpf_int32)proto);
+                       return gen_cmp(cstate, OR_LLC, 0, BPF_B, ll_proto);
                } else {
                        /*
                         * This is an Ethernet type; we assume that it's
@@ -3968,20 +3953,20 @@ gen_llc_linktype(compiler_state_t *cstate, int proto)
                         * organization code of 0x000000 (encapsulated
                         * Ethernet), we'd do
                         *
-                        *      return gen_snap(cstate, 0x000000, proto);
+                        *      return gen_snap(cstate, 0x000000, ll_proto);
                         *
                         * here; for now, we don't, as per the above.
                         * I don't know whether it's worth the extra CPU
                         * time to do the right check or not.
                         */
-                       return gen_cmp(cstate, OR_LLC, 6, BPF_H, (bpf_int32)proto);
+                       return gen_cmp(cstate, OR_LLC, 6, BPF_H, ll_proto);
                }
        }
 }
 
 static struct block *
 gen_hostop(compiler_state_t *cstate, bpf_u_int32 addr, bpf_u_int32 mask,
-    int dir, int proto, u_int src_off, u_int dst_off)
+    int dir, bpf_u_int32 ll_proto, u_int src_off, u_int dst_off)
 {
        struct block *b0, *b1;
        u_int offset;
@@ -3997,15 +3982,15 @@ gen_hostop(compiler_state_t *cstate, bpf_u_int32 addr, bpf_u_int32 mask,
                break;
 
        case Q_AND:
-               b0 = gen_hostop(cstate, addr, mask, Q_SRC, proto, src_off, dst_off);
-               b1 = gen_hostop(cstate, addr, mask, Q_DST, proto, src_off, dst_off);
+               b0 = gen_hostop(cstate, addr, mask, Q_SRC, ll_proto, src_off, dst_off);
+               b1 = gen_hostop(cstate, addr, mask, Q_DST, ll_proto, src_off, dst_off);
                gen_and(b0, b1);
                return b1;
 
        case Q_DEFAULT:
        case Q_OR:
-               b0 = gen_hostop(cstate, addr, mask, Q_SRC, proto, src_off, dst_off);
-               b1 = gen_hostop(cstate, addr, mask, Q_DST, proto, src_off, dst_off);
+               b0 = gen_hostop(cstate, addr, mask, Q_SRC, ll_proto, src_off, dst_off);
+               b1 = gen_hostop(cstate, addr, mask, Q_DST, ll_proto, src_off, dst_off);
                gen_or(b0, b1);
                return b1;
 
@@ -4037,8 +4022,8 @@ gen_hostop(compiler_state_t *cstate, bpf_u_int32 addr, bpf_u_int32 mask,
                abort();
                /*NOTREACHED*/
        }
-       b0 = gen_linktype(cstate, proto);
-       b1 = gen_mcmp(cstate, OR_LINKPL, offset, BPF_W, (bpf_int32)addr, mask);
+       b0 = gen_linktype(cstate, ll_proto);
+       b1 = gen_mcmp(cstate, OR_LINKPL, offset, BPF_W, addr, mask);
        gen_and(b0, b1);
        return b1;
 }
@@ -4046,7 +4031,8 @@ gen_hostop(compiler_state_t *cstate, bpf_u_int32 addr, bpf_u_int32 mask,
 #ifdef INET6
 static struct block *
 gen_hostop6(compiler_state_t *cstate, struct in6_addr *addr,
-    struct in6_addr *mask, int dir, int proto, u_int src_off, u_int dst_off)
+    struct in6_addr *mask, int dir, bpf_u_int32 ll_proto, u_int src_off,
+    u_int dst_off)
 {
        struct block *b0, *b1;
        u_int offset;
@@ -4063,15 +4049,15 @@ gen_hostop6(compiler_state_t *cstate, struct in6_addr *addr,
                break;
 
        case Q_AND:
-               b0 = gen_hostop6(cstate, addr, mask, Q_SRC, proto, src_off, dst_off);
-               b1 = gen_hostop6(cstate, addr, mask, Q_DST, proto, src_off, dst_off);
+               b0 = gen_hostop6(cstate, addr, mask, Q_SRC, ll_proto, src_off, dst_off);
+               b1 = gen_hostop6(cstate, addr, mask, Q_DST, ll_proto, src_off, dst_off);
                gen_and(b0, b1);
                return b1;
 
        case Q_DEFAULT:
        case Q_OR:
-               b0 = gen_hostop6(cstate, addr, mask, Q_SRC, proto, src_off, dst_off);
-               b1 = gen_hostop6(cstate, addr, mask, Q_DST, proto, src_off, dst_off);
+               b0 = gen_hostop6(cstate, addr, mask, Q_SRC, ll_proto, src_off, dst_off);
+               b1 = gen_hostop6(cstate, addr, mask, Q_DST, ll_proto, src_off, dst_off);
                gen_or(b0, b1);
                return b1;
 
@@ -4113,7 +4099,7 @@ gen_hostop6(compiler_state_t *cstate, struct in6_addr *addr,
        gen_and(b0, b1);
        b0 = gen_mcmp(cstate, OR_LINKPL, offset + 0, BPF_W, ntohl(a[0]), ntohl(m[0]));
        gen_and(b0, b1);
-       b0 = gen_linktype(cstate, proto);
+       b0 = gen_linktype(cstate, ll_proto);
        gen_and(b0, b1);
        return b1;
 }
@@ -4848,24 +4834,29 @@ gen_dnhostop(compiler_state_t *cstate, bpf_u_int32 addr, int dir)
        b0 = gen_linktype(cstate, ETHERTYPE_DN);
        /* Check for pad = 1, long header case */
        tmp = gen_mcmp(cstate, OR_LINKPL, 2, BPF_H,
-           (bpf_int32)ntohs(0x0681), (bpf_int32)ntohs(0x07FF));
+           (bpf_u_int32)ntohs(0x0681), (bpf_u_int32)ntohs(0x07FF));
        b1 = gen_cmp(cstate, OR_LINKPL, 2 + 1 + offset_lh,
-           BPF_H, (bpf_int32)ntohs((u_short)addr));
+           BPF_H, (bpf_u_int32)ntohs((u_short)addr));
        gen_and(tmp, b1);
        /* Check for pad = 0, long header case */
-       tmp = gen_mcmp(cstate, OR_LINKPL, 2, BPF_B, (bpf_int32)0x06, (bpf_int32)0x7);
-       b2 = gen_cmp(cstate, OR_LINKPL, 2 + offset_lh, BPF_H, (bpf_int32)ntohs((u_short)addr));
+       tmp = gen_mcmp(cstate, OR_LINKPL, 2, BPF_B, (bpf_u_int32)0x06,
+           (bpf_u_int32)0x7);
+       b2 = gen_cmp(cstate, OR_LINKPL, 2 + offset_lh, BPF_H,
+           (bpf_u_int32)ntohs((u_short)addr));
        gen_and(tmp, b2);
        gen_or(b2, b1);
        /* Check for pad = 1, short header case */
        tmp = gen_mcmp(cstate, OR_LINKPL, 2, BPF_H,
-           (bpf_int32)ntohs(0x0281), (bpf_int32)ntohs(0x07FF));
-       b2 = gen_cmp(cstate, OR_LINKPL, 2 + 1 + offset_sh, BPF_H, (bpf_int32)ntohs((u_short)addr));
+           (bpf_u_int32)ntohs(0x0281), (bpf_u_int32)ntohs(0x07FF));
+       b2 = gen_cmp(cstate, OR_LINKPL, 2 + 1 + offset_sh, BPF_H,
+           (bpf_u_int32)ntohs((u_short)addr));
        gen_and(tmp, b2);
        gen_or(b2, b1);
        /* Check for pad = 0, short header case */
-       tmp = gen_mcmp(cstate, OR_LINKPL, 2, BPF_B, (bpf_int32)0x02, (bpf_int32)0x7);
-       b2 = gen_cmp(cstate, OR_LINKPL, 2 + offset_sh, BPF_H, (bpf_int32)ntohs((u_short)addr));
+       tmp = gen_mcmp(cstate, OR_LINKPL, 2, BPF_B, (bpf_u_int32)0x02,
+           (bpf_u_int32)0x7);
+       b2 = gen_cmp(cstate, OR_LINKPL, 2 + offset_sh, BPF_H,
+           (bpf_u_int32)ntohs((u_short)addr));
        gen_and(tmp, b2);
        gen_or(b2, b1);
 
@@ -4880,13 +4871,13 @@ gen_dnhostop(compiler_state_t *cstate, bpf_u_int32 addr, int dir)
  * field in the IP header.
  */
 static struct block *
-gen_mpls_linktype(compiler_state_t *cstate, int proto)
+gen_mpls_linktype(compiler_state_t *cstate, bpf_u_int32 ll_proto)
 {
        struct block *b0, *b1;
 
-        switch (proto) {
+        switch (ll_proto) {
 
-        case Q_IP:
+        case ETHERTYPE_IP:
                 /* match the bottom-of-stack bit */
                 b0 = gen_mcmp(cstate, OR_LINKPL, (u_int)-2, BPF_B, 0x01, 0x01);
                 /* match the IPv4 version number */
@@ -4894,7 +4885,7 @@ gen_mpls_linktype(compiler_state_t *cstate, int proto)
                 gen_and(b0, b1);
                 return b1;
 
-       case Q_IPV6:
+        case ETHERTYPE_IPV6:
                 /* match the bottom-of-stack bit */
                 b0 = gen_mcmp(cstate, OR_LINKPL, (u_int)-2, BPF_B, 0x01, 0x01);
                 /* match the IPv4 version number */
@@ -4902,8 +4893,10 @@ gen_mpls_linktype(compiler_state_t *cstate, int proto)
                 gen_and(b0, b1);
                 return b1;
 
-       default:
-                abort();
+        default:
+               /* FIXME add other L3 proto IDs */
+               bpf_error(cstate, "unsupported protocol over mpls");
+               /*NOTREACHED*/
         }
 }
 
@@ -5585,46 +5578,46 @@ gen_ipfrag(compiler_state_t *cstate)
  * headers).
  */
 static struct block *
-gen_portatom(compiler_state_t *cstate, int off, bpf_int32 v)
+gen_portatom(compiler_state_t *cstate, int off, bpf_u_int32 v)
 {
        return gen_cmp(cstate, OR_TRAN_IPV4, off, BPF_H, v);
 }
 
 static struct block *
-gen_portatom6(compiler_state_t *cstate, int off, bpf_int32 v)
+gen_portatom6(compiler_state_t *cstate, int off, bpf_u_int32 v)
 {
        return gen_cmp(cstate, OR_TRAN_IPV6, off, BPF_H, v);
 }
 
-struct block *
-gen_portop(compiler_state_t *cstate, int port, int proto, int dir)
+static struct block *
+gen_portop(compiler_state_t *cstate, u_int port, u_int proto, int dir)
 {
        struct block *b0, *b1, *tmp;
 
        /* ip proto 'proto' and not a fragment other than the first fragment */
-       tmp = gen_cmp(cstate, OR_LINKPL, 9, BPF_B, (bpf_int32)proto);
+       tmp = gen_cmp(cstate, OR_LINKPL, 9, BPF_B, proto);
        b0 = gen_ipfrag(cstate);
        gen_and(tmp, b0);
 
        switch (dir) {
        case Q_SRC:
-               b1 = gen_portatom(cstate, 0, (bpf_int32)port);
+               b1 = gen_portatom(cstate, 0, port);
                break;
 
        case Q_DST:
-               b1 = gen_portatom(cstate, 2, (bpf_int32)port);
+               b1 = gen_portatom(cstate, 2, port);
                break;
 
        case Q_AND:
-               tmp = gen_portatom(cstate, 0, (bpf_int32)port);
-               b1 = gen_portatom(cstate, 2, (bpf_int32)port);
+               tmp = gen_portatom(cstate, 0, port);
+               b1 = gen_portatom(cstate, 2, port);
                gen_and(tmp, b1);
                break;
 
        case Q_DEFAULT:
        case Q_OR:
-               tmp = gen_portatom(cstate, 0, (bpf_int32)port);
-               b1 = gen_portatom(cstate, 2, (bpf_int32)port);
+               tmp = gen_portatom(cstate, 0, port);
+               b1 = gen_portatom(cstate, 2, port);
                gen_or(tmp, b1);
                break;
 
@@ -5662,7 +5655,7 @@ gen_portop(compiler_state_t *cstate, int port, int proto, int dir)
 }
 
 static struct block *
-gen_port(compiler_state_t *cstate, int port, int ip_proto, int dir)
+gen_port(compiler_state_t *cstate, u_int port, int ip_proto, int dir)
 {
        struct block *b0, *b1, *tmp;
 
@@ -5689,7 +5682,7 @@ gen_port(compiler_state_t *cstate, int port, int ip_proto, int dir)
        case IPPROTO_UDP:
        case IPPROTO_TCP:
        case IPPROTO_SCTP:
-               b1 = gen_portop(cstate, port, ip_proto, dir);
+               b1 = gen_portop(cstate, port, (u_int)ip_proto, dir);
                break;
 
        case PROTO_UNDEF:
@@ -5708,33 +5701,33 @@ gen_port(compiler_state_t *cstate, int port, int ip_proto, int dir)
 }
 
 struct block *
-gen_portop6(compiler_state_t *cstate, int port, int proto, int dir)
+gen_portop6(compiler_state_t *cstate, u_int port, u_int proto, int dir)
 {
        struct block *b0, *b1, *tmp;
 
        /* ip6 proto 'proto' */
        /* XXX - catch the first fragment of a fragmented packet? */
-       b0 = gen_cmp(cstate, OR_LINKPL, 6, BPF_B, (bpf_int32)proto);
+       b0 = gen_cmp(cstate, OR_LINKPL, 6, BPF_B, proto);
 
        switch (dir) {
        case Q_SRC:
-               b1 = gen_portatom6(cstate, 0, (bpf_int32)port);
+               b1 = gen_portatom6(cstate, 0, port);
                break;
 
        case Q_DST:
-               b1 = gen_portatom6(cstate, 2, (bpf_int32)port);
+               b1 = gen_portatom6(cstate, 2, port);
                break;
 
        case Q_AND:
-               tmp = gen_portatom6(cstate, 0, (bpf_int32)port);
-               b1 = gen_portatom6(cstate, 2, (bpf_int32)port);
+               tmp = gen_portatom6(cstate, 0, port);
+               b1 = gen_portatom6(cstate, 2, port);
                gen_and(tmp, b1);
                break;
 
        case Q_DEFAULT:
        case Q_OR:
-               tmp = gen_portatom6(cstate, 0, (bpf_int32)port);
-               b1 = gen_portatom6(cstate, 2, (bpf_int32)port);
+               tmp = gen_portatom6(cstate, 0, port);
+               b1 = gen_portatom6(cstate, 2, port);
                gen_or(tmp, b1);
                break;
 
@@ -5747,7 +5740,7 @@ gen_portop6(compiler_state_t *cstate, int port, int proto, int dir)
 }
 
 static struct block *
-gen_port6(compiler_state_t *cstate, int port, int ip_proto, int dir)
+gen_port6(compiler_state_t *cstate, u_int port, int ip_proto, int dir)
 {
        struct block *b0, *b1, *tmp;
 
@@ -5758,7 +5751,7 @@ gen_port6(compiler_state_t *cstate, int port, int ip_proto, int dir)
        case IPPROTO_UDP:
        case IPPROTO_TCP:
        case IPPROTO_SCTP:
-               b1 = gen_portop6(cstate, port, ip_proto, dir);
+               b1 = gen_portop6(cstate, port, (u_int)ip_proto, dir);
                break;
 
        case PROTO_UNDEF:
@@ -5778,8 +5771,8 @@ gen_port6(compiler_state_t *cstate, int port, int ip_proto, int dir)
 
 /* gen_portrange code */
 static struct block *
-gen_portrangeatom(compiler_state_t *cstate, int off, bpf_int32 v1,
-    bpf_int32 v2)
+gen_portrangeatom(compiler_state_t *cstate, u_int off, bpf_u_int32 v1,
+    bpf_u_int32 v2)
 {
        struct block *b1, *b2;
 
@@ -5787,7 +5780,7 @@ gen_portrangeatom(compiler_state_t *cstate, int off, bpf_int32 v1,
                /*
                 * Reverse the order of the ports, so v1 is the lower one.
                 */
-               bpf_int32 vtemp;
+               bpf_u_int32 vtemp;
 
                vtemp = v1;
                v1 = v2;
@@ -5802,36 +5795,36 @@ gen_portrangeatom(compiler_state_t *cstate, int off, bpf_int32 v1,
        return b2;
 }
 
-struct block *
-gen_portrangeop(compiler_state_t *cstate, int port1, int port2, int proto,
-    int dir)
+static struct block *
+gen_portrangeop(compiler_state_t *cstate, u_int port1, u_int port2,
+    bpf_u_int32 proto, int dir)
 {
        struct block *b0, *b1, *tmp;
 
        /* ip proto 'proto' and not a fragment other than the first fragment */
-       tmp = gen_cmp(cstate, OR_LINKPL, 9, BPF_B, (bpf_int32)proto);
+       tmp = gen_cmp(cstate, OR_LINKPL, 9, BPF_B, proto);
        b0 = gen_ipfrag(cstate);
        gen_and(tmp, b0);
 
        switch (dir) {
        case Q_SRC:
-               b1 = gen_portrangeatom(cstate, 0, (bpf_int32)port1, (bpf_int32)port2);
+               b1 = gen_portrangeatom(cstate, 0, port1, port2);
                break;
 
        case Q_DST:
-               b1 = gen_portrangeatom(cstate, 2, (bpf_int32)port1, (bpf_int32)port2);
+               b1 = gen_portrangeatom(cstate, 2, port1, port2);
                break;
 
        case Q_AND:
-               tmp = gen_portrangeatom(cstate, 0, (bpf_int32)port1, (bpf_int32)port2);
-               b1 = gen_portrangeatom(cstate, 2, (bpf_int32)port1, (bpf_int32)port2);
+               tmp = gen_portrangeatom(cstate, 0, port1, port2);
+               b1 = gen_portrangeatom(cstate, 2, port1, port2);
                gen_and(tmp, b1);
                break;
 
        case Q_DEFAULT:
        case Q_OR:
-               tmp = gen_portrangeatom(cstate, 0, (bpf_int32)port1, (bpf_int32)port2);
-               b1 = gen_portrangeatom(cstate, 2, (bpf_int32)port1, (bpf_int32)port2);
+               tmp = gen_portrangeatom(cstate, 0, port1, port2);
+               b1 = gen_portrangeatom(cstate, 2, port1, port2);
                gen_or(tmp, b1);
                break;
 
@@ -5869,7 +5862,7 @@ gen_portrangeop(compiler_state_t *cstate, int port1, int port2, int proto,
 }
 
 static struct block *
-gen_portrange(compiler_state_t *cstate, int port1, int port2, int ip_proto,
+gen_portrange(compiler_state_t *cstate, u_int port1, u_int port2, int ip_proto,
     int dir)
 {
        struct block *b0, *b1, *tmp;
@@ -5881,7 +5874,8 @@ gen_portrange(compiler_state_t *cstate, int port1, int port2, int ip_proto,
        case IPPROTO_UDP:
        case IPPROTO_TCP:
        case IPPROTO_SCTP:
-               b1 = gen_portrangeop(cstate, port1, port2, ip_proto, dir);
+               b1 = gen_portrangeop(cstate, port1, port2, (bpf_u_int32)ip_proto,
+                   dir);
                break;
 
        case PROTO_UNDEF:
@@ -5900,8 +5894,8 @@ gen_portrange(compiler_state_t *cstate, int port1, int port2, int ip_proto,
 }
 
 static struct block *
-gen_portrangeatom6(compiler_state_t *cstate, int off, bpf_int32 v1,
-    bpf_int32 v2)
+gen_portrangeatom6(compiler_state_t *cstate, u_int off, bpf_u_int32 v1,
+    bpf_u_int32 v2)
 {
        struct block *b1, *b2;
 
@@ -5909,7 +5903,7 @@ gen_portrangeatom6(compiler_state_t *cstate, int off, bpf_int32 v1,
                /*
                 * Reverse the order of the ports, so v1 is the lower one.
                 */
-               bpf_int32 vtemp;
+               bpf_u_int32 vtemp;
 
                vtemp = v1;
                v1 = v2;
@@ -5924,35 +5918,35 @@ gen_portrangeatom6(compiler_state_t *cstate, int off, bpf_int32 v1,
        return b2;
 }
 
-struct block *
-gen_portrangeop6(compiler_state_t *cstate, int port1, int port2, int proto,
-    int dir)
+static struct block *
+gen_portrangeop6(compiler_state_t *cstate, u_int port1, u_int port2,
+    bpf_u_int32 proto, int dir)
 {
        struct block *b0, *b1, *tmp;
 
        /* ip6 proto 'proto' */
        /* XXX - catch the first fragment of a fragmented packet? */
-       b0 = gen_cmp(cstate, OR_LINKPL, 6, BPF_B, (bpf_int32)proto);
+       b0 = gen_cmp(cstate, OR_LINKPL, 6, BPF_B, proto);
 
        switch (dir) {
        case Q_SRC:
-               b1 = gen_portrangeatom6(cstate, 0, (bpf_int32)port1, (bpf_int32)port2);
+               b1 = gen_portrangeatom6(cstate, 0, port1, port2);
                break;
 
        case Q_DST:
-               b1 = gen_portrangeatom6(cstate, 2, (bpf_int32)port1, (bpf_int32)port2);
+               b1 = gen_portrangeatom6(cstate, 2, port1, port2);
                break;
 
        case Q_AND:
-               tmp = gen_portrangeatom6(cstate, 0, (bpf_int32)port1, (bpf_int32)port2);
-               b1 = gen_portrangeatom6(cstate, 2, (bpf_int32)port1, (bpf_int32)port2);
+               tmp = gen_portrangeatom6(cstate, 0, port1, port2);
+               b1 = gen_portrangeatom6(cstate, 2, port1, port2);
                gen_and(tmp, b1);
                break;
 
        case Q_DEFAULT:
        case Q_OR:
-               tmp = gen_portrangeatom6(cstate, 0, (bpf_int32)port1, (bpf_int32)port2);
-               b1 = gen_portrangeatom6(cstate, 2, (bpf_int32)port1, (bpf_int32)port2);
+               tmp = gen_portrangeatom6(cstate, 0, port1, port2);
+               b1 = gen_portrangeatom6(cstate, 2, port1, port2);
                gen_or(tmp, b1);
                break;
 
@@ -5965,7 +5959,7 @@ gen_portrangeop6(compiler_state_t *cstate, int port1, int port2, int proto,
 }
 
 static struct block *
-gen_portrange6(compiler_state_t *cstate, int port1, int port2, int ip_proto,
+gen_portrange6(compiler_state_t *cstate, u_int port1, u_int port2, int ip_proto,
     int dir)
 {
        struct block *b0, *b1, *tmp;
@@ -5977,7 +5971,8 @@ gen_portrange6(compiler_state_t *cstate, int port1, int port2, int ip_proto,
        case IPPROTO_UDP:
        case IPPROTO_TCP:
        case IPPROTO_SCTP:
-               b1 = gen_portrangeop6(cstate, port1, port2, ip_proto, dir);
+               b1 = gen_portrangeop6(cstate, port1, port2, (bpf_u_int32)ip_proto,
+                   dir);
                break;
 
        case PROTO_UNDEF:
@@ -6047,10 +6042,10 @@ gen_joinsp(struct stmt **s, int n)
 #endif
 
 static struct block *
-gen_protochain(compiler_state_t *cstate, int v, int proto, int dir)
+gen_protochain(compiler_state_t *cstate, bpf_u_int32 v, int proto)
 {
 #ifdef NO_PROTOCHAIN
-       return gen_proto(cstate, v, proto, dir);
+       return gen_proto(cstate, v, proto);
 #else
        struct block *b0, *b;
        struct slist *s[100];
@@ -6067,8 +6062,8 @@ gen_protochain(compiler_state_t *cstate, int v, int proto, int dir)
        case Q_IPV6:
                break;
        case Q_DEFAULT:
-               b0 = gen_protochain(cstate, v, Q_IP, dir);
-               b = gen_protochain(cstate, v, Q_IPV6, dir);
+               b0 = gen_protochain(cstate, v, Q_IP);
+               b = gen_protochain(cstate, v, Q_IPV6);
                gen_or(b0, b);
                return b;
        default:
@@ -6373,7 +6368,7 @@ gen_check_802_11_data_frame(compiler_state_t *cstate)
  * against Q_IP and Q_IPV6.
  */
 static struct block *
-gen_proto(compiler_state_t *cstate, int v, int proto, int dir)
+gen_proto(compiler_state_t *cstate, bpf_u_int32 v, int proto, int dir)
 {
        struct block *b0, *b1;
 #ifndef CHASE_CHAIN
@@ -6411,7 +6406,7 @@ gen_proto(compiler_state_t *cstate, int v, int proto, int dir)
                 */
                b0 = gen_linktype(cstate, ETHERTYPE_IP);
 #ifndef CHASE_CHAIN
-               b1 = gen_cmp(cstate, OR_LINKPL, 9, BPF_B, (bpf_int32)v);
+               b1 = gen_cmp(cstate, OR_LINKPL, 9, BPF_B, v);
 #else
                b1 = gen_protochain(cstate, v, Q_IP);
 #endif
@@ -6482,9 +6477,9 @@ gen_proto(compiler_state_t *cstate, int v, int proto, int dir)
                 * header.
                 */
                b2 = gen_cmp(cstate, OR_LINKPL, 6, BPF_B, IPPROTO_FRAGMENT);
-               b1 = gen_cmp(cstate, OR_LINKPL, 40, BPF_B, (bpf_int32)v);
+               b1 = gen_cmp(cstate, OR_LINKPL, 40, BPF_B, v);
                gen_and(b2, b1);
-               b2 = gen_cmp(cstate, OR_LINKPL, 6, BPF_B, (bpf_int32)v);
+               b2 = gen_cmp(cstate, OR_LINKPL, 6, BPF_B, v);
                gen_or(b2, b1);
 #else
                b1 = gen_protochain(cstate, v, Q_IPV6);
@@ -6548,13 +6543,13 @@ gen_proto(compiler_state_t *cstate, int v, int proto, int dir)
                         */
                        b0 = gen_linktype(cstate, LLCSAP_ISONS<<8 | LLCSAP_ISONS);
                        /* OSI in C-HDLC is stuffed with a fudge byte */
-                       b1 = gen_cmp(cstate, OR_LINKPL_NOSNAP, 1, BPF_B, (bpf_int32)v);
+                       b1 = gen_cmp(cstate, OR_LINKPL_NOSNAP, 1, BPF_B, v);
                        gen_and(b0, b1);
                        return b1;
 
                default:
                        b0 = gen_linktype(cstate, LLCSAP_ISONS);
-                       b1 = gen_cmp(cstate, OR_LINKPL_NOSNAP, 0, BPF_B, (bpf_int32)v);
+                       b1 = gen_cmp(cstate, OR_LINKPL_NOSNAP, 0, BPF_B, v);
                        gen_and(b0, b1);
                        return b1;
                }
@@ -6569,7 +6564,7 @@ gen_proto(compiler_state_t *cstate, int v, int proto, int dir)
                 * 4 is the offset of the PDU type relative to the IS-IS
                 * header.
                 */
-               b1 = gen_cmp(cstate, OR_LINKPL_NOSNAP, 4, BPF_B, (bpf_int32)v);
+               b1 = gen_cmp(cstate, OR_LINKPL_NOSNAP, 4, BPF_B, v);
                gen_and(b0, b1);
                return b1;
 
@@ -6930,7 +6925,7 @@ gen_scode(compiler_state_t *cstate, const char *name, struct qual q)
        case Q_PROTOCHAIN:
                real_proto = lookup_proto(cstate, name, proto);
                if (real_proto >= 0)
-                       return gen_protochain(cstate, real_proto, proto, dir);
+                       return gen_protochain(cstate, real_proto, proto);
                else
                        bpf_error(cstate, "unknown protocol: %s", name);
 
@@ -6944,7 +6939,7 @@ gen_scode(compiler_state_t *cstate, const char *name, struct qual q)
 
 struct block *
 gen_mcode(compiler_state_t *cstate, const char *s1, const char *s2,
-    unsigned int masklen, struct qual q)
+    bpf_u_int32 masklen, struct qual q)
 {
        register int nlen, mlen;
        bpf_u_int32 n, m;
@@ -7064,8 +7059,8 @@ gen_ncode(compiler_state_t *cstate, const char *s, bpf_u_int32 v, struct qual q)
 
            {
                struct block *b;
-               b = gen_port(cstate, (int)v, proto, dir);
-               gen_or(gen_port6(cstate, (int)v, proto, dir), b);
+               b = gen_port(cstate, v, proto, dir);
+               gen_or(gen_port6(cstate, v, proto, dir), b);
                return b;
            }
 
@@ -7086,8 +7081,8 @@ gen_ncode(compiler_state_t *cstate, const char *s, bpf_u_int32 v, struct qual q)
 
            {
                struct block *b;
-               b = gen_portrange(cstate, (int)v, (int)v, proto, dir);
-               gen_or(gen_portrange6(cstate, (int)v, (int)v, proto, dir), b);
+               b = gen_portrange(cstate, v, v, proto, dir);
+               gen_or(gen_portrange6(cstate, v, v, proto, dir), b);
                return b;
            }
 
@@ -7096,10 +7091,10 @@ gen_ncode(compiler_state_t *cstate, const char *s, bpf_u_int32 v, struct qual q)
                /*NOTREACHED*/
 
        case Q_PROTO:
-               return gen_proto(cstate, (int)v, proto, dir);
+               return gen_proto(cstate, v, proto, dir);
 
        case Q_PROTOCHAIN:
-               return gen_protochain(cstate, (int)v, proto, dir);
+               return gen_protochain(cstate, v, proto);
 
        case Q_UNDEF:
                syntax(cstate);
@@ -7115,7 +7110,7 @@ gen_ncode(compiler_state_t *cstate, const char *s, bpf_u_int32 v, struct qual q)
 #ifdef INET6
 struct block *
 gen_mcode6(compiler_state_t *cstate, const char *s1, const char *s2,
-    unsigned int masklen, struct qual q)
+    bpf_u_int32 masklen, struct qual q)
 {
        struct addrinfo *res;
        struct in6_addr *addr;
@@ -7273,8 +7268,10 @@ xfer_to_a(compiler_state_t *cstate, struct arth *a)
  * for "index".
  */
 static struct arth *
-gen_load_internal(compiler_state_t *cstate, int proto, struct arth *inst, int size)
+gen_load_internal(compiler_state_t *cstate, int proto, struct arth *inst,
+    bpf_u_int32 size)
 {
+       int size_code;
        struct slist *s, *tmp;
        struct block *b;
        int regno = alloc_reg(cstate);
@@ -7284,17 +7281,18 @@ gen_load_internal(compiler_state_t *cstate, int proto, struct arth *inst, int si
 
        default:
                bpf_error(cstate, "data size must be 1, 2, or 4");
+               /*NOTREACHED*/
 
        case 1:
-               size = BPF_B;
+               size_code = BPF_B;
                break;
 
        case 2:
-               size = BPF_H;
+               size_code = BPF_H;
                break;
 
        case 4:
-               size = BPF_W;
+               size_code = BPF_W;
                break;
        }
        switch (proto) {
@@ -7321,7 +7319,7 @@ gen_load_internal(compiler_state_t *cstate, int proto, struct arth *inst, int si
                /*
                 * Load the item at that offset.
                 */
-               tmp = new_stmt(cstate, BPF_LD|BPF_IND|size);
+               tmp = new_stmt(cstate, BPF_LD|BPF_IND|size_code);
                sappend(s, tmp);
                sappend(inst->s, s);
                break;
@@ -7363,7 +7361,7 @@ gen_load_internal(compiler_state_t *cstate, int proto, struct arth *inst, int si
                 * variable-length; that header length is what we put
                 * into the X register and then added to the index).
                 */
-               tmp = new_stmt(cstate, BPF_LD|BPF_IND|size);
+               tmp = new_stmt(cstate, BPF_LD|BPF_IND|size_code);
                tmp->s.k = cstate->off_linkhdr.constant_part;
                sappend(s, tmp);
                sappend(inst->s, s);
@@ -7410,7 +7408,7 @@ gen_load_internal(compiler_state_t *cstate, int proto, struct arth *inst, int si
                 * payload, and the constant part of the offset of the
                 * start of the link-layer payload.
                 */
-               tmp = new_stmt(cstate, BPF_LD|BPF_IND|size);
+               tmp = new_stmt(cstate, BPF_LD|BPF_IND|size_code);
                tmp->s.k = cstate->off_linkpl.constant_part + cstate->off_nl;
                sappend(s, tmp);
                sappend(inst->s, s);
@@ -7467,7 +7465,7 @@ gen_load_internal(compiler_state_t *cstate, int proto, struct arth *inst, int si
                sappend(s, xfer_to_a(cstate, inst));
                sappend(s, new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_X));
                sappend(s, new_stmt(cstate, BPF_MISC|BPF_TAX));
-               sappend(s, tmp = new_stmt(cstate, BPF_LD|BPF_IND|size));
+               sappend(s, tmp = new_stmt(cstate, BPF_LD|BPF_IND|size_code));
                tmp->s.k = cstate->off_linkpl.constant_part + cstate->off_nl;
                sappend(inst->s, s);
 
@@ -7529,7 +7527,7 @@ gen_load_internal(compiler_state_t *cstate, int proto, struct arth *inst, int si
         * payload, and the constant part of the offset of the
         * start of the link-layer payload.
         */
-        tmp = new_stmt(cstate, BPF_LD|BPF_IND|size);
+        tmp = new_stmt(cstate, BPF_LD|BPF_IND|size_code);
         tmp->s.k = cstate->off_linkpl.constant_part + cstate->off_nl + 40;
 
         sappend(s, tmp);
@@ -7546,7 +7544,8 @@ gen_load_internal(compiler_state_t *cstate, int proto, struct arth *inst, int si
 }
 
 struct arth *
-gen_load(compiler_state_t *cstate, int proto, struct arth *inst, int size)
+gen_load(compiler_state_t *cstate, int proto, struct arth *inst,
+    bpf_u_int32 size)
 {
        /*
         * Catch errors reported by us and routines below us, and return NULL
@@ -7642,7 +7641,7 @@ gen_loadlen(compiler_state_t *cstate)
 }
 
 static struct arth *
-gen_loadi_internal(compiler_state_t *cstate, int val)
+gen_loadi_internal(compiler_state_t *cstate, bpf_u_int32 val)
 {
        struct arth *a;
        struct slist *s;
@@ -7663,7 +7662,7 @@ gen_loadi_internal(compiler_state_t *cstate, int val)
 }
 
 struct arth *
-gen_loadi(compiler_state_t *cstate, int val)
+gen_loadi(compiler_state_t *cstate, bpf_u_int32 val)
 {
        /*
         * Catch errors reported by us and routines below us, and return NULL
@@ -7738,13 +7737,7 @@ gen_arth(compiler_state_t *cstate, int code, struct arth *a0_arg,
                if (a1->s->s.code == (BPF_LD|BPF_IMM) && a1->s->s.k == 0)
                        bpf_error(cstate, "modulus by zero");
        } else if (code == BPF_LSH || code == BPF_RSH) {
-               /*
-                * XXX - we need to make up our minds as to what integers
-                * are signed and what integers are unsigned in BPF programs
-                * and in our IR.
-                */
-               if (a1->s->s.code == (BPF_LD|BPF_IMM) &&
-                   (a1->s->s.k < 0 || a1->s->s.k > 31))
+               if (a1->s->s.code == (BPF_LD|BPF_IMM) && a1->s->s.k > 31)
                        bpf_error(cstate, "shift by more than 31 bits");
        }
        s0 = xfer_to_x(cstate, a1);
@@ -7865,7 +7858,7 @@ gen_less(compiler_state_t *cstate, int n)
  * would generate code appropriate to the radio header in question.
  */
 struct block *
-gen_byteop(compiler_state_t *cstate, int op, int idx, int val)
+gen_byteop(compiler_state_t *cstate, int op, int idx, bpf_u_int32 val)
 {
        struct block *b;
        struct slist *s;
@@ -7882,14 +7875,14 @@ gen_byteop(compiler_state_t *cstate, int op, int idx, int val)
                abort();
 
        case '=':
-               return gen_cmp(cstate, OR_LINKHDR, (u_int)idx, BPF_B, (bpf_int32)val);
+               return gen_cmp(cstate, OR_LINKHDR, (u_int)idx, BPF_B, val);
 
        case '<':
-               b = gen_cmp_lt(cstate, OR_LINKHDR, (u_int)idx, BPF_B, (bpf_int32)val);
+               b = gen_cmp_lt(cstate, OR_LINKHDR, (u_int)idx, BPF_B, val);
                return b;
 
        case '>':
-               b = gen_cmp_gt(cstate, OR_LINKHDR, (u_int)idx, BPF_B, (bpf_int32)val);
+               b = gen_cmp_gt(cstate, OR_LINKHDR, (u_int)idx, BPF_B, val);
                return b;
 
        case '|':
@@ -7967,9 +7960,9 @@ gen_broadcast(compiler_state_t *cstate, int proto)
                        bpf_error(cstate, "netmask not known, so 'ip broadcast' not supported");
                b0 = gen_linktype(cstate, ETHERTYPE_IP);
                hostmask = ~cstate->netmask;
-               b1 = gen_mcmp(cstate, OR_LINKPL, 16, BPF_W, (bpf_int32)0, hostmask);
+               b1 = gen_mcmp(cstate, OR_LINKPL, 16, BPF_W, 0, hostmask);
                b2 = gen_mcmp(cstate, OR_LINKPL, 16, BPF_W,
-                             (bpf_int32)(~0 & hostmask), hostmask);
+                             ~0 & hostmask, hostmask);
                gen_or(b1, b2);
                gen_and(b0, b2);
                return b2;
@@ -8166,13 +8159,13 @@ gen_multicast(compiler_state_t *cstate, int proto)
 
        case Q_IP:
                b0 = gen_linktype(cstate, ETHERTYPE_IP);
-               b1 = gen_cmp_ge(cstate, OR_LINKPL, 16, BPF_B, (bpf_int32)224);
+               b1 = gen_cmp_ge(cstate, OR_LINKPL, 16, BPF_B, 224);
                gen_and(b0, b1);
                return b1;
 
        case Q_IPV6:
                b0 = gen_linktype(cstate, ETHERTYPE_IPV6);
-               b1 = gen_cmp(cstate, OR_LINKPL, 24, BPF_B, (bpf_int32)255);
+               b1 = gen_cmp(cstate, OR_LINKPL, 24, BPF_B, 255);
                gen_and(b0, b1);
                return b1;
        }
@@ -8243,7 +8236,7 @@ gen_inbound(compiler_state_t *cstate, int dir)
 #ifdef HAVE_NET_PFVAR_H
        case DLT_PFLOG:
                b0 = gen_cmp(cstate, OR_LINKHDR, offsetof(struct pfloghdr, dir), BPF_B,
-                   (bpf_int32)((dir == 0) ? PF_IN : PF_OUT));
+                   ((dir == 0) ? PF_IN : PF_OUT));
                break;
 #endif
 
@@ -8416,7 +8409,7 @@ gen_pf_rnr(compiler_state_t *cstate, int rnr)
        }
 
        b0 = gen_cmp(cstate, OR_LINKHDR, offsetof(struct pfloghdr, rulenr), BPF_W,
-                (bpf_int32)rnr);
+                (bpf_u_int32)rnr);
        return (b0);
 }
 
@@ -8439,7 +8432,7 @@ gen_pf_srnr(compiler_state_t *cstate, int srnr)
        }
 
        b0 = gen_cmp(cstate, OR_LINKHDR, offsetof(struct pfloghdr, subrulenr), BPF_W,
-           (bpf_int32)srnr);
+           (bpf_u_int32)srnr);
        return (b0);
 }
 
@@ -8462,7 +8455,7 @@ gen_pf_reason(compiler_state_t *cstate, int reason)
        }
 
        b0 = gen_cmp(cstate, OR_LINKHDR, offsetof(struct pfloghdr, reason), BPF_B,
-           (bpf_int32)reason);
+           (bpf_u_int32)reason);
        return (b0);
 }
 
@@ -8485,7 +8478,7 @@ gen_pf_action(compiler_state_t *cstate, int action)
        }
 
        b0 = gen_cmp(cstate, OR_LINKHDR, offsetof(struct pfloghdr, action), BPF_B,
-           (bpf_int32)action);
+           (bpf_u_int32)action);
        return (b0);
 }
 #else /* !HAVE_NET_PFVAR_H */
@@ -8576,7 +8569,7 @@ gen_pf_action(compiler_state_t *cstate, int action _U_)
 
 /* IEEE 802.11 wireless header */
 struct block *
-gen_p80211_type(compiler_state_t *cstate, int type, int mask)
+gen_p80211_type(compiler_state_t *cstate, bpf_u_int32 type, bpf_u_int32 mask)
 {
        struct block *b0;
 
@@ -8593,8 +8586,7 @@ gen_p80211_type(compiler_state_t *cstate, int type, int mask)
        case DLT_PRISM_HEADER:
        case DLT_IEEE802_11_RADIO_AVS:
        case DLT_IEEE802_11_RADIO:
-               b0 = gen_mcmp(cstate, OR_LINKHDR, 0, BPF_B, (bpf_int32)type,
-                   (bpf_int32)mask);
+               b0 = gen_mcmp(cstate, OR_LINKHDR, 0, BPF_B, type, mask);
                break;
 
        default:
@@ -8606,7 +8598,7 @@ gen_p80211_type(compiler_state_t *cstate, int type, int mask)
 }
 
 struct block *
-gen_p80211_fcdir(compiler_state_t *cstate, int fcdir)
+gen_p80211_fcdir(compiler_state_t *cstate, bpf_u_int32 fcdir)
 {
        struct block *b0;
 
@@ -8630,8 +8622,8 @@ gen_p80211_fcdir(compiler_state_t *cstate, int fcdir)
                /*NOTREACHED*/
        }
 
-       b0 = gen_mcmp(cstate, OR_LINKHDR, 1, BPF_B, (bpf_int32)fcdir,
-               (bpf_u_int32)IEEE80211_FC1_DIR_MASK);
+       b0 = gen_mcmp(cstate, OR_LINKHDR, 1, BPF_B, fcdir,
+           IEEE80211_FC1_DIR_MASK);
 
        return (b0);
 }
@@ -8748,7 +8740,7 @@ gen_vlan_vid_test(compiler_state_t *cstate, bpf_u_int32 vlan_num)
                bpf_error(cstate, "VLAN tag %u greater than maximum %u",
                    vlan_num, 0x0fff);
        }
-       return gen_mcmp(cstate, OR_LINKPL, 0, BPF_H, (bpf_int32)vlan_num, 0x0fff);
+       return gen_mcmp(cstate, OR_LINKPL, 0, BPF_H, vlan_num, 0x0fff);
 }
 
 static struct block *
@@ -8778,7 +8770,8 @@ gen_vlan_no_bpf_extensions(compiler_state_t *cstate, bpf_u_int32 vlan_num,
 #if defined(SKF_AD_VLAN_TAG_PRESENT)
 /* add v to variable part of off */
 static void
-gen_vlan_vloffset_add(compiler_state_t *cstate, bpf_abs_offset *off, int v, struct slist *s)
+gen_vlan_vloffset_add(compiler_state_t *cstate, bpf_abs_offset *off,
+    bpf_u_int32 v, struct slist *s)
 {
        struct slist *s2;
 
@@ -9064,7 +9057,7 @@ gen_mpls(compiler_state_t *cstate, bpf_u_int32 label_num_arg,
                            label_num, 0xFFFFF);
                }
                label_num = label_num << 12; /* label is shifted 12 bits on the wire */
-               b1 = gen_mcmp(cstate, OR_LINKPL, 0, BPF_W, (bpf_int32)label_num,
+               b1 = gen_mcmp(cstate, OR_LINKPL, 0, BPF_W, label_num,
                    0xfffff000); /* only compare the first 20 bits */
                gen_and(b0, b1);
                b0 = b1;
@@ -9104,7 +9097,7 @@ gen_pppoed(compiler_state_t *cstate)
                return (NULL);
 
        /* check for PPPoE discovery */
-       return gen_linktype(cstate, (bpf_int32)ETHERTYPE_PPPOED);
+       return gen_linktype(cstate, ETHERTYPE_PPPOED);
 }
 
 struct block *
@@ -9122,7 +9115,7 @@ gen_pppoes(compiler_state_t *cstate, bpf_u_int32 sess_num, int has_sess_num)
        /*
         * Test against the PPPoE session link-layer type.
         */
-       b0 = gen_linktype(cstate, (bpf_int32)ETHERTYPE_PPPOES);
+       b0 = gen_linktype(cstate, ETHERTYPE_PPPOES);
 
        /* If a specific session is requested, check PPPoE session id */
        if (has_sess_num) {
@@ -9130,8 +9123,7 @@ gen_pppoes(compiler_state_t *cstate, bpf_u_int32 sess_num, int has_sess_num)
                        bpf_error(cstate, "PPPoE session number %u greater than maximum %u",
                            sess_num, 0x0000ffff);
                }
-               b1 = gen_mcmp(cstate, OR_LINKPL, 0, BPF_W,
-                   (bpf_int32)sess_num, 0x0000ffff);
+               b1 = gen_mcmp(cstate, OR_LINKPL, 0, BPF_W, sess_num, 0x0000ffff);
                gen_and(b0, b1);
                b0 = b1;
        }
@@ -9192,7 +9184,7 @@ gen_pppoes(compiler_state_t *cstate, bpf_u_int32 sess_num, int has_sess_num)
  * specified. Parameterized to handle both IPv4 and IPv6. */
 static struct block *
 gen_geneve_check(compiler_state_t *cstate,
-    struct block *(*gen_portfn)(compiler_state_t *, int, int, int),
+    struct block *(*gen_portfn)(compiler_state_t *, u_int, int, int),
     enum e_offrel offrel, bpf_u_int32 vni, int has_vni)
 {
        struct block *b0, *b1;
@@ -9202,7 +9194,7 @@ gen_geneve_check(compiler_state_t *cstate,
        /* Check that we are operating on version 0. Otherwise, we
         * can't decode the rest of the fields. The version is 2 bits
         * in the first byte of the Geneve header. */
-       b1 = gen_mcmp(cstate, offrel, 8, BPF_B, (bpf_int32)0, 0xc0);
+       b1 = gen_mcmp(cstate, offrel, 8, BPF_B, 0, 0xc0);
        gen_and(b0, b1);
        b0 = b1;
 
@@ -9212,8 +9204,7 @@ gen_geneve_check(compiler_state_t *cstate,
                            vni, 0xffffff);
                }
                vni <<= 8; /* VNI is in the upper 3 bytes */
-               b1 = gen_mcmp(cstate, offrel, 12, BPF_W, (bpf_int32)vni,
-                             0xffffff00);
+               b1 = gen_mcmp(cstate, offrel, 12, BPF_W, vni, 0xffffff00);
                gen_and(b0, b1);
                b0 = b1;
        }
@@ -9496,7 +9487,7 @@ gen_geneve_ll_check(compiler_state_t *cstate)
 
 static struct block *
 gen_atmfield_code_internal(compiler_state_t *cstate, int atmfield,
-    bpf_int32 jvalue, bpf_u_int32 jtype, int reverse)
+    bpf_u_int32 jvalue, int jtype, int reverse)
 {
        struct block *b0;
 
@@ -9507,8 +9498,8 @@ gen_atmfield_code_internal(compiler_state_t *cstate, int atmfield,
                        bpf_error(cstate, "'vpi' supported only on raw ATM");
                if (cstate->off_vpi == OFFSET_NOT_SET)
                        abort();
-               b0 = gen_ncmp(cstate, OR_LINKHDR, cstate->off_vpi, BPF_B, 0xffffffff, jtype,
-                   reverse, jvalue);
+               b0 = gen_ncmp(cstate, OR_LINKHDR, cstate->off_vpi, BPF_B,
+                   0xffffffffU, jtype, reverse, jvalue);
                break;
 
        case A_VCI:
@@ -9516,22 +9507,22 @@ gen_atmfield_code_internal(compiler_state_t *cstate, int atmfield,
                        bpf_error(cstate, "'vci' supported only on raw ATM");
                if (cstate->off_vci == OFFSET_NOT_SET)
                        abort();
-               b0 = gen_ncmp(cstate, OR_LINKHDR, cstate->off_vci, BPF_H, 0xffffffff, jtype,
-                   reverse, jvalue);
+               b0 = gen_ncmp(cstate, OR_LINKHDR, cstate->off_vci, BPF_H,
+                   0xffffffffU, jtype, reverse, jvalue);
                break;
 
        case A_PROTOTYPE:
                if (cstate->off_proto == OFFSET_NOT_SET)
                        abort();        /* XXX - this isn't on FreeBSD */
-               b0 = gen_ncmp(cstate, OR_LINKHDR, cstate->off_proto, BPF_B, 0x0f, jtype,
-                   reverse, jvalue);
+               b0 = gen_ncmp(cstate, OR_LINKHDR, cstate->off_proto, BPF_B,
+                   0x0fU, jtype, reverse, jvalue);
                break;
 
        case A_MSGTYPE:
                if (cstate->off_payload == OFFSET_NOT_SET)
                        abort();
                b0 = gen_ncmp(cstate, OR_LINKHDR, cstate->off_payload + MSG_TYPE_POS, BPF_B,
-                   0xffffffff, jtype, reverse, jvalue);
+                   0xffffffffU, jtype, reverse, jvalue);
                break;
 
        case A_CALLREFTYPE:
@@ -9539,8 +9530,8 @@ gen_atmfield_code_internal(compiler_state_t *cstate, int atmfield,
                        bpf_error(cstate, "'callref' supported only on raw ATM");
                if (cstate->off_proto == OFFSET_NOT_SET)
                        abort();
-               b0 = gen_ncmp(cstate, OR_LINKHDR, cstate->off_proto, BPF_B, 0xffffffff,
-                   jtype, reverse, jvalue);
+               b0 = gen_ncmp(cstate, OR_LINKHDR, cstate->off_proto, BPF_B,
+                   0xffffffffU, jtype, reverse, jvalue);
                break;
 
        default:
@@ -9583,7 +9574,7 @@ gen_atmtype_llc(compiler_state_t *cstate)
 
 struct block *
 gen_atmfield_code(compiler_state_t *cstate, int atmfield,
-    bpf_int32 jvalue, bpf_u_int32 jtype, int reverse)
+    bpf_u_int32 jvalue, int jtype, int reverse)
 {
        /*
         * Catch errors reported by us and routines below us, and return NULL
@@ -9723,7 +9714,8 @@ gen_mtp2type_abbrev(compiler_state_t *cstate, int type)
                     (cstate->linktype != DLT_MTP2_WITH_PHDR) )
                        bpf_error(cstate, "'fisu' supported only on MTP2");
                /* gen_ncmp(cstate, offrel, offset, size, mask, jtype, reverse, value) */
-               b0 = gen_ncmp(cstate, OR_PACKET, cstate->off_li, BPF_B, 0x3f, BPF_JEQ, 0, 0);
+               b0 = gen_ncmp(cstate, OR_PACKET, cstate->off_li, BPF_B,
+                   0x3fU, BPF_JEQ, 0, 0U);
                break;
 
        case M_LSSU:
@@ -9731,8 +9723,10 @@ gen_mtp2type_abbrev(compiler_state_t *cstate, int type)
                     (cstate->linktype != DLT_ERF) &&
                     (cstate->linktype != DLT_MTP2_WITH_PHDR) )
                        bpf_error(cstate, "'lssu' supported only on MTP2");
-               b0 = gen_ncmp(cstate, OR_PACKET, cstate->off_li, BPF_B, 0x3f, BPF_JGT, 1, 2);
-               b1 = gen_ncmp(cstate, OR_PACKET, cstate->off_li, BPF_B, 0x3f, BPF_JGT, 0, 0);
+               b0 = gen_ncmp(cstate, OR_PACKET, cstate->off_li, BPF_B,
+                   0x3fU, BPF_JGT, 1, 2U);
+               b1 = gen_ncmp(cstate, OR_PACKET, cstate->off_li, BPF_B,
+                   0x3fU, BPF_JGT, 0, 0U);
                gen_and(b1, b0);
                break;
 
@@ -9741,7 +9735,8 @@ gen_mtp2type_abbrev(compiler_state_t *cstate, int type)
                     (cstate->linktype != DLT_ERF) &&
                     (cstate->linktype != DLT_MTP2_WITH_PHDR) )
                        bpf_error(cstate, "'msu' supported only on MTP2");
-               b0 = gen_ncmp(cstate, OR_PACKET, cstate->off_li, BPF_B, 0x3f, BPF_JGT, 0, 2);
+               b0 = gen_ncmp(cstate, OR_PACKET, cstate->off_li, BPF_B,
+                   0x3fU, BPF_JGT, 0, 2U);
                break;
 
        case MH_FISU:
@@ -9750,7 +9745,8 @@ gen_mtp2type_abbrev(compiler_state_t *cstate, int type)
                     (cstate->linktype != DLT_MTP2_WITH_PHDR) )
                        bpf_error(cstate, "'hfisu' supported only on MTP2_HSL");
                /* gen_ncmp(cstate, offrel, offset, size, mask, jtype, reverse, value) */
-               b0 = gen_ncmp(cstate, OR_PACKET, cstate->off_li_hsl, BPF_H, 0xff80, BPF_JEQ, 0, 0);
+               b0 = gen_ncmp(cstate, OR_PACKET, cstate->off_li_hsl, BPF_H,
+                   0xff80U, BPF_JEQ, 0, 0U);
                break;
 
        case MH_LSSU:
@@ -9758,8 +9754,10 @@ gen_mtp2type_abbrev(compiler_state_t *cstate, int type)
                     (cstate->linktype != DLT_ERF) &&
                     (cstate->linktype != DLT_MTP2_WITH_PHDR) )
                        bpf_error(cstate, "'hlssu' supported only on MTP2_HSL");
-               b0 = gen_ncmp(cstate, OR_PACKET, cstate->off_li_hsl, BPF_H, 0xff80, BPF_JGT, 1, 0x0100);
-               b1 = gen_ncmp(cstate, OR_PACKET, cstate->off_li_hsl, BPF_H, 0xff80, BPF_JGT, 0, 0);
+               b0 = gen_ncmp(cstate, OR_PACKET, cstate->off_li_hsl, BPF_H,
+                   0xff80U, BPF_JGT, 1, 0x0100U);
+               b1 = gen_ncmp(cstate, OR_PACKET, cstate->off_li_hsl, BPF_H,
+                   0xff80U, BPF_JGT, 0, 0U);
                gen_and(b1, b0);
                break;
 
@@ -9768,7 +9766,8 @@ gen_mtp2type_abbrev(compiler_state_t *cstate, int type)
                     (cstate->linktype != DLT_ERF) &&
                     (cstate->linktype != DLT_MTP2_WITH_PHDR) )
                        bpf_error(cstate, "'hmsu' supported only on MTP2_HSL");
-               b0 = gen_ncmp(cstate, OR_PACKET, cstate->off_li_hsl, BPF_H, 0xff80, BPF_JGT, 0, 0x0100);
+               b0 = gen_ncmp(cstate, OR_PACKET, cstate->off_li_hsl, BPF_H,
+                   0xff80U, BPF_JGT, 0, 0x0100U);
                break;
 
        default:
@@ -9784,7 +9783,7 @@ gen_mtp2type_abbrev(compiler_state_t *cstate, int type)
  */
 struct block *
 gen_mtp3field_code(compiler_state_t *cstate, int mtp3field,
-    bpf_u_int32 jvalue_arg, bpf_u_int32 jtype, int reverse)
+    bpf_u_int32 jvalue_arg, int jtype, int reverse)
 {
        bpf_u_int32 jvalue = jvalue_arg;
        struct block *b0;
@@ -9818,8 +9817,8 @@ gen_mtp3field_code(compiler_state_t *cstate, int mtp3field,
                if(jvalue > 255)
                        bpf_error(cstate, "sio value %u too big; max value = 255",
                            jvalue);
-               b0 = gen_ncmp(cstate, OR_PACKET, newoff_sio, BPF_B, 0xffffffff,
-                   (u_int)jtype, reverse, (u_int)jvalue);
+               b0 = gen_ncmp(cstate, OR_PACKET, newoff_sio, BPF_B, 0xffffffffU,
+                   jtype, reverse, jvalue);
                break;
 
        case MH_OPC:
@@ -9840,8 +9839,8 @@ gen_mtp3field_code(compiler_state_t *cstate, int mtp3field,
                val3 = jvalue & 0x00000003;
                val3 = val3 <<22;
                jvalue = val1 + val2 + val3;
-               b0 = gen_ncmp(cstate, OR_PACKET, newoff_opc, BPF_W, 0x00c0ff0f,
-                   (u_int)jtype, reverse, (u_int)jvalue);
+               b0 = gen_ncmp(cstate, OR_PACKET, newoff_opc, BPF_W, 0x00c0ff0fU,
+                   jtype, reverse, jvalue);
                break;
 
        case MH_DPC:
@@ -9862,8 +9861,8 @@ gen_mtp3field_code(compiler_state_t *cstate, int mtp3field,
                val2 = jvalue & 0x00003f00;
                val2 = val2 << 8;
                jvalue = val1 + val2;
-               b0 = gen_ncmp(cstate, OR_PACKET, newoff_dpc, BPF_W, 0xff3f0000,
-                   (u_int)jtype, reverse, (u_int)jvalue);
+               b0 = gen_ncmp(cstate, OR_PACKET, newoff_dpc, BPF_W, 0xff3f0000U,
+                   jtype, reverse, jvalue);
                break;
 
        case MH_SLS:
@@ -9878,8 +9877,8 @@ gen_mtp3field_code(compiler_state_t *cstate, int mtp3field,
                /* the following instruction is made to convert jvalue
                 * to the forme used to write sls in an ss7 message*/
                jvalue = jvalue << 4;
-               b0 = gen_ncmp(cstate, OR_PACKET, newoff_sls, BPF_B, 0xf0,
-                   (u_int)jtype,reverse, (u_int)jvalue);
+               b0 = gen_ncmp(cstate, OR_PACKET, newoff_sls, BPF_B, 0xf0U,
+                   jtype, reverse, jvalue);
                break;
 
        default: