static_assert(sizeof(EDNS0Record) == 4, "EDNS0Record size must be 4");
-#if defined(__FreeBSD__) || defined(__APPLE__) || defined(__OpenBSD__) || defined(__DragonFly__) || defined(__FreeBSD_kernel__)
+#if defined(__FreeBSD__) || defined(__APPLE__) || defined(__OpenBSD__) || defined(__DragonFly__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__)
#include <machine/endian.h>
#elif __linux__ || __GNU__
# include <endian.h>
#include "sodcrypto.hh"
#include "pwd.h"
-#if defined (__OpenBSD__)
+#if defined (__OpenBSD__) || defined(__NetBSD__)
#include <readline/readline.h>
#include <readline/history.h>
#else
#include <limits>
#include "dolog.hh"
-#if defined (__OpenBSD__)
+#if defined (__OpenBSD__) || defined(__NetBSD__)
#include <readline/readline.h>
#else
#include <editline/readline.h>
bool HarvestDestinationAddress(const struct msghdr* msgh, ComboAddress* destination)
{
memset(destination, 0, sizeof(*destination));
+#ifdef __NetBSD__
+ struct cmsghdr* cmsg;
+#else
const struct cmsghdr* cmsg;
+#endif
for (cmsg = CMSG_FIRSTHDR(msgh); cmsg != NULL; cmsg = CMSG_NXTHDR(const_cast<struct msghdr*>(msgh), const_cast<struct cmsghdr*>(cmsg))) {
#if defined(IP_PKTINFO)
if ((cmsg->cmsg_level == IPPROTO_IP) && (cmsg->cmsg_type == IP_PKTINFO)) {
#include <sys/endian.h>
#endif
+#if defined(__NetBSD__) && defined(IP_PKTINFO) && !defined(IP_SENDSRCADDR)
+// The IP_PKTINFO option in NetBSD was incompatible with Linux until a
+// change that also introduced IP_SENDSRCADDR for FreeBSD compatibility.
+#undef IP_PKTINFO
+#endif
+
union ComboAddress {
struct sockaddr_in sin4;
struct sockaddr_in6 sin6;
#elif defined(IP_RECVDSTADDR)
#define GEN_IP_PKTINFO IP_RECVDSTADDR
#endif
+
bool IsAnyAddress(const ComboAddress& addr);
bool HarvestDestinationAddress(const struct msghdr* msgh, ComboAddress* destination);
bool HarvestTimestamp(struct msghdr* msgh, struct timeval* tv);
#include <unistd.h>
#include "misc.hh"
#include <sys/types.h>
-#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__)
#include <sys/event.h>
#endif
#include <sys/time.h>
#ifdef __FreeBSD__
# include <pthread_np.h>
#endif
+#ifdef __NetBSD__
+# include <pthread.h>
+# include <sched.h>
+#endif
bool g_singleThreaded;
pkt->ipi6_ifindex = itfIndex;
}
else {
-#ifdef IP_PKTINFO
+#if defined(IP_PKTINFO)
struct in_pktinfo *pkt;
msgh->msg_control = cmsgbuf;
memset(pkt, 0, sizeof(*pkt));
pkt->ipi_spec_dst = source->sin4.sin_addr;
pkt->ipi_ifindex = itfIndex;
-#endif
-#ifdef IP_SENDSRCADDR
+#elif defined(IP_SENDSRCADDR)
struct in_addr *in;
msgh->msg_control = cmsgbuf;
int mapThreadToCPUList(pthread_t tid, const std::set<int>& cpus)
{
#ifdef HAVE_PTHREAD_SETAFFINITY_NP
-# ifdef __FreeBSD__
-# define cpu_set_t cpuset_t
-# endif
+# ifdef __NetBSD__
+ cpuset_t *cpuset;
+ cpuset = cpuset_create();
+ for (const auto cpuID : cpus) {
+ cpuset_set(cpuID, cpuset);
+ }
+
+ return pthread_setaffinity_np(tid,
+ cpuset_size(cpuset),
+ cpuset);
+# else
+# ifdef __FreeBSD__
+# define cpu_set_t cpuset_t
+# endif
cpu_set_t cpuset;
CPU_ZERO(&cpuset);
for (const auto cpuID : cpus) {
return pthread_setaffinity_np(tid,
sizeof(cpuset),
&cpuset);
+# endif
#endif /* HAVE_PTHREAD_SETAFFINITY_NP */
return ENOSYS;
}