IO::Socket::Multicast in limbo?

R

RayB

I've a device that's sending out a packet to 225.1.1.1 connected to a
Fedora Core 3 box, running with a local subnet address 192.168.1.0
connected to eth1. I installed ethereal on the linux server and can
verify that the packet coming in through eth1 are indeed source
192.168.1.100 (the address the device uses (in this case .100) is
based upon dhcp server running on the linux box, so I know the
interface is working.) and destination 225.1.1.1

Other info about the packet incoming: udp srcport:1024 dstport: 1118

Pertty simple. Linux Server eth1: <---> hub <---> device (or two)

I thought I could use the IO::Socket::Multicast module to receive the
initial packet, but it just sits and hangs at the recv call. I've
tried writing a simple UDP server receiver as well, but it behaves the
same way. I admit I'm pretty new at the jargon here and have tried to
change the ports etc, but it always behaves the same. I apologize if
this is an OS configuration issue, but does anyone have any ideas why
I might not be able to see these packets?

(Here's the multicast script I'm using... I got it from a book that
I'm reading, which is decent, but not specific enough for me to know
if there's something else I should be doing, regarding the setup of my
system.)

#!/usr/bin/perl
$|=1;
use IO::Socket;
use IO::Socket::Multicast;
my $port = 1118;
my $addr = '225.1.1.1';
my $sock = IO::Socket::Multicast->new('LocalPort' => $port) or die
"Can't create socket:$!";

print $sock->mcast_if; //value is set to "any" by default

$sock->mcast_if("eth1");
$sock->mcast_add($addr) or die "mcast_add: $!";

while (1) {
my ($msg, $peer);
die "recv error: $!" unless $peer = recv($sock, $msg, 1024, 0); //it
hangs here...
my ($port, $peeraddr) = sockaddr_in($peer);
print inet_ntoa($peeraddr) . ":" . inet_ntoa($portaddr) . ": $msg
\n";
}

I have a feeling the solution is a simple issue, so I figure I'll post
this here. If there's a better newsgroup for this post, I'd be pleased
to go there.

--Ray
beanleafpress.com
 
T

Thomas Kratz

RayB said:
#!/usr/bin/perl
$|=1;
use IO::Socket;
use IO::Socket::Multicast;
my $port = 1118;
my $addr = '225.1.1.1';
my $sock = IO::Socket::Multicast->new('LocalPort' => $port) or die
"Can't create socket:$!";

print $sock->mcast_if; //value is set to "any" by default

$sock->mcast_if("eth1");

perldoc IO::Socket::Multicast says
$sock->mcast_if is for *outgoing* multicasts.
$sock->mcast_add($addr) or die "mcast_add: $!";

$sock->mcast_add($addr, 'eth1') or die "mcast_add: $!";
while (1) {
my ($msg, $peer);
die "recv error: $!" unless $peer = recv($sock, $msg, 1024, 0); //it
hangs here...
my ($port, $peeraddr) = sockaddr_in($peer);
print inet_ntoa($peeraddr) . ":" . inet_ntoa($portaddr) . ": $msg\n";

print inet_ntoa($peeraddr) . ":" . $port . ": $msg\n";

you didn't have $portaddr. Please post code that is strict compliant.

apart from getting it to compile your script runs fine here
(WinXP, perl 5.8.8, ISM 1.04), with a simple multicast sender
from the local machine like this:

use strict;
use warnings;
use IO::Socket::Multicast;
my $s = IO::Socket::Multicast->new() or die $!;
for ( 1..100 ) {
$s->mcast_send($_ x 100, '225.1.1.1:1118');
sleep(1);
}

Thomas

--
$/=$,,$_=<DATA>,s,(.*),$1,see;__END__
s,^(.*\043),,mg,@_=map{[split'']}split;{#>J~.>_an~>>e~......>r~
$_=$_[$%][$"];y,<~>^,-++-,?{$/=--$|?'"':#..u.t.^.o.P.r.>ha~.e..
'%',s,(.),\$$/$1=1,,$;=$_}:/\w/?{y,_, ,,#..>s^~ht<._..._..c....
print}:y,.,,||last,,,,,,$_=$;;eval,redo}#.....>.e.r^.>l^..>k^.-
 
R

RayB

RayB wrote:
perldoc IO::Socket::Multicast says
$sock->mcast_if is for *outgoing* multicasts.
$sock->mcast_add($addr, 'eth1') or die "mcast_add: $!";

Heh. Thanks Thomas for the correction. Now that it's pointed out to
me, I don't see how I could've missed it. :)

