Debian Codegraph @

README

raw
1 NAME
2
3 Template::Plugin::IPAddr - Template::Toolkit plugin handling
4 IP-addresses
5
6 VERSION
7
8 version 0.03
9
10 SYNOPSIS
11
12 # Create IPAddr object via USE directive...
13 [% USE IPAddr %]
14 [% USE IPAddr(prefix) %]
15
16 # ...or via new
17 [% ip = IPAddr.new(prefix) %]
18
19 # Methods that return the different parts of the prefix
20 [% IPAddr.addr %]
21 [% IPAddr.addr_cidr %]
22 [% IPAddr.cidr %]
23 [% IPAddr.network %]
24 [% IPAddr.netmask %]
25 [% IPAddr.wildcard %]
26
27 # Methods for retrieving usable IP-adresses from a prefix
28 [% IPAddr.first %]
29 [% IPAddr.last %]
30
31 DESCRIPTION
32
33 This module implements an IPAddr class for handling IPv4 and
34 IPv6-address in an object-orientated way. The module is based on
35 NetAddr::IP and works on IPv4 as well as IPv6-addresses.
36
37 You can create a IPAddr object via the USE directive, adding any
38 initial prefix as an argument.
39
40 [% USE IPAddr %]
41 [% USE IPAddr(prefix) %]
42
43 Once you've got a IPAddr object, you can use it as a prototype to
44 create other IPAddr objects with the new() method.
45
46 [% USE IPAddr %]
47 [% ip = IPAddr.new(prefix) %]
48
49 After creating an IPaddr object, you can use the supplied methods for
50 retrieving properties of the prefix.
51
52 [% USE IPAddr('10.0.0.0/24') %]
53 [% IPAddr.netmask %] # 255.255.255.0
54 [% IPAddr.first %] # 10.0.0.1
55 [% IPAddr.last %] # 10.0.0.254
56
57 METHODS
58
59 new
60
61 Creates a new IPAddr object using an initial value passed as a
62 positional parameter. Any string which is accepted by NetAddr::IP->new
63 can be used as a parameter.
64
65 [% USE IPAddr %]
66 [% USE IPAddr(prefix) %]
67 [% ip = IPAddr.new(prefix) %]
68
69 Examples of (recommended) formats of initial parameters that can be
70 used:
71
72 # IPv4
73 n.n.n.n # Host address
74 n.n.n.n/m # CIDR notation
75 n.n.n.n/m.m.m.m # address + netmask
76
77 # IPv6
78 x:x:x:x:x:x:x:x # Host address
79 x:x:x:x:x:x:x:x/m # CIDR notation
80 ::n.n.n.n # IPv4-compatible IPv6 address
81
82 When used as [% USE IPAddr %] the prefix assigned internally is
83 0.0.0.0/0
84
85 addr
86
87 Returns the address part of the prefix as written in the initial value.
88
89 [% USE IPAddr('10.1.1.1/24') %]
90 [% IPAddr.addr %] # 10.1.1.1
91
92 [% USE IPAddr('2001:DB8::DEAD:BEEF') %]
93 [% IPAddr.addr %] # 2001:db8::dead:beef
94
95 addr_cidr
96
97 Returns the address in CIDR notation, i.e. as address/prefixlen.
98
99 [% USE IPAddr('10.1.1.1/255.255.255.0') %]
100 [% IPAddr.addr_cidr %] # 10.1.1.1/24
101
102 [% USE IPAddr('2001:db8:a:b:c:d:e:f/48') %]
103 [% IPAddr.addr_cidr %] # 2001:db8:a:b:c:d:e:f/48
104
105 cidr
106
107 Returns the prefix in CIDR notation, i.e. as network/prefixlen.
108
109 [% USE IPAddr('10.1.1.1/255.255.255.0') %]
110 [% IPAddr.cidr %] # 10.1.1.0/24
111
112 [% USE IPAddr('2001:db8:a:b:c:d:e:f/48') %]
113 [% IPAddr.cidr %] # 2001:db8:a::/48
114
115 Note that differs from the cidr method in NetAddr::IP (which returns
116 address/prefixlen). You can retrieve an address on that format by using
117 the "addr_cidr" method.
118
119 first
120
121 Returns the first usable IP-address within the prefix.
122
123 [% USE IPAddr('10.0.0.0/16') %]
124 [% IPAddr.first %] # 10.0.0.1
125
126 last
127
128 Returns the last usable IP-address within the prefix.
129
130 [% USE IPAddr('10.0.0.0/16') %]
131 [% IPAddr.last %] # 10.0.255.254
132
133 network
134
135 Returns the network part of the prefix.
136
137 [% USE IPAddr('10.1.1.1/24') %]
138 [% IPAddr.network %] # 10.1.1.0
139
140 [% USE IPAddr('2001:db8:a:b:c:d:e:f/48') %]
141 [% IPAddr.network %] # 2001:db8:a::
142
143 netmask
144
145 Returns the netmask part of the prefix.
146
147 [% USE IPAddr('10.1.1.1/24') %]
148 [% IPAddr.netmask %] # 255.255.255.0
149
150 wildcard
151
152 Returns the netmask of the prefix in wildcard format (the netmask with
153 all bits inverted).
154
155 [% USE IPAddr('10.1.1.1/24') %]
156 [% IPAddr.wildcard %] # 0.0.0.255
157
158 NOTES
159
160 Please note the subtle, but important, difference between addr_cidr and
161 cidr (see "cidr" for an explanation).
162
163 Not all methods are applicable in a IPv6 context. For example there are
164 no notation of netmask or wildcard in IPv6, and the first and last
165 returns values of no use.
166
167 When using IPv6 mapped IPv4 addresses, the "dot notation" is lost in
168 the process. For example:
169
170 [% USE IPAddr('::192.0.2.1') %]
171
172 then
173
174 [% IPAddr.addr %]
175
176 will print ::c000:201.
177
178 SEE ALSO
179
180 Template, "PLUGINS" in Template::Manual::Config, NetAddr::IP
181
182 AUTHOR
183
184 Per Carlson <[email protected]>
185
186 COPYRIGHT AND LICENSE
187
188 This software is copyright (c) 2014 by Per Carlson.
189
190 This is free software; you can redistribute it and/or modify it under
191 the same terms as the Perl 5 programming language system itself.
192