]> granicus.if.org Git - pdns/commitdiff
Work around CMSG_SPACE somehow not being a constexpr on macOS
authorRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 14 Oct 2019 08:21:20 +0000 (10:21 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 14 Oct 2019 08:21:20 +0000 (10:21 +0200)
pdns/misc.cc

index abd0ba6622c1f99734da4892a0c7d138b1032dea..f9248af42a1193d8f28af6aa2bcdcdcf11dcd8a1 100644 (file)
@@ -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);