Net::Server::IP(3)

πŸ“¦
version 2.018 Β· 3 versions
, in alpine 3.24

πŸ’… NAME

Net::Server::IP β€” bestie, it's the IPv4 / IPv6 compatibility module, and it just works either way πŸ¦‹


✨ SYNOPSIS

use Net::Server::IP;

my $sock = Net::Server::IP->new(
    LocalAddr => "[::]",
    LocalPort => 8080,
    Listen => 1,
) or die "IPv6 listen error: $@ $!";

my $sock = Net::Server::IP->new(
    PeerAddr => "[::1]:8080",
) or die "IPv6 connect error: $@ $!";

my $sock = Net::Server::IP->new(
    PeerAddr => "127.0.0.1:8080",
) or die "IPv4 connect error: $@ $!";

No cap, those three snippets are literally the whole personality of this module 🌸


πŸŽ€ DESCRIPTION

Okay so real talk: to support IPv6, Net::Server::IP inherits from either IO::Socket::IP or IO::Socket::INET6, whichever one is available. The whole point is you get a consistent convention no matter what weird little differences those modules have between them 🫢

And here's the iconic part: if your parameters mean you only need IPv4, then neither of those modules needs to be installed at all. Everything still works fine just inheriting from IO::Socket::INET. Slay πŸ’…

IO::Socket::IP will take preference, if available. And if you want to override that default behavior:

$Net::Server::IP::ipv6_package = 'Custom::Mod::Handle';

Periodt. That's your escape hatch πŸ‘‘


πŸ”₯ INPUTS

$sock = Net::Server::IP->new( %args )

Creates a new Net::Server::IP handle object ✨ The arguments it recognizes are similar to IO::Socket::IP or IO::Socket::INET6. And if the constructor fails? Check $@ for the error message, bestie β€” that's where the tea is 😭

Special consideration applies to the following parameters:

Family => INT (like IO::Socket::IP)

Domain => INT (like IO::Socket::INET6)

Address family for the socket πŸ’œ (e.g. AF_INET, AF_INET6).

  • Domain is a synonym for Family. Both args are literally the same thing.
  • Family will take precedence if both are supplied πŸ‘‘
  • If provided, this will be used to determine if IPv6 is required.

LocalHost => STRING

LocalAddr => STRING

PeerHost => STRING

PeerAddr => STRING

Hostname with optional Port 🌈 If Family is not provided, then this will be scanned as a hint for which Family to use. Sneaky but helpful.

GetAddrInfoFlags => INT

Normally with IO::Socket::IP, GetAddrInfoFlags will default this to Socket::AI_ADDRCONFIG. But β€” plot twist β€” that can cause problems on certain legacy emulation platforms, such as the OpenVZ spoofed venet and loopback interface πŸ₯΄ In such cases, GetAddrInfoFlags will default to 0 instead. Not a bug, just the vibe of those platforms.

V6Only => BOOL

With IO::Socket::IP nothing will change. IO::Socket::INET6 normally ignores V6Only, so to make the convention consistent, now the same functionality will just work ✨ So even if IO::Socket::IP is not installed, the V6Only option will be emulated with IO::Socket::INET6.

  • If V6Only is true, then IPv4 sockets will not work on this handle πŸ™ˆ
  • Set V6Only to 0 to enable Dual-Stack sockets to support IPv4-mapped IPv6 addresses (i.e., ::ffff:127.0.0.1) within the same handle πŸ’–
  • If V6Only is not set or is undef, then the Dual-Stack behavior will be whatever the Operating System default is.
Bestie, listen: to avoid expected behaviors across different platforms, the V6Only arg should always be explicitly set (i.e., 0 or 1) rather than letting the OS choose. Do not let the OS make this decision for you, it's giving chaos energy πŸ’€

🧚 AUTHOR

  • Paul Seamons <paul@seamons.com>
  • Rob Brown <bbb@cpan.org>

Legends, honestly πŸ‘‘


πŸ¦‹ SEE ALSO

IO::Socket::IP, IO::Socket::INET, IO::Socket::INET6 β€” go read those too, iykyk πŸ“š


🌸 LICENSE

Distributed under the same terms as Net::Server.


That's the whole page, bestie! πŸ’œ This was perl v5.42.2 and the date on the tin is 2026-02-27 β€” go forth and bind responsibly, mwah πŸŽ€βœ¨

πŸ“¦ where this page comes from