VinsWorldcom has asked for the wisdom of the Perl Monks concerning the following question:
QUESTION:What's the best cross-platform / backward compatible way to support IPv4 and IPv6 in Perl servers?
My research / testing:
I have a few modules on CPAN that create simple servers for listening and parsing of messages (shameless plug: Net::Syslogd and Net::SNMPTrapd). Currently, they support IPv4 by creating the listener with IO::Socket::INET.
I've been doing some work / testing and some reading on Perl support for IPv6 lately (IPv6 Name Resolution). I'm wondering what the best way to support both IPv4 and IPv6 in a Perl server would be?
Currently, I've done something with IO::Select and both IO::Socket::INET/6. Psuedo code below:
... # determine v4 or v6, nothing selected - then both if (!defined($opt{ipv4}) && !defined($opt{ipv6})) { $opt{ipv4} = $opt{ipv6} = 1 } ... # server (select between v4 and v6 if both exist) my $server = IO::Select->new(); # v4 server if ($opt{ipv4}) { my $server4 = IO::Socket::INET->new( Proto => 'tcp', LocalPort => $opt{port}, Listen => SOMAXCONN, Reuse => 1 ) or die "$0: Unable to create + IPv4 server: $!\n"; $server->add($server4) } # v6 server if ($opt{ipv6}) { my $server6 = IO::Socket::INET6->new( Proto => 'tcp', LocalPort => $opt{port}, Listen => SOMAXCONN, Reuse => 1 ) or die "$0: Unable to creat +e IPv6 server: $!\n"; $server->add($server6) } ... # determine which server has data while (my @servers = $server->can_read) { # loop servers for my $svr (@servers) { # read from v4 or v6 server that has data while(my $client = $svr->accept()) { #DO STUFF } } }
The code works fine - no problem / debug there. According to 'corelist', Socket6, IO::Socket::INET6 and "the new drop-in replacement" IO::Socket::IP aren't in 5.12.3 (the version I'm using) and don't appear to be in 5.14 according to http://perldoc.perl.org/index-modules-I.html.
So what are your opinions on the best way to support IPv4 and IPv6 in Perl servers:
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: How best to support IPv4/v6 in Perl server
by Anonymous Monk on Jan 26, 2012 at 17:18 UTC | |
by VinsWorldcom (Prior) on Jan 26, 2012 at 17:23 UTC | |
Re: How best to support IPv4/v6 in Perl server
by Rhandom (Curate) on Jan 30, 2012 at 15:11 UTC |