.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.40) .\" .\" 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 "Template::Plugin::IPAddr 3pm" .TH Template::Plugin::IPAddr 3pm "2021-01-08" "perl v5.32.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" Template::Plugin::IPAddr \- Template::Toolkit plugin handling IP\-addresses .SH "VERSION" .IX Header "VERSION" version 0.03 .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 3 \& # Create IPAddr object via USE directive... \& [% USE IPAddr %] \& [% USE IPAddr(prefix) %] \& \& # ...or via new \& [% ip = IPAddr.new(prefix) %] \& \& # Methods that return the different parts of the prefix \& [% IPAddr.addr %] \& [% IPAddr.addr_cidr %] \& [% IPAddr.cidr %] \& [% IPAddr.network %] \& [% IPAddr.netmask %] \& [% IPAddr.wildcard %] \& \& # Methods for retrieving usable IP\-adresses from a prefix \& [% IPAddr.first %] \& [% IPAddr.last %] .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This module implements an \f(CW\*(C`IPAddr\*(C'\fR class for handling IPv4 and IPv6\-address in an object-orientated way. The module is based on NetAddr::IP and works on IPv4 as well as IPv6\-addresses. .PP You can create a \f(CW\*(C`IPAddr\*(C'\fR object via the \f(CW\*(C`USE\*(C'\fR directive, adding any initial prefix as an argument. .PP .Vb 2 \& [% USE IPAddr %] \& [% USE IPAddr(prefix) %] .Ve .PP Once you've got a \f(CW\*(C`IPAddr\*(C'\fR object, you can use it as a prototype to create other \f(CW\*(C`IPAddr\*(C'\fR objects with the \fBnew()\fR method. .PP .Vb 2 \& [% USE IPAddr %] \& [% ip = IPAddr.new(prefix) %] .Ve .PP After creating an \f(CW\*(C`IPaddr\*(C'\fR object, you can use the supplied methods for retrieving properties of the prefix. .PP .Vb 4 \& [% USE IPAddr(\*(Aq10.0.0.0/24\*(Aq) %] \& [% IPAddr.netmask %] # 255.255.255.0 \& [% IPAddr.first %] # 10.0.0.1 \& [% IPAddr.last %] # 10.0.0.254 .Ve .SH "METHODS" .IX Header "METHODS" .SS "new" .IX Subsection "new" Creates a new IPAddr object using an initial value passed as a positional parameter. Any string which is accepted by NetAddr::IP\->new can be used as a parameter. .PP .Vb 3 \& [% USE IPAddr %] \& [% USE IPAddr(prefix) %] \& [% ip = IPAddr.new(prefix) %] .Ve .PP Examples of (recommended) formats of initial parameters that can be used: .PP .Vb 4 \& # IPv4 \& n.n.n.n # Host address \& n.n.n.n/m # CIDR notation \& n.n.n.n/m.m.m.m # address + netmask \& \& # IPv6 \& x:x:x:x:x:x:x:x # Host address \& x:x:x:x:x:x:x:x/m # CIDR notation \& ::n.n.n.n # IPv4\-compatible IPv6 address .Ve .PP When used as \f(CW\*(C`[% USE IPAddr %]\*(C'\fR the prefix assigned internally is \f(CW\*(C`0.0.0.0/0\*(C'\fR .SS "addr" .IX Subsection "addr" Returns the address part of the prefix as written in the initial value. .PP .Vb 2 \& [% USE IPAddr(\*(Aq10.1.1.1/24\*(Aq) %] \& [% IPAddr.addr %] # 10.1.1.1 \& \& [% USE IPAddr(\*(Aq2001:DB8::DEAD:BEEF\*(Aq) %] \& [% IPAddr.addr %] # 2001:db8::dead:beef .Ve .SS "addr_cidr" .IX Subsection "addr_cidr" Returns the \fIaddress\fR in \s-1CIDR\s0 notation, i.e. as \f(CW\*(C`address/prefixlen\*(C'\fR. .PP .Vb 2 \& [% USE IPAddr(\*(Aq10.1.1.1/255.255.255.0\*(Aq) %] \& [% IPAddr.addr_cidr %] # 10.1.1.1/24 \& \& [% USE IPAddr(\*(Aq2001:db8:a:b:c:d:e:f/48\*(Aq) %] \& [% IPAddr.addr_cidr %] # 2001:db8:a:b:c:d:e:f/48 .Ve .SS "cidr" .IX Subsection "cidr" Returns the \fIprefix\fR in \s-1CIDR\s0 notation, i.e. as \f(CW\*(C`network/prefixlen\*(C'\fR. .PP .Vb 2 \& [% USE IPAddr(\*(Aq10.1.1.1/255.255.255.0\*(Aq) %] \& [% IPAddr.cidr %] # 10.1.1.0/24 \& \& [% USE IPAddr(\*(Aq2001:db8:a:b:c:d:e:f/48\*(Aq) %] \& [% IPAddr.cidr %] # 2001:db8:a::/48 .Ve .PP Note that differs from the \f(CW\*(C`cidr\*(C'\fR method in NetAddr::IP (which returns \f(CW\*(C`address/prefixlen\*(C'\fR). You can retrieve an address on that format by using the \*(L"addr_cidr\*(R" method. .SS "first" .IX Subsection "first" Returns the first usable IP-address within the prefix. .PP .Vb 2 \& [% USE IPAddr(\*(Aq10.0.0.0/16\*(Aq) %] \& [% IPAddr.first %] # 10.0.0.1 .Ve .SS "last" .IX Subsection "last" Returns the last usable IP-address within the prefix. .PP .Vb 2 \& [% USE IPAddr(\*(Aq10.0.0.0/16\*(Aq) %] \& [% IPAddr.last %] # 10.0.255.254 .Ve .SS "network" .IX Subsection "network" Returns the network part of the prefix. .PP .Vb 2 \& [% USE IPAddr(\*(Aq10.1.1.1/24\*(Aq) %] \& [% IPAddr.network %] # 10.1.1.0 \& \& [% USE IPAddr(\*(Aq2001:db8:a:b:c:d:e:f/48\*(Aq) %] \& [% IPAddr.network %] # 2001:db8:a:: .Ve .SS "netmask" .IX Subsection "netmask" Returns the netmask part of the prefix. .PP .Vb 2 \& [% USE IPAddr(\*(Aq10.1.1.1/24\*(Aq) %] \& [% IPAddr.netmask %] # 255.255.255.0 .Ve .SS "wildcard" .IX Subsection "wildcard" Returns the netmask of the prefix in wildcard format (the netmask with all bits inverted). .PP .Vb 2 \& [% USE IPAddr(\*(Aq10.1.1.1/24\*(Aq) %] \& [% IPAddr.wildcard %] # 0.0.0.255 .Ve .SH "NOTES" .IX Header "NOTES" Please note the subtle, but important, difference between \f(CW\*(C`addr_cidr\*(C'\fR and \f(CW\*(C`cidr\*(C'\fR (see \*(L"cidr\*(R" for an explanation). .PP Not all methods are applicable in a IPv6 context. For example there are no notation of netmask or wildcard in IPv6, and the first and last returns values of no use. .PP When using IPv6 mapped IPv4 addresses, the \*(L"dot notation\*(R" is lost in the process. For example: .PP .Vb 1 \& [% USE IPAddr(\*(Aq::192.0.2.1\*(Aq) %] .Ve .PP then .PP .Vb 1 \& [% IPAddr.addr %] .Ve .PP will print \f(CW\*(C`::c000:201\*(C'\fR. .SH "SEE ALSO" .IX Header "SEE ALSO" Template, \&\*(L"\s-1PLUGINS\*(R"\s0 in Template::Manual::Config, NetAddr::IP .SH "AUTHOR" .IX Header "AUTHOR" Per Carlson .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" This software is copyright (c) 2014 by Per Carlson. .PP This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.