From: Remi Gacogne Date: Mon, 14 Oct 2019 08:21:20 +0000 (+0200) Subject: Work around CMSG_SPACE somehow not being a constexpr on macOS X-Git-Tag: dnsdist-1.4.0-rc4~25^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=aeb011b75de61d4b31f2750b8d929ba042bfeb2f;p=pdns Work around CMSG_SPACE somehow not being a constexpr on macOS --- diff --git a/pdns/misc.cc b/pdns/misc.cc index abd0ba662..f9248af42 100644 --- a/pdns/misc.cc +++ b/pdns/misc.cc @@ -890,7 +890,14 @@ void addCMsgSrcAddr(struct msghdr* msgh, cmsgbuf_aligned* cmsgbuf, const ComboAd struct in6_pktinfo *pkt; msgh->msg_control = cmsgbuf; +#if !defined( __APPLE__ ) + /* CMSG_SPACE is not a constexpr on macOS */ static_assert(CMSG_SPACE(sizeof(*pkt)) <= sizeof(*cmsgbuf), "Buffer is too small for in6_pktinfo"); +#else /* __APPLE__ */ + if (CMSG_SPACE(sizeof(*pkt)) > sizeof(*cmsgbuf)) { + throw std::runtime_error("Buffer is too small for in6_pktinfo"); + } +#endif /* __APPLE__ */ msgh->msg_controllen = CMSG_SPACE(sizeof(*pkt)); cmsg = CMSG_FIRSTHDR(msgh); @@ -909,7 +916,14 @@ void addCMsgSrcAddr(struct msghdr* msgh, cmsgbuf_aligned* cmsgbuf, const ComboAd struct in_pktinfo *pkt; msgh->msg_control = cmsgbuf; +#if !defined( __APPLE__ ) + /* CMSG_SPACE is not a constexpr on macOS */ static_assert(CMSG_SPACE(sizeof(*pkt)) <= sizeof(*cmsgbuf), "Buffer is too small for in_pktinfo"); +#else /* __APPLE__ */ + if (CMSG_SPACE(sizeof(*pkt)) > sizeof(*cmsgbuf)) { + throw std::runtime_error("Buffer is too small for in_pktinfo"); + } +#endif /* __APPLE__ */ msgh->msg_controllen = CMSG_SPACE(sizeof(*pkt)); cmsg = CMSG_FIRSTHDR(msgh); @@ -926,7 +940,13 @@ void addCMsgSrcAddr(struct msghdr* msgh, cmsgbuf_aligned* cmsgbuf, const ComboAd struct in_addr *in; msgh->msg_control = cmsgbuf; +#if !defined( __APPLE__ ) static_assert(CMSG_SPACE(sizeof(*in)) <= sizeof(*cmsgbuf), "Buffer is too small for in_addr"); +#else /* __APPLE__ */ + if (CMSG_SPACE(sizeof(*in)) > sizeof(*cmsgbuf)) { + throw std::runtime_error("Buffer is too small for in_addr"); + } +#endif /* __APPLE__ */ msgh->msg_controllen = CMSG_SPACE(sizeof(*in)); cmsg = CMSG_FIRSTHDR(msgh);