iphony has asked for the wisdom of the Perl Monks concerning the following question:
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?#!/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) }
Thanks.my $in_sock = IO::Socket::Multicast->new(Proto=>'udp',LocalPort=>$mult +icast_port);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Multicast to Unicast to Multicast
by zwon (Abbot) on Jan 09, 2009 at 11:18 UTC |