From 98af46c55cdfc1a5b1b518f54703654931a1b009 Mon Sep 17 00:00:00 2001 From: Peter Griess Date: Thu, 13 Aug 2015 10:19:09 -0700 Subject: [PATCH] Set IPV6_V6ONLY in folly::AsyncUDPServerSocket Summary: - This mirrors the behavior in AsyncServerSocket Reviewed By: @yfeldblum Differential Revision: D2338665 --- folly/io/async/AsyncUDPSocket.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/folly/io/async/AsyncUDPSocket.cpp b/folly/io/async/AsyncUDPSocket.cpp index 5b128126..1364ed3f 100644 --- a/folly/io/async/AsyncUDPSocket.cpp +++ b/folly/io/async/AsyncUDPSocket.cpp @@ -91,6 +91,18 @@ void AsyncUDPSocket::bind(const folly::SocketAddress& address) { } } + // If we're using IPv6, make sure we don't accept V4-mapped connections + if (address.getFamily() == AF_INET6) { + int flag = 1; + if (::setsockopt(socket, IPPROTO_IPV6, IPV6_V6ONLY, + &flag, sizeof(flag))) { + throw AsyncSocketException( + AsyncSocketException::NOT_OPEN, + "Failed to set IPV6_V6ONLY", + errno); + } + } + // bind to the address sockaddr_storage addrStorage; address.getAddress(&addrStorage); -- 2.34.1