diff options
author | Denis Ovsienko <denis@ovsienko.info> | 2023-04-22 22:18:43 +0100 |
---|---|---|
committer | Denis Ovsienko <denis@ovsienko.info> | 2023-04-23 17:21:05 +0100 |
commit | 02b98a948dfb661c3e04fca91bd9485525d4198f (patch) | |
tree | ffbab0174b5071c2c7f037408e39d547cb780732 /pcap.c | |
parent | ab3f6a677ba66a9679c6f3412f0320a5776842d0 (diff) |
Address a few compiler warnings on Haiku.
In gencode.c instead of casting pointer types copy the data to squelch 4
previously known warnings from GCC and Clang. (Oddly enough, Haiku is
the only OS that unconditionally puts a 32-bit array into the union
inside struct in6_addr, yet the only OS where these warnings appeared.)
In pcap.c add a temporary workaround for ioctl() to squelch two other
Clang warnings:
pcap.c:1619:6: error: missing field 'size' initializer
[-Werror,-Wmissing-field-initializers]
pcap.c:1638:6: error: missing field 'size' initializer
[-Werror,-Wmissing-field-initializers]
With these changes GCC builds are now warning-free, so in build.sh set
LIBPCAP_TAINTED for Clang only and update the comment to show the
current remaining warnings.
Diffstat (limited to 'pcap.c')
-rw-r--r-- | pcap.c | 17 |
1 files changed, 17 insertions, 0 deletions
@@ -1616,7 +1616,19 @@ pcap_lookupnet(const char *device, bpf_u_int32 *netp, bpf_u_int32 *maskp, ifr.ifr_addr.sa_family = AF_INET; #endif (void)pcap_strlcpy(ifr.ifr_name, device, sizeof(ifr.ifr_name)); +#if defined(__HAIKU__) && defined(__clang__) + /* + * In Haiku R1/beta4 <unistd.h> ioctl() is a macro that needs to take 4 + * arguments to initialize its intermediate 2-member structure fully so + * that Clang does not generate a -Wmissing-field-initializers warning + * (which manifests only when it runs with -Werror). This workaround + * can be removed as soon as there is a Haiku release that fixes the + * problem. See also https://review.haiku-os.org/c/haiku/+/6369 + */ + if (ioctl(fd, SIOCGIFADDR, (char *)&ifr, sizeof(ifr)) < 0) { +#else if (ioctl(fd, SIOCGIFADDR, (char *)&ifr) < 0) { +#endif /* __HAIKU__ && __clang__ */ if (errno == EADDRNOTAVAIL) { (void)snprintf(errbuf, PCAP_ERRBUF_SIZE, "%s: no IPv4 address assigned", device); @@ -1635,7 +1647,12 @@ pcap_lookupnet(const char *device, bpf_u_int32 *netp, bpf_u_int32 *maskp, ifr.ifr_addr.sa_family = AF_INET; #endif (void)pcap_strlcpy(ifr.ifr_name, device, sizeof(ifr.ifr_name)); +#if defined(__HAIKU__) && defined(__clang__) + /* Same as above. */ + if (ioctl(fd, SIOCGIFNETMASK, (char *)&ifr, sizeof(ifr)) < 0) { +#else if (ioctl(fd, SIOCGIFNETMASK, (char *)&ifr) < 0) { +#endif /* __HAIKU__ && __clang__ */ pcap_fmt_errmsg_for_errno(errbuf, PCAP_ERRBUF_SIZE, errno, "SIOCGIFNETMASK: %s", device); (void)close(fd); |