1NetAddr::IP::InetBase(3U)ser Contributed Perl DocumentatiNoentAddr::IP::InetBase(3)
2
3
4
6 NetAddr::IP::InetBase -- IPv4 and IPV6 utilities
7
9 use NetAddr::IP::Base qw(
10 :upper
11 inet_aton
12 inet_ntoa
13 ipv6_aton
14 ipv6_ntoa
15 ipv6_n2x
16 ipv6_n2d
17 inet_any2n
18 inet_n2dx
19 inet_n2ad
20 inet_pton
21 inet_ntop
22 packzeros
23 isIPv4
24 isNewIPv4
25 isAnyIPv4
26 AF_INET
27 AF_INET6
28 fake_AF_INET6
29 fillIPv4
30 );
31
32 use NetAddr::IP::Util qw(:all :inet :ipv4 :ipv6 :math)
33
34 :ipv4 => inet_aton, inet_ntoa, fillIPv4
35
36 :ipv6 => ipv6_aton, ipv6_ntoa,ipv6_n2x, ipv6_n2d,
37 inet_any2n, inet_n2dx, inet_n2ad
38 inet_pton, inet_ntop, packzeros
39
40 $dotquad = inet_ntoa($netaddr);
41 $netaddr = inet_aton($dotquad);
42 $ipv6naddr = ipv6_aton($ipv6_text);
43 $ipv6_text = ipv6_ntoa($ipv6naddr);
44 $hex_text = ipv6_n2x($ipv6naddr);
45 $dec_text = ipv6_n2d($ipv6naddr);
46 $ipv6naddr = inet_any2n($dotquad or $ipv6_text);
47 $dotquad or $hex_text = inet_n2dx($ipv6naddr);
48 $dotquad or $dec_text = inet_n2ad($ipv6naddr);
49 $netaddr = inet_pton($AF_family,$text_addr);
50 $text_addr = inet_ntop($AF_family,$netaddr);
51 $hex_text = packzeros($hex_text);
52 $rv = isIPv4($bits128);
53 $rv = isNewIPv4($bits128);
54 $rv = isAnyIPv4($bits128);
55 $constant = AF_INET();
56 $constant = AF_INET6();
57 $trueif = fake_AF_INET6();
58 $ip_filled = fillIPv4($shortIP);
59
60 NetAddr::IP::InetBase::lower();
61 NetAddr::IP::InetBase::upper();
62
64 Un-tar the distribution in an appropriate directory and type:
65
66 perl Makefile.PL
67 make
68 make test
69 make install
70
72 NetAddr::IP::InetBase provides a suite network of conversion functions
73 written in pure Perl for converting both IPv4 and IPv6 addresses to and
74 from network address format and text format.
75
76 The IPv6 functions support all rfc1884 formats.
77
78 i.e. x:x:x:x:x:x:x:x:x
79 x:x:x:x:x:x:x:d.d.d.d
80 ::x:x:x
81 ::x:d.d.d.d
82 and so on...
83
84 • $dotquad = inet_ntoa($netaddr);
85
86 Convert a packed IPv4 network address to a dot-quad IP address.
87
88 input: packed network address
89 returns: IP address i.e. 10.4.12.123
90
91 • $netaddr = inet_aton($dotquad);
92
93 Convert a dot-quad IP address into an IPv4 packed network address.
94
95 input: IP address i.e. 192.5.16.32
96 returns: packed network address
97
98 • $ipv6addr = ipv6_aton($ipv6_text);
99
100 Takes an IPv6 address of the form described in rfc1884 and returns
101 a 128 bit binary RDATA string.
102
103 input: ipv6 text
104 returns: 128 bit RDATA string
105
106 • $ipv6text = ipv6_ntoa($ipv6naddr);
107
108 Convert a 128 bit binary IPv6 address to compressed rfc 1884 text
109 representation.
110
111 input: 128 bit RDATA string
112 returns: ipv6 text
113
114 • $hex_text = ipv6_n2x($ipv6addr);
115
116 Takes an IPv6 RDATA string and returns an 8 segment IPv6 hex
117 address
118
119 input: 128 bit RDATA string
120 returns: x:x:x:x:x:x:x:x
121
122 Note: this function does NOT compress adjacent
123 strings of 0:0:0:0 into the :: format
124
125 • $dec_text = ipv6_n2d($ipv6addr);
126
127 Takes an IPv6 RDATA string and returns a mixed hex - decimal IPv6
128 address with the 6 uppermost chunks in hex and the lower 32 bits in
129 dot-quad representation.
130
131 input: 128 bit RDATA string
132 returns: x:x:x:x:x:x:d.d.d.d
133
134 Note: this function does NOT compress adjacent
135 strings of 0:0:0:0 into the :: format
136
137 • $ipv6naddr = inet_any2n($dotquad or $ipv6_text);
138
139 This function converts a text IPv4 or IPv6 address in text format
140 in any standard notation into a 128 bit IPv6 string address. It
141 prefixes any dot-quad address (if found) with '::' and passes it to
142 ipv6_aton.
143
144 input: dot-quad or rfc1844 address
145 returns: 128 bit IPv6 string
146
147 • $dotquad or $hex_text = inet_n2dx($ipv6naddr);
148
149 This function does the right thing and returns the text for either
150 a dot-quad IPv4 or a hex notation IPv6 address.
151
152 input: 128 bit IPv6 string
153 returns: ddd.ddd.ddd.ddd
154 or x:x:x:x:x:x:x:x
155
156 Note: this function does NOT compress adjacent
157 strings of 0:0:0:0 into the :: format
158
159 • $dotquad or $dec_text = inet_n2ad($ipv6naddr);
160
161 This function does the right thing and returns the text for either
162 a dot-quad IPv4 or a hex::decimal notation IPv6 address.
163
164 input: 128 bit IPv6 string
165 returns: ddd.ddd.ddd.ddd
166 or x:x:x:x:x:x:ddd.ddd.ddd.dd
167
168 Note: this function does NOT compress adjacent
169 strings of 0:0:0:0 into the :: format
170
171 • $netaddr = inet_pton($AF_family,$text_addr);
172
173 This function takes an IP address in IPv4 or IPv6 text format and
174 converts it into binary format. The type of IP address conversion
175 is controlled by the FAMILY argument.
176
177 NOTE: inet_pton, inet_ntop and AF_INET6 come from the Socket6
178 library if it is present on this host.
179
180 • $text_addr = inet_ntop($AF_family,$netaddr);
181
182 This function takes and IP address in binary format and converts it
183 into text format. The type of IP address conversion is controlled
184 by the FAMILY argument.
185
186 NOTE: inet_ntop ALWAYS returns lowercase characters.
187
188 NOTE: inet_pton, inet_ntop and AF_INET6 come from the Socket6
189 library if it is present on this host.
190
191 • $hex_text = packzeros($hex_text);
192
193 This function optimizes and rfc 1884 IPv6 hex address to reduce the
194 number of long strings of zero bits as specified in rfc 1884, 2.2
195 (2) by substituting :: for the first occurence of the longest
196 string of zeros in the address.
197
198 • $ipv6naddr = ipv4to6($netaddr);
199
200 Convert an ipv4 network address into an ipv6 network address.
201
202 input: 32 bit network address
203 returns: 128 bit network address
204
205 • $rv = isIPv4($bits128);
206
207 This function returns true if there are no on bits present in the
208 IPv6 portion of the 128 bit string and false otherwise.
209
210 i.e. the address must be of the form - ::d.d.d.d
211
212 Note: this is an old and deprecated ipV4 compatible ipV6 address
213
214 • $rv = isNewIPv4($bits128);
215
216 This function return true if the IPv6 128 bit string is of the form
217
218 ::ffff:d.d.d.d
219
220 • $rv = isAnyIPv4($bits128);
221
222 This function return true if the IPv6 bit string is of the form
223
224 ::d.d.d.d or ::ffff:d.d.d.d
225
226 • NetAddr::IP::InetBase::lower();
227
228 Return IPv6 strings in lowercase. This is the default.
229
230 • NetAddr::IP::InetBase::upper();
231
232 Return IPv6 strings in uppercase.
233
234 The default may be set to uppercase when the module is loaded by
235 invoking the TAG :upper. i.e.
236
237 use NetAddr::IP::InetBase qw( :upper );
238
239 • $constant = AF_INET;
240
241 This function returns the system value for AF_INET.
242
243 • $constant = AF_INET6;
244
245 AF_INET6 is sometimes present in the Socket library and always
246 present in the Socket6 library. When the Socket library does not
247 contain AF_INET6 and when Socket6 is not present, a place holder
248 value is "guessed" based on the underlying host operating system.
249 See fake_AF_INET6 below.
250
251 NOTE: inet_pton, inet_ntop and AF_INET6 come from the Socket6
252 library if it is present on this host.
253
254 • $trueif = fake_AF_INET6;
255
256 This function return FALSE if AF_INET6 is provided by Socket or
257 Socket6. Otherwise, it returns the best guess value based on name
258 of the host operating system.
259
260 • $ip_filled = fillIPv4($shortIP);
261
262 This function converts IPv4 addresses of the form 127.1 to the long
263 form 127.0.0.1
264
265 If the function is passed an argument that does not match the form
266 of an IP address, the original argument is returned. i.e. pass it a
267 hostname or a short IP and it will return a hostname or a filled
268 IP.
269
271 :upper
272 inet_aton
273 inet_ntoa
274 ipv6_aton
275 ipv6_ntoa
276 ipv6_n2x
277 ipv6_n2d
278 inet_any2n
279 inet_n2dx
280 inet_n2ad
281 inet_pton
282 inet_ntop
283 packzeros
284 isIPv4
285 isNewIPv4
286 isAnyIPv4
287 AF_INET
288 AF_INET6
289 fake_AF_INET6
290 fillIPv4
291
293 :all
294 :ipv4
295 :ipv6
296 :upper
297
299 Michael Robinton <michael@bizsystems.com>
300
302 Copyright 2003 - 2012, Michael Robinton <michael@bizsystems.com>
303
304 All rights reserved.
305
306 This program is free software; you can redistribute it and/or modify it
307 under the terms of either:
308
309 a) the GNU General Public License as published by the Free
310 Software Foundation; either version 2, or (at your option) any
311 later version, or
312
313 b) the "Artistic License" which comes with this distribution.
314
315 This program is distributed in the hope that it will be useful, but
316 WITHOUT ANY WARRANTY; without even the implied warranty of
317 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See either the
318 GNU General Public License or the Artistic License for more details.
319
320 You should have received a copy of the Artistic License with this
321 distribution, in the file named "Artistic". If not, I'll be glad to
322 provide one.
323
324 You should also have received a copy of the GNU General Public License
325 along with this program in the file named "Copying". If not, write to
326 the
327
328 Free Software Foundation, Inc.,
329 51 Franklin Street, Fifth Floor
330 Boston, MA 02110-1301 USA
331
332 or visit their web page on the internet at:
333
334 http://www.gnu.org/copyleft/gpl.html.
335
337 Michael Robinton <michael@bizsystems.com>
338
340 NetAddr::IP(3), NetAddr::IP::Lite(3), NetAddr::IP::Util(3)
341
342
343
344perl v5.34.0 2022-01-21 NetAddr::IP::InetBase(3)