summaryrefslogtreecommitdiff
path: root/pcap.c
diff options
context:
space:
mode:
Diffstat (limited to 'pcap.c')
-rw-r--r--pcap.c27
1 files changed, 23 insertions, 4 deletions
diff --git a/pcap.c b/pcap.c
index 44ce8a01..04aa7441 100644
--- a/pcap.c
+++ b/pcap.c
@@ -65,6 +65,8 @@ struct rtentry; /* declarations in <net/if.h> */
#include "diag-control.h"
+#include "thread-local.h"
+
#ifdef HAVE_OS_PROTO_H
#include "os-proto.h"
#endif
@@ -1616,7 +1618,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 +1649,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);
@@ -3377,7 +3396,7 @@ pcap_datalink_val_to_description(int dlt)
const char *
pcap_datalink_val_to_description_or_dlt(int dlt)
{
- static char unkbuf[40];
+ static thread_local char unkbuf[40];
const char *description;
description = pcap_datalink_val_to_description(dlt);
@@ -3643,7 +3662,7 @@ pcap_setnonblock_fd(pcap_t *p, int nonblock)
const char *
pcap_statustostr(int errnum)
{
- static char ebuf[15+10+1];
+ static thread_local char ebuf[15+10+1];
switch (errnum) {
@@ -3704,7 +3723,7 @@ pcap_strerror(int errnum)
{
#ifdef HAVE_STRERROR
#ifdef _WIN32
- static char errbuf[PCAP_ERRBUF_SIZE];
+ static thread_local char errbuf[PCAP_ERRBUF_SIZE];
errno_t err = strerror_s(errbuf, PCAP_ERRBUF_SIZE, errnum);
if (err != 0) /* err = 0 if successful */
@@ -3716,7 +3735,7 @@ pcap_strerror(int errnum)
#else
extern int sys_nerr;
extern const char *const sys_errlist[];
- static char errbuf[PCAP_ERRBUF_SIZE];
+ static thread_local char errbuf[PCAP_ERRBUF_SIZE];
if ((unsigned int)errnum < sys_nerr)
return ((char *)sys_errlist[errnum]);