Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Tuesday, August 29, 2017 4:00 PM
Would appreciate if you could let me know the best place to ask this:
On my desktop windows 10 machines I am able to send multicast to a socket bound
to 127.0.0.1. However on my laptop windows 10 it refuses so send (WSAENETUNREACH).
I've compared routing tables and they appear the same for the multicast
addresses. Both have routes to 224.0.0/240 on interface 127.0.0.1.
What am I missing?
//////////////////////////////////////////////////////////////////////////////
The following code works fine sending a multicast packet on interface 192.168.1.77
on the laptop but it fails with WSAENETUNREACH if sent on interface 127.0.0.1.
//////////////////////////////////////////////////////////////////////////////
SOCKET m_Socket;
struct sockaddr_in m_sAddr;
int retCode;
int wsaErrCode;
DWORD nicAddrBE;
nicAddrBE = inet_addr( "127.0.0.1" ); // this fails to sendto (WSAENETUNREACH)
// nicAddrBE = inet_addr( "192.168.1.77" ); // this works
m_Socket = socket( AF_INET, SOCK_DGRAM, IPPROTO_UDP );
if( INVALID_SOCKET == m_Socket ) {
wsaErrCode = WSAGetLastError();
return false;
}
m_sAddr.sin_port = 0;
m_sAddr.sin_addr.s_addr = nicAddrBE;
retCode = bind( m_Socket, (SOCKADDR *)&m_sAddr, sizeof(sockaddr_in) );
if( SOCKET_ERROR == retCode ) {
wsaErrCode = WSAGetLastError();
}
#if 0 // this section doesn't have any effect on fixing the issue
if( 0 == retCode ) {
DWORD loop;
DWORD ip;
loop = 1;
retCode = setsockopt( m_Socket, IPPROTO_IP , IP_MULTICAST_LOOP, (const char*)&loop, sizeof(loop) );
if( SOCKET_ERROR == retCode ) {
wsaErrCode = WSAGetLastError();
}
ip = nicAddrBE;
retCode = setsockopt( m_Socket, IPPROTO_IP , IP_MULTICAST_IF, (const char*)&ip, sizeof(ip) );
if( SOCKET_ERROR == retCode ) {
wsaErrCode = WSAGetLastError();
}
}
#endif
// set up multicast destination
m_sAddr.sin_port = ntohs(40000);
m_sAddr.sin_addr.s_addr = inet_addr( "239.0.0.1" );
retCode = sendto( m_Socket, pBuf, bufSize, 0, (sockaddr*)&m_sAddr, sizeof(m_sAddr) );
if( SOCKET_ERROR == retCode ) {
wsaErrCode = WSAGetLastError();
// wsaErrCode == 10051 .. WSAENETUNREACH
}
//////////////////////////////////////////////////////////////////////////////
Routing table seems to have the correct entry for routing multicast to 127.0.0.1
route -4 print (this is with no outside ethernet connections)
Interface List 10...74 86 7a 23 cd 00 ......Realtek PCIe FE Family Controller 7...64 5a 04 54 b7 3b ......Dell Wireless 1705 802.11b/g/n (2.4GHZ) 8...16 5a 04 54 b7 3b ......Microsoft Wi-Fi Direct Virtual Adapter 5...56 5a 04 54 b7 3b ......Microsoft Hosted Network Virtual Adapter 3...64 5a 04 54 b7 3c ......Bluetooth PAN HelpText 1...........................Software Loopback Interface 1 6...00 00 00 00 00 00 00 e0 Teredo Tunneling Pseudo-Interface
IPv4 Route Table
Active Routes: Network Destination Netmask Gateway Interface Metric 127.0.0.0 255.0.0.0 On-link 127.0.0.1 331 127.0.0.1 255.255.255.255 On-link 127.0.0.1 331 127.255.255.255 255.255.255.255 On-link 127.0.0.1 331 224.0.0.0 240.0.0.0 On-link 127.0.0.1 331 255.255.255.255 255.255.255.255 On-link 127.0.0.1 331
Persistent Routes:
None
//////////////////////////////////////////////////////////////////////////////
Just to make sure this is not an issue, firewall is temporarily OFF
All replies (3)
Wednesday, October 11, 2017 1:50 PM
I am seeing the same problem as above. It can be reproduced with a little python:
>>> from socket import *
>>> s=socket(AF_INET,SOCK_DGRAM)
>>> s.bind(('127.0.0.1', 0))
>>> s.sendto('hello', ('239.0.0.1', 40000))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
socket.error: [Errno 10051] A socket operation was attempted to an unreachable network
Switching to a real interface works fine.
Wednesday, October 11, 2017 4:54 PM | 2 votes
The sendto() call succeeds when the multicast group has been joined.
There seems to be an issue when transmitting to a multicast group which is not subscribed to.
Tuesday, August 7, 2018 12:39 PM
The sendto() call succeeds when the multicast group has been joined.
There seems to be an issue when transmitting to a multicast group which is not subscribed to.
When I was reading this answer first time I did not get it. But now it makes sense for me.
So, when you send something to 127.0.0.1, Windows 10 knows for sure if there listener for data. If not, it returns error. Seems useless for me.