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"; } }

In reply to Same multicast packet received by multiple NICs by sophate

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.