Hi Monks,
I have a server that has two NICs, eth1(192.168.0.1) and eth2(192.168.1.1). Each NIC can receive the same multicast packets to 224.10.10.10:12345. The multicast traffic to the two NICs are via two ISOLATED routing paths to provide resiliency. I'm writing a Perl program to monitor the multicast traffic via each NIC. The idea is that if I don't get any multicast packets from a NIC, I can suspect there is something wrong with that multicast path. A sample program with IO::Socket::Multicast is shown below.
The problem is that if NIC1 receives packet A and NIC2 receives packet A', the recv() call of both threads gets both A and A'! This defeat the purpose that if one mcast path is down, recv() returns nothing for the socket associated with the NIC connected to the mcast path with problem coz recv() can still get data from the NIC without issue. Any one can shred some light on why the sockets gets the data from all the NICs?
#!/usr/bin/perl -w
use warnings;
use strict;
use IO::Socket::Multicast;
use threads;
use threads::shared;
my $thread1 = threads->create(\&MulticastListen, '192.168.0.1');
$thread1->detach();
my $thread2 = threads->create(\&MulticastListen, '192.168.1.1');
$thread2->detach();
while (1) {
# Some codes here
}
#################
## Subroutines ##
#################
sub MulticastListen {
my $interfaceIP = shift;
my $Socket = IO::Socket::Multicast->new(
LocalPort => '12345',
LocalAddr => '224.10.10.10',
ReuseAddr => 1
);
$Socket->mcast_add('224.10.10.10', $interfaceIP );
while (1) {
$Socket->recv( $Data, 1024 );
print "[$Data]\n";
}
}