.\" Automatically generated by Pod::Man 4.10 (Pod::Simple 3.35) .\" .\" 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 .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . 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::IPv4 3pm" .TH Paranoid::Network::IPv4 3pm "2018-11-09" "perl v5.28.0" "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::IPv4 \- IPv4\-related functions .SH "VERSION" .IX Header "VERSION" \&\f(CW$Id:\fR lib/Paranoid/Network/IPv4.pm, 2.06 2018/08/05 01:21:48 acorliss Exp $ .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use Paranoid::Network::IPv4; \& \& @net = ipv4NetConvert($netAddr); \& $rv = ipv4NetIntersect($net1, $net2); \& \& use Paranoid::Network::IPv4 qw(:all); \& \& print "Valid IP address\en" if $netAddr =~ /^@{[ IPV4REGEX ]}$/; \& \& @net = ipv4NetConvert($netAddr); \& $broadcast = $net[IPV4BRDCST]; \& \& use Paranoid::Network::IPv4 qw(:ipv4Sort); \& \& @nets = sort ipv4StrSort @nets; \& @nets = sort ipv4PackedSort @nets; \& @nets = sort ipv4NumSort @nets; .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This module contains a few convenience functions for working with IPv4 addresses. .PP By default only \fBipv4NetConvert\fR and \fBipv4NetIntersect\fR are imported. Other symbol sets are: .PP .Vb 6 \& Name Description \& \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- \& all all functions/constants \& base default exported functions \& constants constants \& ipv4Sort sort functions .Ve .SH "SUBROUTINES/METHODS" .IX Header "SUBROUTINES/METHODS" .SS "ipv4NetConvert" .IX Subsection "ipv4NetConvert" .Vb 1 \& @net = ipv4NetConvert($netAddr); .Ve .PP This function takes an IPv4 network address in string format and converts it into an array containing the base network address, the broadcast address, and the netmask, in integer format. The network address can have the netmask in either \s-1CIDR\s0 format or dotted quads. .PP In the case of a single \s-1IP\s0 address, the array with only have one element, that of the \s-1IP\s0 in integer format. .PP Passing any argument to this function that is not a string representation of an \s-1IP\s0 address (including undef values) will cause this function to return an empty array. .SS "ipv4NetIntersect" .IX Subsection "ipv4NetIntersect" .Vb 1 \& $rv = ipv4NetIntersect($net1, $net2); .Ve .PP This function tests whether an \s-1IP\s0 or subnet intersects with another \s-1IP\s0 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 \fBipv4NetConvert\fR, but will allow you to test single IPs in integer format as well. .SS "ipv4StrSort" .IX Subsection "ipv4StrSort" .Vb 1 \& @sorted = sort ipv4StrSort @nets; .Ve .PP This function allows IPv4 addresses and networks to be passed in string format. Networks can be in \s-1CIDR\s0 format. Sorts in ascending order. .SS "ipv4PackedSort" .IX Subsection "ipv4PackedSort" .Vb 1 \& @sorted = sort ipv4PackedSort @nets; .Ve .PP This function sorts IPv4 addresses as returned by inet_aton. Sorts in ascending order. .SS "ipv4NumSort" .IX Subsection "ipv4NumSort" .Vb 1 \& @sorted = sort ipv4NumSort @nets; .Ve .PP This function is rather pointless, but is included merely for completeness. Addresses are in unpacked, native integer format, such as one gets from: .PP .Vb 1 \& $ip = unpack \*(AqN\*(Aq, inet_aton($ipAddr); .Ve .PP Sorts in ascending order. .SH "CONSTANTS" .IX Header "CONSTANTS" These are only imported if explicitly requested or with the \fB:all\fR tag. .SS "\s-1MAXIPV4CIDR\s0" .IX Subsection "MAXIPV4CIDR" Simply put: 32. This is the largest \s-1CIDR\s0 notation supported in IPv4. .SS "\s-1IPV4REGEX\s0" .IX Subsection "IPV4REGEX" Regular expression. .PP You can use this for validating \s-1IP\s0 addresses as such: .PP .Vb 1 \& $ip =~ m#^@{[ IPV4REGEX ]}$#; .Ve .PP or to extract potential IPs from extraneous text: .PP .Vb 1 \& @ips = ( $string =~ m#(@{[ IPV4REGEX ]})#gsm); .Ve .SS "\s-1IPV4CIDRRGX\s0" .IX Subsection "IPV4CIDRRGX" Regular expression. .PP By default this will test a \s-1CIDR\s0 notation or dotted quad network address: .PP .Vb 1 \& $netaddr =~ m#@{[ IPV4CIDRRGX ]}$#s; .Ve .PP or extract network addresses from a string: .PP .Vb 1 \& @networks = ( $string =~ m#(@{[ IPV4CIDRRGX ]})#s ); .Ve .SS "\s-1IPV4BASE\s0" .IX Subsection "IPV4BASE" This is the ordinal index of the base network address as returned by \&\fBipv4NetConvert\fR. .SS "\s-1IPV4BRDCST\s0" .IX Subsection "IPV4BRDCST" This is the ordinal index of the broadcast address as returned by \&\fBipv4NetConvert\fR. .SS "\s-1IPV4MASK\s0" .IX Subsection "IPV4MASK" This is the ordinal index of the network mask as returned by \&\fBipv4NetConvert\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 licensed under the same terms as Perl, itself. Please see http://dev.perl.org/licenses/ for more information. .PP (c) 2005 \- 2017, Arthur Corliss (corliss@digitalmages.com)