title: UDP packet sent to a multicast destination is sent via the loopback interface
body: <p>I'm running <em>Windows 10</em>.
  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 <a href="https://trac.videolan.org/vlc/ticket/17477" rel="nofollow">here</a>).</p>
  
  <p>Example code:</p>
  
  <pre><code>import socket
  s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  s.sendto(b"herpyderp", ('224.0.0.251', 5353))
  </code></pre>
  
  <p>The packet is seen on the loopback interface only (used <em>Microsoft Message Analyzer</em> to sniff).</p>
  
  <p>I tried inspecting the routing table via <code>route print</code>, and got the following output:</p>
  
  <pre><code>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
  ===========================================================================
  </code></pre>
  
  <p>You'll note the metric indicates the packet should be sent through my 'default' interface.</p>
  
  <p>I then tried inspecting the interface metric via the <em>PowerShell</em> <code>Get-NetIPInterface</code> cmdlet (as implied <a href="https://blogs.technet.microsoft.com/networking/2015/08/14/adjusting-the-network-protocol-bindings-in-windows-10/" rel="nofollow">here</a>), and got the following output:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>You'll note the <code>InterfaceMetric</code> field also seems to indicate my packet should be sent through the 'default' interface rather than through the loopback interface.</p>
  
  <p>Forcing the socket to send the packet through a different interface via <code>s.setsockopt(socket.IP_MULTICAST_IF, ...)</code> works, but I shouldn't need to do that.</p>
  
  <p>You'll note that there are two Ethernet interfaces corresponding to two network cards on my motherboard. When I connected the cable to <em>Ethernet</em> instead of <em>Ethernet 3</em>, the code above started behaving as I expected and the packet was sent through that interface rather than through the loopback interface.</p>
  
  <p>What is going on?</p>