.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Paranoid::Network::IPv6 3pm" .TH Paranoid::Network::IPv6 3pm 2024-03-07 "perl v5.38.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME Paranoid::Network::IPv6 \- IPv6\-related functions .SH VERSION .IX Header "VERSION" \&\f(CW$Id:\fR lib/Paranoid/Network/IPv6.pm, 2.10 2022/03/08 00:01:04 acorliss Exp $ .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 1 \& use Paranoid::Network::IPv6; \& \& @net = ipv6NetConvert($netAddr); \& $rv = ipv6NetIntersect($net1, $net2); .Ve .PP or .PP .Vb 1 \& use Paranoid::Network::IPv6 qw(:all); \& \& print "Valid IP address\en" if $netAddr =~ /^@{[ IPV6REGEX ]}$/; \& \& @net = ipv6NetConvert($netAddr); \& $broadcast = $net[IPV6BRDCST]; \& \& use Paranoid::Network::IPv6 qw(:ipv6Sort); \& \& @nets = sort ipv6StrSort @nets; \& @nets = sort ipv6PackedSort @nets; \& @nets = sort ipv6NumSort @nets; .Ve .SH DESCRIPTION .IX Header "DESCRIPTION" This module contains a few convenience functions for working with IPv6 addresses. .SH "IMPORT LISTS" .IX Header "IMPORT LISTS" This module exports the following symbols by default: .PP .Vb 1 \& ipv6NetConvert ipv6NetPacked ipv6NetIntersect .Ve .PP The following specialized import lists also exist: .PP .Vb 7 \& List Members \& \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- \& base @defaults \& constants MAXIPV6CIDR IPV6REGEX IPV6CIDRRGX IPV6BASE \& IPV6BRDCST IPV6MASK \& ipv6Sort ipv6StrSort ipv6PackedSort ipv6NumSort \& all @base @constants @ipv6Sort .Ve .SH SUBROUTINES/METHODS .IX Header "SUBROUTINES/METHODS" .SS ipv6NetConvert .IX Subsection "ipv6NetConvert" .Vb 1 \& @net = ipv6NetConvert($netAddr); .Ve .PP This function takes an IPv4 network address in string format and converts it into and array of arrays. The arrays will contain the base network address, the broadcast address, and the netmask, each split into native 32bit integer format chunks. Each sub array is essentially what you would get from: .PP .Vb 1 \& @chunks = unpack \*(AqNNNN\*(Aq, inet_pton(AF_INET6, \*(Aq::1\*(Aq); .Ve .PP using '::1' as the sample IPv6 address. .PP The network address must have the netmask in CIDR format. In the case of a single IP address, the array with only have one subarray, that of the IP itself, split into 32bit integers. .PP Passing any argument to this function that is not a string representation of an IP address (including undef values) will cause this function to return an empty array. .SS ipv6NetPacked .IX Subsection "ipv6NetPacked" .Vb 1 \& @net = ipv6NetPacked(\*(Aqfe80::/64\*(Aq); .Ve .PP This function is a wrapper for \fBipv6NetConvert\fR, but instead of subarrays each element is the packed (opaque) string as returned by \fBinet_pton\fR. .SS ipv6NetIntersect .IX Subsection "ipv6NetIntersect" .Vb 1 \& $rv = ipv6NetIntersect($net1, $net2); .Ve .PP This function tests whether an IP or subnet intersects with another IP or subnet. The return value is essentially boolean, but the true value can vary to indicate which is a subset of the other: .PP .Vb 3 \& \-1: destination range encompasses target range \& 0: both ranges do not intersect at all \& 1: target range encompasses destination range .Ve .PP The function handles the same string formats as \fBipv6NetConvert\fR, but will allow you to test single IPs in integer format as well. .SS ipv6StrSort .IX Subsection "ipv6StrSort" .Vb 1 \& @sorted = sort ipv6StrSort @nets; .Ve .PP This function allows IPv6 addresses and networks to be passed in string format. Networks can be in CIDR format. Sorts in ascending order. :w .SS ipv6PackedSort .IX Subsection "ipv6PackedSort" .Vb 1 \& @sorted = sort ipv6PackedSort @nets; .Ve .PP This function sorts addresses that are in packed format, such as returned by inet_pton. Sorts in ascending order. .SS ipv6NumSort .IX Subsection "ipv6NumSort" .Vb 1 \& @sorted = sort ipv6NumSort @nets; .Ve .PP This function sorts addresses that are in unpacked, native integer format, such as one gets from: .PP .Vb 1 \& @ip = unpack \*(AqNNNN\*(Aq, inet_pton(AF_INET6, $ipAddr); .Ve .PP Sorts in ascending order. List of addresses should be a list of lists. .SH CONSTANTS .IX Header "CONSTANTS" These are only imported if explicitly requested or with the \fB:all\fR tag. .SS MAXIPV6CIDR .IX Subsection "MAXIPV6CIDR" Simply put: 128. This is the largest CIDR notation supported in IPv6. .SS IPV6REGEX .IX Subsection "IPV6REGEX" Regular expression. .PP You can use this for validating IP addresses as such: .PP .Vb 1 \& $ip =~ m#^@{[ IPV6REGEX ]}$#; .Ve .PP or to extract potential IPs from extraneous text: .PP .Vb 1 \& @ips = ( $string =~ m#(@{[ IPV6REGEX ]})#g); .Ve .SS IPV6CIDRRGX .IX Subsection "IPV6CIDRRGX" Regular expression. .PP By default this will extract CIDR notation network addresses: .PP .Vb 1 \& @networks = ( $string =~ m#(@{[ IPV6CIDRRGX ]})#si ); .Ve .SS IPV6BASE .IX Subsection "IPV6BASE" This is the ordinal index of the base network address as returned by \&\fBipv6NetConvert\fR. .SS IPV6BRDCST .IX Subsection "IPV6BRDCST" This is the ordinal index of the broadcast address as returned by \&\fBipv6NetConvert\fR. .SS IPV6MASK .IX Subsection "IPV6MASK" This is the ordinal index of the network mask as returned by \&\fBipv6NetConvert\fR. .SH DEPENDENCIES .IX Header "DEPENDENCIES" .IP o 4 .IX Item "o" Paranoid .IP o 4 .IX Item "o" Paranoid::Debug .IP o 4 .IX Item "o" Paranoid::Network::Socket .SH "BUGS AND LIMITATIONS" .IX Header "BUGS AND LIMITATIONS" .SH AUTHOR .IX Header "AUTHOR" Arthur Corliss (corliss@digitalmages.com) .SH "LICENSE AND COPYRIGHT" .IX Header "LICENSE AND COPYRIGHT" This software is free software. Similar to Perl, you can redistribute it and/or modify it under the terms of either: .PP .Vb 7 \& a) the GNU General Public License \& as published by the \& Free Software Foundation ; either version 1 \& , or any later version \& , or \& b) the Artistic License 2.0 \& , .Ve .PP subject to the following additional term: No trademark rights to "Paranoid" have been or are conveyed under any of the above licenses. However, "Paranoid" may be used fairly to describe this unmodified software, in good faith, but not as a trademark. .PP (c) 2005 \- 2020, Arthur Corliss (corliss@digitalmages.com) (tm) 2008 \- 2020, Paranoid Inc. (www.paranoid.com)