From: Denis Ovsienko Date: Tue, 14 Jun 2022 20:24:28 +0000 (+0100) Subject: Fix building without protochain support. (GH #852) X-Git-Url: https://git.tcpdump.org/libpcap/commitdiff_plain/bc594f185299d9d4e3b39ba94e91a5b9ca8a938d Fix building without protochain support. (GH #852) 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 --- diff --git a/CHANGES b/CHANGES index 1b0ea5e2..25d51c81 100644 --- 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!) diff --git a/gencode.c b/gencode.c index 91973013..ea272e17 100644 --- 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);