From 22307d22e05ecd5bc035d4add497ee2133394763 Mon Sep 17 00:00:00 2001 From: Daniel Roethlisberger Date: Sun, 3 Mar 2024 12:59:17 +0100 Subject: [PATCH] Fix a number of benign compiler warnings on Linux/GCC MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit src/recv.c:103:17: warning: ‘static’ is not at beginning of declaration [-Wold-style-declaration] 103 | const static uint32_t available_space = sizeof(fake_eth_hdr) - sizeof(struct ether_header); | ^~~~~ src/if-netmap-linux.c: In function ‘fetch_stats64’: src/if-netmap-linux.c:94:18: warning: ISO C99 doesn’t support unnamed structs/unions [-Wpedantic] 94 | }; | ^ src/probe_modules/packet.h: In function ‘check_dst_port’: src/probe_modules/packet.h:162:37: warning: suggest parentheses around comparison in operand of ‘^’ -Wparentheses] 162 | return (to_validate <= max ^ to_validate >= min); | ~~~~~~~~~~~~^~~~~~ src/probe_modules/packet.c: In function ‘set_timestamp_option_with_nops’: src/probe_modules/packet.c:178:24: warning: implicit declaration of function ‘time’ [-Wimplicit-function-declaration] 178 | uint32_t now = time(NULL); | ^~~~ src/probe_modules/packet.c:178:24: warning: nested extern declaration of ‘time’ [-Wnested-externs] 178 | uint32_t now = time(NULL); | ^~~~ --- src/if-netmap-linux.c | 16 ++++++++-------- src/probe_modules/packet.c | 1 + src/probe_modules/packet.h | 2 +- src/recv.c | 2 +- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/if-netmap-linux.c b/src/if-netmap-linux.c index 4af87f169..863272743 100644 --- a/src/if-netmap-linux.c +++ b/src/if-netmap-linux.c @@ -91,15 +91,15 @@ fetch_stats64(struct rtnl_link_stats64 *rtlstats64, char const *ifname, int nlrt struct { struct nlmsgerr nlerr; } err; - }; + } u; } nlresp; - _Static_assert(sizeof(nlresp.ans) >= sizeof(nlresp.err)); - static const size_t ans_size = offsetof(struct nlresp, ans) + sizeof(nlresp.ans); - static const size_t err_size = offsetof(struct nlresp, err) + sizeof(nlresp.err); + _Static_assert(sizeof(nlresp.u.ans) >= sizeof(nlresp.u.err)); + static const size_t ans_size = offsetof(struct nlresp, u.ans) + sizeof(nlresp.u.ans); + static const size_t err_size = offsetof(struct nlresp, u.err) + sizeof(nlresp.u.err); memset(iov, 0, sizeof(iov)); iov[0].iov_base = (void *)&nlresp; - iov[0].iov_len = offsetof(struct nlresp, ans.rtlstats64); + iov[0].iov_len = offsetof(struct nlresp, u.ans.rtlstats64); iov[1].iov_base = (void *)rtlstats64; // caller-provided iov[1].iov_len = sizeof(struct rtnl_link_stats64); memset(&msg, 0, sizeof(msg)); @@ -116,9 +116,9 @@ fetch_stats64(struct rtnl_link_stats64 *rtlstats64, char const *ifname, int nlrt if (nlresp.nlh.nlmsg_type == NLMSG_ERROR) { // copy second iov into ans in first iov to get contiguous struct nlmsgerr - nlresp.ans.rtlstats64 = *rtlstats64; - assert(nlresp.err.nlerr.error < 0); - errno = -nlresp.err.nlerr.error; + nlresp.u.ans.rtlstats64 = *rtlstats64; + assert(nlresp.u.err.nlerr.error < 0); + errno = -nlresp.u.err.nlerr.error; log_fatal("if-netmap-linux", "received NLMSG_ERROR: %d: %s", errno, strerror(errno)); } if (nlresp.nlh.nlmsg_type != RTM_NEWSTATS) { diff --git a/src/probe_modules/packet.c b/src/probe_modules/packet.c index bac41e2de..3a82f7fb7 100644 --- a/src/probe_modules/packet.c +++ b/src/probe_modules/packet.c @@ -10,6 +10,7 @@ #include #include #include +#include #include "../../lib/includes.h" #include "../../lib/xalloc.h" diff --git a/src/probe_modules/packet.h b/src/probe_modules/packet.h index 1cfe7331d..e894b7de0 100644 --- a/src/probe_modules/packet.h +++ b/src/probe_modules/packet.h @@ -159,7 +159,7 @@ static inline int check_dst_port(uint16_t port, int num_ports, if (min <= max) { return (to_validate <= max && to_validate >= min); } else { - return (to_validate <= max ^ to_validate >= min); + return ((to_validate <= max) != (to_validate >= min)); } } diff --git a/src/recv.c b/src/recv.c index 691345bb2..152368b29 100644 --- a/src/recv.c +++ b/src/recv.c @@ -100,7 +100,7 @@ void handle_packet(uint32_t buflen, const u_char *bytes, // Here, we fake an ethernet frame (which is initialized to // have ETH_P_IP proto and 00s for dest/src). if (zconf.send_ip_pkts) { - const static uint32_t available_space = sizeof(fake_eth_hdr) - sizeof(struct ether_header); + static const uint32_t available_space = sizeof(fake_eth_hdr) - sizeof(struct ether_header); assert(buflen > (uint32_t)zconf.data_link_size); buflen -= zconf.data_link_size; if (buflen > available_space) {