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               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

DESCRIPTION

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

EXPORT_OK

172               hasbits
173               isIPv4
174               shiftleft
175               addconst
176               add128
177               sub128
178               notcontiguous
179               ipv4to6
180               mask4to6
181               ipanyto6
182               maskanyto6
183               ipv6to4
184               bin2bcd
185               bcd2bin
186               comp128
187               bin2bcdn
188               bcdn2txt
189               bcdn2bin
190               simple_pack
191

AUTHOR

193       Michael Robinton <michael@bizsystems.com>
194
196       Copyright 2006, Michael Robinton <michael@bizsystems.com>
197
198       This program is free software; you can redistribute it and/or modify it
199       under the terms of the GNU General Public License (except as noted oth‐
200       erwise in individuals sub modules)  published by the Free Software
201       Foundation; either version 2 of the License, or (at your option) any
202       later version.
203
204       This program is distributed in the hope that it will be useful, but
205       WITHOUT ANY WARRANTY; without even the implied warranty of MER‐
206       CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
207       Public License for more details.
208
209       You should have received a copy of the GNU General Public License along
210       with this program; if not, write to the Free Software Foundation, Inc.,
211       59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
212

AUTHOR

214       Michael Robinton <michael@bizsystems.com>
215
216
217
218perl v5.8.8                       2006-08-14            NetAddr::IP::UtilPP(3)
Impressum