Hello,
On a multi-homed host, I want to create a separate socket for each
multicast interface. So I have come up with the solution attached
below. This solution works fine, except for one problem: if a packet
is received on the given multicast-group, this packet is received on
_all_ sockets and not only on the one that is bound to the receiving
port.
Any hints how to tell IO::Socket::Multicast that it should deliver
the packet only to the socket that listens on the receiving interface?
BTW: this is ubuntu-8.10 with Linux 2.6.27-7-generic
#! /usr/bin/perl
use strict;
use warnings;
use IO::Handle;
use IO::Select;
use IO::Socket::INET;
use IO::Socket::Multicast;
use IO::Interface::Simple;
my $rdfds = IO::Select->new();
my @ssdp_server;
foreach my $if (IO::Interface::Simple->interfaces) {
my $adr=$if->address;
next unless $adr =~ /^(192|172)/;
next unless $if->is_multicast;
print "$adr\n";
my $socket = IO::Socket::Multicast->new (LocalAddr=>"239.255.255.250",
LocalPort=>1900,
ReuseAddr=>1) or die;
$socket->mcast_add("239.255.255.250", $adr);
$socket->mcast_if($adr);
$socket->mcast_ttl(4);
$socket->mcast_loopback(0);
$rdfds->add($socket);
}
while (1) {
my @ready=$rdfds->can_read (0);
foreach my $fh (@ready) {
print $fh->mcast_if, "\n";
$fh->recv(my $data, 1024);
# print "$data\n";
}
}
|