[snip]
print inet_ntoa($peeraddr) . ":" . $port . ": $msg\n";
you didn't have $portaddr. Please post code that is strict compliant.

Thanks again. I've never gotten the script past the recv, hence
everything after that line was... well... untested. :)

I've added your suggested changes, but unfortunately it continues to
hand on that same spot.

I'm curious why Ethereal receives the packet, but my script can't. I'm
curious if Perl is reliant upon some feature of the IP stack or OS
that I just don't know about (being a TCP/IP and Linux (FC-3) newbie),
or if there's some configuration somewhere I need to tweak or some
flag in the config that is different on my OS. I know ethereal uses
Pcap stuff, and I see terms like "promiscuous mode" that I don't know
if they're necessary for my script to engage in order to see it, or if
there's something else I'm missing.

Anyhow thanks for the pointers thusfar. Little by little it'll come,
so thanks for taking the time to respond.

Best regards,

--Ray
 
T

Thomas Kratz

RayB said:
I've added your suggested changes, but unfortunately it continues to
hand on that same spot.

Did you try to use my posted send script to test the multicasts locally?
If yes, I would bet on some OS issue. Do you have anything else on your
machine that is successfully receiving multicasts?

I'm not a Linux hack but you could check:
http://www.yolinux.com/TUTORIALS/LinuxTutorialNetworking.html#MULTICAST

Thomas

--
$/=$,,$_=<DATA>,s,(.*),$1,see;__END__
s,^(.*\043),,mg,@_=map{[split'']}split;{#>J~.>_an~>>e~......>r~
$_=$_[$%][$"];y,<~>^,-++-,?{$/=--$|?'"':#..u.t.^.o.P.r.>ha~.e..
'%',s,(.),\$$/$1=1,,$;=$_}:/\w/?{y,_, ,,#..>s^~ht<._..._..c....
print}:y,.,,||last,,,,,,$_=$;;eval,redo}#.....>.e.r^.>l^..>k^.-
 
R

RayB

Did you try to use my posted send script to test the multicasts locally?
If yes, I would bet on some OS issue. Do you have anything else on your
machine that is successfully receiving multicasts?

Hey Thomas, Thanks a ton for your help. I tried the little send script
and to my surprise it worked. I captured the working packets along
side the nonworking ones, and saw almost immediately that I'd been
listening to the wrong port the whole time... 1119 not 1118... Sigh...
I then proceeded to bang my head against the wall for a while... :)

Your help was invaluable, though I feel ridiculous posting the
solution behind the problem... :)

--Ray
 
T

Thomas Kratz

RayB said:
Hey Thomas, Thanks a ton for your help. I tried the little send script
and to my surprise it worked. I captured the working packets along
side the nonworking ones, and saw almost immediately that I'd been
listening to the wrong port the whole time... 1119 not 1118... Sigh...
I then proceeded to bang my head against the wall for a while... :)

I hope you didn't do any permanent damage :)
Your help was invaluable, though I feel ridiculous posting the
solution behind the problem... :)

No sweat, it happens to all of us...

Thomas

--
$/=$,,$_=<DATA>,s,(.*),$1,see;__END__
s,^(.*\043),,mg,@_=map{[split'']}split;{#>J~.>_an~>>e~......>r~
$_=$_[$%][$"];y,<~>^,-++-,?{$/=--$|?'"':#..u.t.^.o.P.r.>ha~.e..
'%',s,(.),\$$/$1=1,,$;=$_}:/\w/?{y,_, ,,#..>s^~ht<._..._..c....
print}:y,.,,||last,,,,,,$_=$;;eval,redo}#.....>.e.r^.>l^..>k^.-
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,189
Members
46,735
Latest member
HikmatRamazanov

Latest Threads

Top