From: Peter Griess Date: Thu, 13 Aug 2015 17:19:09 +0000 (-0700) Subject: Set IPV6_V6ONLY in folly::AsyncUDPServerSocket X-Git-Tag: v0.54.0~9 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=98af46c55cdfc1a5b1b518f54703654931a1b009;p=folly.git Set IPV6_V6ONLY in folly::AsyncUDPServerSocket Summary: - This mirrors the behavior in AsyncServerSocket Reviewed By: @yfeldblum Differential Revision: D2338665 --- 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);