.\" Automatically generated by Pod::Man 2.25 (Pod::Simple 3.16) .\" .\" 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" '' '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 turned on, 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. .ie \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . nr % 0 . rr F .\} .el \{\ . de IX .. .\} .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "Paranoid::Network::IPv4 3pm" .TH Paranoid::Network::IPv4 3pm "2012-05-29" "perl v5.14.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::IPv4 \- IPv4\-related functions .SH "VERSION" .IX Header "VERSION" \&\f(CW$Id:\fR IPv4.pm,v 0.1 2012/05/29 21:37:44 acorliss Exp $ .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use Paranoid::Network::IPv4; \& \& @net = ipv4NetConvert($netAddr); \& $rv = ipv4NetIntersect($net1, $net2); .Ve .PP or .PP .Vb 1 \& use Paranoid::Network::IPv4 qw(:all); \& \& print "Valid IP address\en" if $netAddr =~ /^@{[ IPV4REGEX ]}$/; \& \& @net = ipv4NetConvert($netAddr); \& $broadcast = $net[IPV4BRDCST]; .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This module contains a few convenience functions for working with IPv4 addresses. .PP By default only the subroutines themselves are imported. Requesting \fB:all\fR will also import the constants as well. .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. .SH "CONSTANTS" .IX Header "CONSTANTS" These are only imported if explicity 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: \fBqr/(?:\ed{1,3}\e.){3}\ed{1,3}/sm\fR .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 .Vb 1 \& qr#(@{[ IPV4REGEX ]})(?:/(\ed+|@{[ IPV4REGEX ]}))?#sm .Ve .PP By default this will extract an \s-1IP\s0 or \s-1CIDR\s0 notation network address: .PP .Vb 1 \& ($net, $mask) = ( $ip =~ m#^@{[ IPV4CIDRRGX ]}$# ); .Ve .PP In the case of a simple \s-1IP\s0 address \fB\f(CB$mask\fB\fR will be undefined. .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::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) 2012, Arthur Corliss (corliss@digitalmages.com)