1NetAddr::IP::UtilPP(3)User Contributed Perl DocumentationNetAddr::IP::UtilPP(3)
2
3
4
6 NetAddr::IP::UtilPP -- pure Perl functions for NetAddr::IP::Util
7
9 use NetAddr::IP::UtilPP qw(
10 hasbits
11 isIPv4
12 shiftleft
13 addconst
14 add128
15 sub128
16 notcontiguous
17 ipv4to6
18 mask4to6
19 ipanyto6
20 maskanyto6
21 ipv6to4
22 bin2bcd
23 bcd2bin
24 );
25
26 use NetAddr::IP::UtilPP qw(:all)
27
28 $rv = hasbits($bits128);
29 $rv = isIPv4($bits128);
30 $bitsX2 = shiftleft($bits128,$n);
31 $carry = addconst($ipv6naddr,$signed_32con);
32 ($carry,$ipv6naddr)=addconst($ipv6naddr,$signed_32con);
33 $carry = add128($ipv6naddr1,$ipv6naddr2);
34 ($carry,$ipv6naddr)=add128($ipv6naddr1,$ipv6naddr2);
35 $carry = sub128($ipv6naddr1,$ipv6naddr2);
36 ($spurious,$cidr) = notcontiguous($mask128);
37 ($carry,$ipv6naddr)=sub128($ipv6naddr1,$ipv6naddr2);
38 $ipv6naddr = ipv4to6($netaddr);
39 $ipv6naddr = mask4to6($netaddr);
40 $ipv6naddr = ipanyto6($netaddr);
41 $ipv6naddr = maskanyto6($netaddr);
42 $netaddr = ipv6to4($pv6naddr);
43 $bcdtext = bin2bcd($bits128);
44 $bits128 = bcd2bin($bcdtxt);
45
47 NetAddr::IP::UtilPP provides pure Perl functions for NetAddr::IP::Util
48
49 · $rv = hasbits($bits128);
50
51 This function returns true if there are one's present in the 128
52 bit string and false if all the bits are zero.
53
54 i.e. if (hasbits($bits128)) {
55 &do_something;
56 }
57
58 or if (hasbits($bits128 & $mask128) {
59 &do_something;
60 }
61
62 This allows the implementation of logical functions of the form of:
63
64 if ($bits128 & $mask128) {
65 ...
66
67 input: 128 bit IPv6 string
68 returns: true if any bits are present
69
70 · $rv = isIPv4($bits128);
71
72 This function returns true if there are no on bits present in the
73 IPv6 portion of the 128 bit string and false otherwise.
74
75 · $bitsXn = shiftleft($bits128,$n);
76
77 input: 128 bit string variable,
78 number of shifts [optional]
79 returns: bits X n shifts
80
81 NOTE: input bits are returned
82 if $n is not specified
83
84 · addconst($ipv6naddr,$signed_32con);
85
86 Add a signed constant to a 128 bit string variable.
87
88 input: 128 bit IPv6 string,
89 signed 32 bit integer
90 returns: scalar carry
91 array (carry, result)
92
93 · add128($ipv6naddr1,$ipv6naddr2);
94
95 Add two 128 bit string variables.
96
97 input: 128 bit string var1,
98 128 bit string var2
99 returns: scalar carry
100 array (carry, result)
101
102 · sub128($ipv6naddr1,$ipv6naddr2);
103
104 Subtract two 128 bit string variables.
105
106 input: 128 bit string var1,
107 128 bit string var2
108 returns: scalar carry
109 array (carry, result)
110
111 Note: The carry from this operation is the result of adding the
112 one's complement of ARG2 +1 to the ARG1. It is logically NOT
113 borrow.
114
115 i.e. if ARG1 >= ARG2 then carry = 1
116 or if ARG1 < ARG2 then carry = 0
117
118 · ($spurious,$cidr) = notcontiguous($mask128);
119
120 This function counts the bit positions remaining in the mask when
121 the rightmost '0's are removed.
122
123 input: 128 bit netmask
124 returns true if there are spurious
125 zero bits remaining in the
126 mask, false if the mask is
127 contiguous one's,
128 128 bit cidr
129
130 · $ipv6naddr = ipv4to6($netaddr);
131
132 Convert an ipv4 network address into an ipv6 network address.
133
134 input: 32 bit network address
135 returns: 128 bit network address
136
137 · $ipv6naddr = mask4to6($netaddr);
138
139 Convert an ipv4 netowrk address into an ipv6 network mask.
140
141 input: 32 bit network/mask address
142 returns: 128 bit network/mask address
143
144 NOTE: returns the high 96 bits as one's
145
146 · $ipv6naddr = ipanyto6($netaddr);
147
148 Similar to ipv4to6 except that this function takes either an IPv4
149 or IPv6 input and always returns a 128 bit IPv6 network address.
150
151 input: 32 or 128 bit network address
152 returns: 128 bit network address
153
154 · $ipv6naddr = maskanyto6($netaddr);
155
156 Similar to mask4to6 except that this function takes either an IPv4
157 or IPv6 netmask and always returns a 128 bit IPv6 netmask.
158
159 input: 32 or 128 bit network mask
160 returns: 128 bit network mask
161
162 · $netaddr = ipv6to4($pv6naddr);
163
164 Truncate the upper 96 bits of a 128 bit address and return the
165 lower 32 bits. Returns an IPv4 address as returned by inet_aton.
166
167 input: 128 bit network address
168 returns: 32 bit inet_aton network address
169
170 · $bcdtext = bin2bcd($bits128);
171
172 Convert a 128 bit binary string into binary coded decimal text
173 digits.
174
175 input: 128 bit string variable
176 returns: string of bcd text digits
177
178 · $bits128 = bcd2bin($bcdtxt);
179
180 Convert a bcd text string to 128 bit string variable
181
182 input: string of bcd text digits
183 returns: 128 bit string variable
184
186 hasbits
187 isIPv4
188 shiftleft
189 addconst
190 add128
191 sub128
192 notcontiguous
193 ipv4to6
194 mask4to6
195 ipanyto6
196 maskanyto6
197 ipv6to4
198 bin2bcd
199 bcd2bin
200 comp128
201 bin2bcdn
202 bcdn2txt
203 bcdn2bin
204 simple_pack
205 threads
206
208 Michael Robinton <michael@bizsystems.com>
209
211 Copyright 2006 - 2008, Michael Robinton <michael@bizsystems.com>
212
213 This program is free software; you can redistribute it and/or modify it
214 under the terms of the GNU General Public License (except as noted
215 otherwise in individuals sub modules) published by the Free Software
216 Foundation; either version 2 of the License, or (at your option) any
217 later version.
218
219 This program is distributed in the hope that it will be useful, but
220 WITHOUT ANY WARRANTY; without even the implied warranty of
221 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
222 General Public License for more details.
223
224 You should have received a copy of the GNU General Public License along
225 with this program; if not, write to the Free Software Foundation, Inc.,
226 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
227
229 Michael Robinton <michael@bizsystems.com>
230
231
232
233perl v5.10.1 2008-12-09 NetAddr::IP::UtilPP(3)