0

I wrote a multithread program in Python, that analyses traffic from two multicast addresses with the same port, however it looks like my threads don't distinguish from where are datagram's coming.

Information:

1st multicast address: 239.0.1.104:12345 with throughput of 10.69 Mbps

2nd multicast address: 239.0.1.105:12345 with throughput of 6.08 Mbps

The goal of my program is to call analyser two times by two different threads, the desired outcome is that program would print:

Received 10.69 Mbps! Received 6.08 Mbps!

However currently my program sums up both multicasts and prints:

Received 16.78 Mbps Received 16.78 Mbps

So I wanted to forward address let's say from 239.0.1.105 to port 12346 instead of 12345 and pass this port into my program hoping that this will help program to distinguish which datagrams are coming to which socket.

How can I do this using iptables?

Also, If this would help, there is the issue of my program asked on programming stack: Programming stack question

I modified a little bit code to be called by functions, however general idea is the same:

Current code

ifconfig, my interface and my address

ifconfig, my interface and my address

Route Table

route table

Netstat Output

netstat

kenlukas
  • 2,886
  • 2
  • 14
  • 25
  • Hi, please don't crosspost. As you have one problem with the multicast, I dont see why a iptable rule might help, please find the bug first, and if needed come back after to create the iptables rules – yagmoth555 Aug 30 '19 at 16:09
  • For your bug I just suspect that .bind(('', MCAST_PORT)) is called, as you define IS_ALL_GROUPS = True – yagmoth555 Aug 30 '19 at 16:11
  • That was actually true. I had problem with this for 2 weeks... Could You please explain me what happen in my function `socket_creator`? As far as I understand: `socket_name = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)` => creating socket with IP proto ver 4, that will receive MC datagrams using UDP. `socket_name.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)` this is responsible for setting parameter that socket could use the same address (and in this case, port, because SO_REUSEADDR = SO_REUSEPORT for Multicasts). – Jędrzej Kieruj Sep 02 '19 at 07:17
  • `if IS_ALL_GROUPS: socket_name.bind(('', MCAST_PORT))` means that if `IS_ALL_GROUPS` is true, bind socket to any addres, and `else: socket_name.bind((MCAST_GRP, MCAST_PORT))` means bind socket to specific given IP address. `mreq = struct.pack("4sl", socket.inet_aton(MCAST_GRP), socket.INADDR_ANY)` means convert IP address to binary form and `socket_name.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq)` means that we add membership of group. However I don't understand some thing. Why if I used only one MC_group and set `is_all_groups` to `true` program didnt bound it? – Jędrzej Kieruj Sep 02 '19 at 07:27
  • It was only one addres, and "any" address so in my opinion program should think "okay, this is any addres so I will bind to it". And how does the computer or program distinguish summing up the results? In other words, was the option `is_all_groups=false` setting only one socket that gathered both results, and setting it to true allowed it to open more, or how to understand it? – Jędrzej Kieruj Sep 02 '19 at 07:28

0 Answers0