From 4949721389fdb00b29cec1d959aaf21bc863abdc Mon Sep 17 00:00:00 2001 From: Steven Siloti Date: Sat, 2 Apr 2016 14:20:48 -0700 Subject: [PATCH] apply {get,set}_option to the appropriate socket based on the option's level This avoids spurious errors being returned when trying to apply IPv4 options to the IPv6 socket and vice-versa. --- include/libtorrent/udp_socket.hpp | 19 ++++++++++++++----- simulation/libsimulator | 2 +- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/include/libtorrent/udp_socket.hpp b/include/libtorrent/udp_socket.hpp index 81f79f6b2..47a358789 100644 --- a/include/libtorrent/udp_socket.hpp +++ b/include/libtorrent/udp_socket.hpp @@ -114,25 +114,34 @@ namespace libtorrent template void get_option(SocketOption const& opt, error_code& ec) { - m_ipv4_sock.get_option(opt, ec); #if TORRENT_USE_IPV6 - m_ipv6_sock.get_option(opt, ec); + if (opt.level(udp::v6()) == IPPROTO_IPV6) + m_ipv6_sock.get_option(opt, ec); + else #endif + m_ipv4_sock.get_option(opt, ec); } template void set_option(SocketOption const& opt, error_code& ec) { - m_ipv4_sock.set_option(opt, ec); + if (opt.level(udp::v4()) != IPPROTO_IPV6) + m_ipv4_sock.set_option(opt, ec); #if TORRENT_USE_IPV6 - m_ipv6_sock.set_option(opt, ec); + if (opt.level(udp::v6()) != IPPROTO_IP) + m_ipv6_sock.set_option(opt, ec); #endif } template void get_option(SocketOption& opt, error_code& ec) { - m_ipv4_sock.get_option(opt, ec); +#if TORRENT_USE_IPV6 + if (opt.level(udp::v6()) == IPPROTO_IPV6) + m_ipv6_sock.get_option(opt, ec); + else +#endif + m_ipv4_sock.get_option(opt, ec); } udp::endpoint proxy_addr() const { return m_proxy_addr; } diff --git a/simulation/libsimulator b/simulation/libsimulator index 66356b0ce..0151d5c17 160000 --- a/simulation/libsimulator +++ b/simulation/libsimulator @@ -1 +1 @@ -Subproject commit 66356b0ce99cd126c7c99df50609b3050ba44e5d +Subproject commit 0151d5c17fa3f4cf0ce518d0b8f90a23792c9b24