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:


In reply to How best to support IPv4/v6 in Perl server by VinsWorldcom

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.