Hi, I came across this "IO::Socket::Multicast" in CPAN and my goal is to "tunnel" multicast packets across unicast network and then finally converting them back to multicast. For the multicast to unicast portion, I managed to use the above module to convert multicast packets to unicast address.
#!/usr/bin/perl use IO::Socket::Multicast; use strict; my $multicast_ip = '232.0.64.4'; my $multicast_port = '9100'; my $if = 'eth1'; my $in_sock = IO::Socket::Multicast->new(Proto=>'udp',LocalPort=>$mult +icast_port); $in_sock->mcast_add($multicast_ip, $if) || die "\nCouldn't set group: +$!\n"; my $dest_ip = '10.10.20.20:9100'; my $out_sock = IO::Socket::Multicast->new(Proto=>'udp',PeerAddr=>$dest +_ip); while (1) { my $data; next unless $in_sock->recv($data,1024); $out_sock->send($data) }
However, I need to listen and forward packets on 30 different ports. Question is how do I efficiently create 30 instance of the below code without typing them out line by line? Second question is, are there better ways to achieve this multicast tunneling in Perl without using any 3rd party tunneling applications?
my $in_sock = IO::Socket::Multicast->new(Proto=>'udp',LocalPort=>$mult +icast_port);
Thanks.

In reply to Multicast to Unicast to Multicast by iphony

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.