Commit d6d816e9 authored by jselbie's avatar jselbie

IPv6 sockets don't get IPv4 bindings

parent ffe05770
......@@ -176,7 +176,6 @@ HRESULT CStunSocket::EnablePktInfo_IPV6(bool fEnable)
return EnablePktInfoImpl(level, option1, option2, fEnable);
}
HRESULT CStunSocket::EnablePktInfoOption(bool fEnable)
{
int family = _addrlocal.GetFamily();
......@@ -194,6 +193,27 @@ HRESULT CStunSocket::EnablePktInfoOption(bool fEnable)
return hr;
}
HRESULT CStunSocket::SetV6Only(int sock)
{
int optname = -1;
int result = 0;
HRESULT hr = S_OK;
int enabled = 1;
#ifdef IPV6_BINDV6ONLY
optname = IPV6_BINDV6ONLY;
#elif IPV6_V6ONLY
optname = IPV6_V6ONLY;
#else
return E_NOTIMPL;
#endif
result = setsockopt(sock, IPPROTO_IPV6, optname, (char *)&enabled, sizeof(enabled));
hr = (result == 0) ? S_OK : ERRNOHR ;
return hr;
}
HRESULT CStunSocket::SetNonBlocking(bool fEnable)
{
HRESULT hr = S_OK;
......@@ -221,6 +241,7 @@ Cleanup:
return hr;
}
void CStunSocket::UpdateAddresses()
{
sockaddr_storage addrLocal = {};
......@@ -263,6 +284,15 @@ HRESULT CStunSocket::InitCommon(int socktype, const CSocketAddress& addrlocal, S
sock = socket(addrlocal.GetFamily(), socktype, 0);
ChkIf(sock < 0, ERRNOHR);
if (addrlocal.GetFamily() == AF_INET6)
{
// Don't allow IPv6 socket to receive binding request from IPv4 client
// Because if we don't then an IPv4 client will get an IPv6 mapped address in the binding response
// I'm pretty sure you have to call this before bind()
// Intentionally ignoring result
(void)SetV6Only(sock);
}
if (fSetReuseFlag)
{
int fAllow = 1;
......
......@@ -38,6 +38,8 @@ private:
HRESULT EnablePktInfo_IPV4(bool fEnable);
HRESULT EnablePktInfo_IPV6(bool fEnable);
HRESULT SetV6Only(int sock);
public:
CStunSocket();
......@@ -60,6 +62,7 @@ public:
HRESULT EnablePktInfoOption(bool fEnable);
HRESULT SetNonBlocking(bool fEnable);
void UpdateAddresses();
HRESULT UDPInit(const CSocketAddress& local, SocketRole role);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment