6

There is quite a few examples to RECEIVE multicast messages with a spcific network interface (NIC, e.g. eth0, 127.0.0.1 etc). However, there is few discussion/examples about how to SEND multicast (UDP) messages to a specific interface, e.g. local loop (127.0.0.1) instead of eth0 by default.

Background: RedHat Linux, Python, 224.1.1.1 5005

Python Code example in Multicast in Python

A similar discuss for IPv6 How to send multicast packets via a specfic interface in Linux

A similar discuss for Windows How to Multicast (send) to first NIC?

Thanks in advance.

Community
  • 1
  • 1
user1268888
  • 63
  • 1
  • 4

1 Answers1

5

The question that you've linked How to Multicast (send) to first NIC? mentions that you could use IP_MULTICAST_IF:

sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_IF, socket.inet_aton(addr))
Community
  • 1
  • 1
jfs
  • 346,887
  • 152
  • 868
  • 1,518
  • Don't forget to increase TTL – e271p314 Oct 29 '15 at 18:26
  • @e271p314: I don't remember what it is about but [the code example that is linked in the question appears to handle TTL already (since 2009)](http://stackoverflow.com/questions/603852/multicast-in-python). My answer sets a single option i.e., it only answers the question in the title. – jfs Oct 29 '15 at 18:32
  • First of all, thanks a lot, your answer is correct. when I tried it I saw I didn't get the multicast and was breaking my head to understand what is the issue. My TTL was configured to 2 because I copy pasted the code. After some time I realized from this [link](http://svn.python.org/projects/stackless/trunk/Demo/sockets/mcast.py) That I need to "Increase to reach other networks" So I just though that if might be usful to other which came to your answer get this tip too :-) – e271p314 Oct 29 '15 at 18:43