I'm running Windows 10. I had recently diagnosed an issue with my computer where any packet sent to a multicast destination is sent through the loopback interface rather than the 'default' one (see my adventures here).
Example code:
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.sendto(b"herpyderp", ('224.0.0.251', 5353))
The packet is seen on the loopback interface only (used Microsoft Message Analyzer to sniff).
I tried inspecting the routing table via route print
, and got the following output:
IPv4 Route Table
===========================================================================
Active Routes:
Network Destination Netmask Gateway Interface Metric
0.0.0.0 0.0.0.0 10.0.10.138 10.0.10.30 35
10.0.10.0 255.255.255.0 On-link 10.0.10.30 291
10.0.10.30 255.255.255.255 On-link 10.0.10.30 291
10.0.10.255 255.255.255.255 On-link 10.0.10.30 291
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
224.0.0.0 240.0.0.0 On-link 10.0.10.30 291
255.255.255.255 255.255.255.255 On-link 127.0.0.1 331
255.255.255.255 255.255.255.255 On-link 10.0.10.30 291
===========================================================================
You'll note the metric indicates the packet should be sent through my 'default' interface.
I then tried inspecting the interface metric via the PowerShell Get-NetIPInterface
cmdlet (as implied here), and got the following output:
ifIndex InterfaceAlias AddressFamily NlMtu(Bytes) InterfaceMetric Dhcp ConnectionState PolicyStore
------- -------------- ------------- ------------ --------------- ---- --------------- -----------
2 Ethernet 3 IPv6 1500 35 Enabled Connected ActiveStore
7 Ethernet IPv6 1500 5 Enabled Disconnected ActiveStore
1 Loopback Pseudo-Interface 1 IPv6 4294967295 75 Disabled Connected ActiveStore
3 isatap.home IPv6 1280 75 Disabled Disconnected ActiveStore
17 Teredo Tunneling Pseudo-Inte... IPv6 1280 75 Enabled Connected ActiveStore
2 Ethernet 3 IPv4 1500 35 Enabled Connected ActiveStore
7 Ethernet IPv4 1500 5 Enabled Disconnected ActiveStore
1 Loopback Pseudo-Interface 1 IPv4 4294967295 75 Disabled Connected ActiveStore
You'll note the InterfaceMetric
field also seems to indicate my packet should be sent through the 'default' interface rather than through the loopback interface.
Forcing the socket to send the packet through a different interface via s.setsockopt(socket.IP_MULTICAST_IF, ...)
works, but I shouldn't need to do that.
You'll note that there are two Ethernet interfaces corresponding to two network cards on my motherboard. When I connected the cable to Ethernet instead of Ethernet 3, the code above started behaving as I expected and the packet was sent through that interface rather than through the loopback interface.
What is going on?