.\" -*- 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::IPv4 3pm" .TH Paranoid::Network::IPv4 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::IPv4 \- IPv4\-related functions .SH VERSION .IX Header "VERSION" \&\f(CW$Id:\fR lib/Paranoid/Network/IPv4.pm, 2.10 2022/03/08 00:01:04 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. .SH "IMPORT LISTS" .IX Header "IMPORT LISTS" This module exports the following symbols by default: .PP .Vb 1 \& ipv4NetConvert ipv4NetIntersect .Ve .PP The following specialized import lists also exist: .PP .Vb 7 \& List Members \& \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- \& base @defaults \& constants MAXIPV4CIDR IPV4REGEX IPV4CIDRRGX IPV4BASE \& IPV4BRDCST IPV4MASK \& ipv4Sort ipv4NumSort ipv4StrSort ipv4PackedSort \& all @base @constants @ipv4sort .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 CIDR format or dotted quads. .PP In the case of a single IP address, the array with only have one element, that of the IP in integer format. .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 ipv4NetIntersect .IX Subsection "ipv4NetIntersect" .Vb 1 \& $rv = ipv4NetIntersect($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 \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 CIDR 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 MAXIPV4CIDR .IX Subsection "MAXIPV4CIDR" Simply put: 32. This is the largest CIDR notation supported in IPv4. .SS IPV4REGEX .IX Subsection "IPV4REGEX" Regular expression. .PP You can use this for validating IP 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 IPV4CIDRRGX .IX Subsection "IPV4CIDRRGX" Regular expression. .PP By default this will test a CIDR 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 IPV4BASE .IX Subsection "IPV4BASE" This is the ordinal index of the base network address as returned by \&\fBipv4NetConvert\fR. .SS IPV4BRDCST .IX Subsection "IPV4BRDCST" This is the ordinal index of the broadcast address as returned by \&\fBipv4NetConvert\fR. .SS IPV4MASK .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 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)