From 5bc19d0b84d0d1c448cd4e4ba0e3e7da3503434a Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Thu, 14 Aug 2014 15:12:34 +0200 Subject: netsniff-ng: Only use TPACKET_V3 if HAVE_TPACKET3 is defined TPACKET_V3 is not defined if tpacket v3 is not available, thus make its use conditional on HAVE_TPACKET3. Wrap the check for TPACKET_V3 in ring_rx in an inline function which always returns false if HAVE_TPACKET3 is not defined. Reported-by: Mike Reeves Signed-off-by: Tobias Klauser --- ring_rx.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/ring_rx.c b/ring_rx.c index 1b8dd23..72587fd 100644 --- a/ring_rx.c +++ b/ring_rx.c @@ -20,10 +20,22 @@ #include "ring_rx.h" #include "built_in.h" +#ifdef HAVE_TPACKET3 +static inline bool is_tpacket_v3(int sock) +{ + return get_sockopt_tpacket(sock) == TPACKET_V3; +} +#else +static inline bool is_tpacket_v3(int sock __maybe_unused) +{ + return false; +} +#endif + void destroy_rx_ring(int sock, struct ring *ring) { int ret; - bool v3 = get_sockopt_tpacket(sock) == TPACKET_V3; + bool v3 = is_tpacket_v3(sock); munmap(ring->mm_space, ring->mm_len); ring->mm_len = 0; @@ -85,11 +97,10 @@ static void setup_rx_ring_layout(int sock, struct ring *ring, size_t size, static void create_rx_ring(int sock, struct ring *ring, bool verbose) { int ret; + bool v3 = is_tpacket_v3(sock); #ifdef HAVE_TPACKET3 - bool v3 = get_sockopt_tpacket(sock) == TPACKET_V3; size_t layout_size = v3 ? sizeof(ring->layout3) : sizeof(ring->layout); #else - bool v3 = false; size_t layout_size = sizeof(ring->layout); #endif /* HAVE_TPACKET3 */ @@ -126,15 +137,11 @@ static void alloc_rx_ring_frames(int sock, struct ring *ring) { int num; size_t size; -#if HAVE_TPACKET3 - bool v3 = get_sockopt_tpacket(sock) == TPACKET_V3; + bool v3 = is_tpacket_v3(sock); if (v3) { num = ring->layout3.tp_block_nr; size = ring->layout3.tp_block_size; -#else - if (0) { -#endif /* HAVE_TPACKET3 */ } else { num = ring->layout.tp_frame_nr; size = ring->layout.tp_frame_size; @@ -159,7 +166,7 @@ void ring_rx_setup(struct ring *ring, int sock, size_t size, int ifindex, void sock_rx_net_stats(int sock, unsigned long seen) { int ret; - bool v3 = get_sockopt_tpacket(sock) == TPACKET_V3; + bool v3 = is_tpacket_v3(sock); union { struct tpacket_stats k2; struct tpacket_stats_v3 k3; -- cgit v1.2.3-54-g00ecf