]> The Tcpdump Group git mirrors - libpcap/commitdiff
Fix building without protochain support. (GH #852)
authorDenis Ovsienko <[email protected]>
Tue, 14 Jun 2022 20:24:28 +0000 (21:24 +0100)
committerDenis Ovsienko <[email protected]>
Tue, 14 Jun 2022 20:36:51 +0000 (21:36 +0100)
The NO_PROTOCHAIN macro is properly managed by both of the current build
systems, but it looks like noone has exercised the option in a long
time, as the source code compiles only with the default "enable
protochain" setting and the other branch fails due to a compiler error:

./configure --disable-protochain && make
[...]
./gencode.c: In function 'gen_protochain':
./gencode.c:6077:9: error: too few arguments to function 'gen_proto'
 6077 |  return gen_proto(cstate, v, proto);

Drop the offending call to gen_proto() because it is out of place anyway
and make both the declarations and the invocations of gen_protochain()
conditional on NO_PROTOCHAIN to emphasize that when the macro is
defined, the code is not reachable because the parser rejects the
"protochain" token at an earlier step.

./configure --disable-protochain && make
[...]
$ tcpdump -y EN10MB -d 'ip protochain \tcp'
tcpdump: protochain not supported

CHANGES
gencode.c

diff --git a/CHANGES b/CHANGES
index 1b0ea5e2a62615b8674b277a41c674deb09a0b10..25d51c81e7b278ec929a308e5e9272f2b7e81879 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -16,6 +16,8 @@ Monthday, Month DD, YYYY:
       Support user names and passwords in rpcap:// and rpcaps:// URLs.
     Documentation:
       Improve some protocol details in pcap-filter(7).
+    Building and testing:
+      Fix building without protochain support. (GH #852)
 
 Monthday, Month DD, YYYY:
   Summary for 1.10.2 libpcap release (so far!)
index 9197301321033263b0c48c8e6c6a7489e6de73ba..ea272e17649aff9c1123b88d8f0c01ec76f55067 100644 (file)
--- a/gencode.c
+++ b/gencode.c
@@ -564,7 +564,9 @@ 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);
+#if !defined(NO_PROTOCHAIN)
 static struct block *gen_protochain(compiler_state_t *, bpf_u_int32, int);
+#endif /* !defined(NO_PROTOCHAIN) */
 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 *);
@@ -6070,12 +6072,10 @@ lookup_proto(compiler_state_t *cstate, const char *name, int proto)
        return v;
 }
 
+#if !defined(NO_PROTOCHAIN)
 static struct block *
 gen_protochain(compiler_state_t *cstate, bpf_u_int32 v, int proto)
 {
-#ifdef NO_PROTOCHAIN
-       return gen_proto(cstate, v, proto);
-#else
        struct block *b0, *b;
        struct slist *s[100];
        int fix2, fix3, fix4, fix5;
@@ -6369,8 +6369,8 @@ gen_protochain(compiler_state_t *cstate, bpf_u_int32 v, int proto)
 
        gen_and(b0, b);
        return b;
-#endif
 }
+#endif /* !defined(NO_PROTOCHAIN) */
 
 static struct block *
 gen_check_802_11_data_frame(compiler_state_t *cstate)
@@ -6953,12 +6953,14 @@ gen_scode(compiler_state_t *cstate, const char *name, struct qual q)
                else
                        bpf_error(cstate, "unknown protocol: %s", name);
 
+#if !defined(NO_PROTOCHAIN)
        case Q_PROTOCHAIN:
                real_proto = lookup_proto(cstate, name, proto);
                if (real_proto >= 0)
                        return gen_protochain(cstate, real_proto, proto);
                else
                        bpf_error(cstate, "unknown protocol: %s", name);
+#endif /* !defined(NO_PROTOCHAIN) */
 
        case Q_UNDEF:
                syntax(cstate);
@@ -7131,8 +7133,10 @@ gen_ncode(compiler_state_t *cstate, const char *s, bpf_u_int32 v, struct qual q)
        case Q_PROTO:
                return gen_proto(cstate, v, proto, dir);
 
+#if !defined(NO_PROTOCHAIN)
        case Q_PROTOCHAIN:
                return gen_protochain(cstate, v, proto);
+#endif
 
        case Q_UNDEF:
                syntax(cstate);