1NetAddr::IP::UtilPP(3)User Contributed Perl DocumentationNetAddr::IP::UtilPP(3)
2
3
4

NAME

6       NetAddr::IP::UtilPP -- pure Perl functions for NetAddr::IP::Util
7

SYNOPSIS

9         use NetAddr::IP::UtilPP qw(
10               hasbits
11               shiftleft
12               addconst
13               add128
14               sub128
15               notcontiguous
16               ipv4to6
17               mask4to6
18               ipanyto6
19               maskanyto6
20               ipv6to4
21               bin2bcd
22               bcd2bin
23         );
24
25         use NetAddr::IP::UtilPP qw(:all)
26
27         $rv = hasbits($bits128);
28         $bitsX2 = shiftleft($bits128,$n);
29         $carry = addconst($ipv6naddr,$signed_32con);
30         ($carry,$ipv6naddr)=addconst($ipv6naddr,$signed_32con);
31         $carry = add128($ipv6naddr1,$ipv6naddr2);
32         ($carry,$ipv6naddr)=add128($ipv6naddr1,$ipv6naddr2);
33         $carry = sub128($ipv6naddr1,$ipv6naddr2);
34         ($spurious,$cidr) = notcontiguous($mask128);
35         ($carry,$ipv6naddr)=sub128($ipv6naddr1,$ipv6naddr2);
36         $ipv6naddr = ipv4to6($netaddr);
37         $ipv6naddr = mask4to6($netaddr);
38         $ipv6naddr = ipanyto6($netaddr);
39         $ipv6naddr = maskanyto6($netaddr);
40         $netaddr = ipv6to4($pv6naddr);
41         $bcdtext = bin2bcd($bits128);
42         $bits128 = bcd2bin($bcdtxt);
43

DESCRIPTION

45       NetAddr::IP::UtilPP provides pure Perl functions for NetAddr::IP::Util
46
47       ·   $rv = hasbits($bits128);
48
49           This function returns true if there are one's present in the 128
50           bit string and false if all the bits are zero.
51
52             i.e.  if (hasbits($bits128)) {
53                     &do_something;
54                   }
55
56             or    if (hasbits($bits128 & $mask128) {
57                     &do_something;
58                   }
59
60           This allows the implementation of logical functions of the form of:
61
62                   if ($bits128 & $mask128) {
63                       ...
64
65             input:        128 bit IPv6 string
66             returns:      true if any bits are present
67
68       ·   $bitsXn = shiftleft($bits128,$n);
69
70             input:        128 bit string variable,
71                           number of shifts [optional]
72             returns:      bits X n shifts
73
74             NOTE: input bits are returned
75                   if $n is not specified
76
77       ·   addconst($ipv6naddr,$signed_32con);
78
79           Add a signed constant to a 128 bit string variable.
80
81             input:        128 bit IPv6 string,
82                           signed 32 bit integer
83             returns:  scalar      carry
84                       array       (carry, result)
85
86       ·   add128($ipv6naddr1,$ipv6naddr2);
87
88           Add two 128 bit string variables.
89
90             input:        128 bit string var1,
91                           128 bit string var2
92             returns:  scalar      carry
93                       array       (carry, result)
94
95       ·   sub128($ipv6naddr1,$ipv6naddr2);
96
97           Subtract two 128 bit string variables.
98
99             input:        128 bit string var1,
100                           128 bit string var2
101             returns:  scalar      carry
102                       array       (carry, result)
103
104           Note: The carry from this operation is the result of adding the
105           one's complement of ARG2 +1 to the ARG1. It is logically NOT
106           borrow.
107
108                   i.e.    if ARG1 >= ARG2 then carry = 1
109                   or      if ARG1  < ARG2 then carry = 0
110
111       ·   ($spurious,$cidr) = notcontiguous($mask128);
112
113           This function counts the bit positions remaining in the mask when
114           the rightmost '0's are removed.
115
116                   input:  128 bit netmask
117                   returns true if there are spurious
118                               zero bits remaining in the
119                               mask, false if the mask is
120                               contiguous one's,
121                           128 bit cidr
122
123       ·   $ipv6naddr = ipv4to6($netaddr);
124
125           Convert an ipv4 network address into an ipv6 network address.
126
127             input:        32 bit network address
128             returns:      128 bit network address
129
130       ·   $ipv6naddr = mask4to6($netaddr);
131
132           Convert an ipv4 netowrk address into an ipv6 network mask.
133
134             input:        32 bit network/mask address
135             returns:      128 bit network/mask address
136
137           NOTE: returns the high 96 bits as one's
138
139       ·   $ipv6naddr = ipanyto6($netaddr);
140
141           Similar to ipv4to6 except that this function takes either an IPv4
142           or IPv6 input and always returns a 128 bit IPv6 network address.
143
144             input:        32 or 128 bit network address
145             returns:      128 bit network address
146
147       ·   $ipv6naddr = maskanyto6($netaddr);
148
149           Similar to mask4to6 except that this function takes either an IPv4
150           or IPv6 netmask and always returns a 128 bit IPv6 netmask.
151
152             input:        32 or 128 bit network mask
153             returns:      128 bit network mask
154
155       ·   $netaddr = ipv6to4($pv6naddr);
156
157           Truncate the upper 96 bits of a 128 bit address and return the
158           lower 32 bits. Returns an IPv4 address as returned by inet_aton.
159
160             input:        128 bit network address
161             returns:      32 bit inet_aton network address
162
163       ·   $bcdtext = bin2bcd($bits128);
164
165           Convert a 128 bit binary string into binary coded decimal text
166           digits.
167
168             input:        128 bit string variable
169             returns:      string of bcd text digits
170
171       ·   $bits128 = bcd2bin($bcdtxt);
172
173           Convert a bcd text string to 128 bit string variable
174
175             input:        string of bcd text digits
176             returns:      128 bit string variable
177

EXPORT_OK

179               hasbits
180               shiftleft
181               addconst
182               add128
183               sub128
184               notcontiguous
185               ipv4to6
186               mask4to6
187               ipanyto6
188               maskanyto6
189               ipv6to4
190               bin2bcd
191               bcd2bin
192               comp128
193               bin2bcdn
194               bcdn2txt
195               bcdn2bin
196               simple_pack
197               threads
198

AUTHOR

200       Michael Robinton <michael@bizsystems.com>
201
203       Copyright 2003 - 2012, Michael Robinton <michael@bizsystems.com>
204
205       All rights reserved.
206
207       This program is free software; you can redistribute it and/or modify it
208       under the terms of either:
209
210         a) the GNU General Public License as published by the Free
211         Software Foundation; either version 2, or (at your option) any
212         later version, or
213
214         b) the "Artistic License" which comes with this distribution.
215
216       This program is distributed in the hope that it will be useful, but
217       WITHOUT ANY WARRANTY; without even the implied warranty of
218       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See either the
219       GNU General Public License or the Artistic License for more details.
220
221       You should have received a copy of the Artistic License with this
222       distribution, in the file named "Artistic".  If not, I'll be glad to
223       provide one.
224
225       You should also have received a copy of the GNU General Public License
226       along with this program in the file named "Copying". If not, write to
227       the
228
229               Free Software Foundation, Inc.,
230               51 Franklin Street, Fifth Floor
231               Boston, MA 02110-1301 USA
232
233       or visit their web page on the internet at:
234
235               http://www.gnu.org/copyleft/gpl.html.
236

AUTHOR

238       Michael Robinton <michael@bizsystems.com>
239
240
241
242perl v5.16.3                      2012-08-10            NetAddr::IP::UtilPP(3)
Impressum