NAME
NetAddr::IP::Lite - Manages IPv4 and IPv6 addresses and subnets (lightweight)
VERSION
version 4.080_04
SYNOPSIS
use NetAddr::IP::Lite qw(
Zeros
Ones
V4mask
V4net
);
use NetAddr::IP::Util qw(inet_aton ipv6_n2x);
my $ip = NetAddr::IP::Lite->new('192.0.2.1');
# from a packed IPv4 address
my $a = NetAddr::IP::Lite->new_from_aton(inet_aton('192.0.2.1')); # 192.0.2.1/32
# from an octal filtered one
my $b = NetAddr::IP::Lite->new_no('198.051.100.001'); # 198.51.100.1/32
print 'The address is ', $ip->addr, ' with mask ', $ip->mask, "\n" ;
# The address is 192.0.2.1 with mask 255.255.255.255
if ($ip->within(NetAddr::IP::Lite->new('192.0.2.0', '255.255.255.224'))) {
print "Is within 192.0.2.0/27\n"; # Is within 192.0.2.0/27
}
print "You can also say $ip...\n"; # You can also say 192.0.2.1/32...
# The following four functions return 128-bit vectors; this shows
# their string form via ipv6_n2x():
print ipv6_n2x(Zeros()), "\n"; # 0:0:0:0:0:0:0:0
print ipv6_n2x(Ones()), "\n"; # FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF
print ipv6_n2x(V4mask()), "\n"; # FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:0:0
print ipv6_n2x(V4net()), "\n"; # 0:0:0:0:0:0:FFFF:FFFF
DESCRIPTION
The build steps, including the pure Perl mode, are in README.md. This module does not choose how it was built; mode() from NetAddr::IP::Util reports which implementation is active.
This module provides an object-oriented abstraction on top of IP addresses or IP subnets, that allows for easy manipulations. Most of the operations of NetAddr::IP are supported. It is compatible with Math::BigInt, and requires perl 5.14 or later.
This module is the base class of NetAddr::IP. It has the constructors, the accessors, the containment tests, the host counts and every operator except @{}. The rest is in NetAddr::IP only: the text forms short, canon, full, full6, full6m, prefix, nprefix and wildcard, the splitting and set operations, hostenum, hostenumref, re, re6 and netlimit.
Once NetAddr::IP is loaded, a NetAddr::IP::Lite object can call those methods too, because the AUTOLOAD in this module passes the call on to NetAddr::IP. Before that the call dies:
use NetAddr::IP::Lite;
my $ip = NetAddr::IP::Lite->new('192.0.2.0/30');
print eval { $ip->hostenum; 1 } ? "works\n" : "dies\n"; # dies
require NetAddr::IP;
print join(' ', $ip->hostenum), "\n"; # 192.0.2.1/32 192.0.2.2/32
* By default NetAddr::IP functions and methods return string IPv6 addresses in uppercase. To change that to lowercase:
NOTE: the AUGUST 2010 RFC5952 states:
4.3. Lowercase
The characters "a", "b", "c", "d", "e", and "f" in an IPv6
address MUST be represented in lowercase.
It is recommended that all NEW applications using NetAddr::IP::Lite be invoked as shown on the next line.
use NetAddr::IP::Lite qw(:lower);
* To ensure the current IPv6 string case behavior even if the default changes:
use NetAddr::IP::Lite qw(:upper);
The internal representation of all IP objects is in 128 bit IPv6 notation. IPv4 and IPv6 objects may be freely mixed.
The supported operations are described below:
Overloaded Operators
- Assignment (
=) -
Has been optimized to copy one NetAddr::IP::Lite object to another very quickly.
->copy()-
The assignment (
=) operation is only put in to operation when the copied object is further mutated by another overloaded operation. See overload SPECIAL SYMBOLS FOR "use overload" for details.->copy()actually creates a new object when called. - Stringification
-
An object can be used just as a string. For instance, the following code
my $ip = NetAddr::IP::Lite->new('192.0.2.123'); print "$ip\n";Will print the string 192.0.2.123/32.
my $ip = NetAddr::IP::Lite->new6('192.0.2.123'); print "$ip\n";Will print the string 0:0:0:0:0:0:C000:27B/128
- Equality
-
You can test for equality with either
eq,ne,==or!=.eq,neallows the comparison with arbitrary strings as well as NetAddr::IP::Lite objects. The following example:if (NetAddr::IP::Lite->new('198.51.100.1','255.255.255.224') eq '198.51.100.1/27') { print "Yes\n"; }Will print out "Yes".
Comparison with
==and!=requires both operands to be NetAddr::IP::Lite objects. - Comparison via >, <, >=, <=, <=> and
cmp -
Internally, all network objects are represented in 128 bit format, and the comparison runs on that numeric form. The order is deterministic: the address portion first, then, when the addresses are equal, the numeric value of the masks. Since a longer mask is the larger number, this leads to the counterintuitive result that
/24 > /16The same order applies to
sort:my @nets = map { NetAddr::IP::Lite->new($_) } qw(192.0.2.1/32 192.0.2.1/8 192.0.2.1/24 192.0.2.1/16); print join(', ', sort @nets), "\n"; # 192.0.2.1/8, 192.0.2.1/16, 192.0.2.1/24, 192.0.2.1/32So the ordering is predictable, but it is not the ordering most people mean by "bigger". To rank netblocks by size, compare the mask lengths directly:
$ip1->masklen <=> $ip2->masklen - Addition of a constant (
+) -
Add a signed integer constant to the address part of a NetAddr object. This operation changes the address part to point so many hosts above the current objects start address. For instance, this code:
print NetAddr::IP::Lite->new('203.0.113.1/24') + 5;will output 203.0.113.6/24. The address wraps around at the broadcast back to the network address, so this code:
print NetAddr::IP::Lite->new('203.0.113.1/24') + 255;outputs 203.0.113.0/24.
Returns a copy of the object when the constant is missing or zero. The constant must be an integer with a magnitude below 2**64; anything else croaks, including a string that is not a number, such as '0x10'. Values above 2**53 must be passed as integers (IV or UV), since a floating point value that large has no unit precision and is rejected.
- Subtraction of a constant (
-) -
The complement of the addition of a constant.
The object must be the left operand. Subtracting an object from a constant (
10 - $ip) has no meaning and croaks. - Difference (
-) -
Returns the difference between the address parts of two NetAddr::IP::Lite objects address parts as a 32 bit signed number.
Returns undef if the difference is out of range.
- Negation and absolute value (
-andabs) -
Both croak. An address has no meaningful negation, and
abswould be the identity at best:-$ip; # cannot negate a NetAddr::IP::Lite object abs $ip; # cannot take the absolute value of a NetAddr::IP::Lite objectTo move to another address, add or subtract a constant with the overloaded
+and-, or usenth(). - Auto-increment
-
Auto-incrementing a NetAddr::IP::Lite object causes the address part to be adjusted to the next host address within the subnet. It will wrap at the broadcast address and start again from the network address.
- Auto-decrement
-
Auto-decrementing a NetAddr::IP::Lite object performs exactly the opposite of auto-incrementing it, as you would expect.
Constructors
->new([$addr, [ $mask|IPv6 ]])->new6([$addr, [ $mask]])->new6FFFF([$addr, [ $mask]])->new_no([$addr, [ $mask]])->new_from_aton($netaddr)->new_cis("$addr $mask")->new_cis6("$addr $mask")-
newandnew6create a new address with the supplied address in$addrand an optional netmask$mask, which can be omitted to get a /32 or /128 netmask for IPv4 / IPv6 addresses respectively.new6FFFFis the third constructor, and is what makes an IPv4-mapped address, RFC 4291 s2.5.5.2:NetAddr::IP::Lite->new6FFFF('192.0.2.1'); # 0:0:0:0:0:FFFF:C000:201/128new_nois exclusively for IPv4 addresses and filters improperly formatted dot quad strings for leading 0's that would normally be interpreted as octal format by NetAddr per the specifications for inet_aton.new_from_aton takes a packed IPv4 address and assumes a /32 mask. This function replaces the :aton functionality, which reads a packed string as text first and is fundamentally broken. See "DEPRECATED".
new_cis and new_cis6 accept the common Cisco address notation for address/mask pairs with a space as a separator instead of a slash (/). Both are deprecated in favour of new and new6, which do the same. See "DEPRECATED".
->new6and->new_cis6mark the address as being in ipV6 address space even if the format would suggest otherwise.print NetAddr::IP::Lite->new6('192.0.2.1'), "\n"; # 0:0:0:0:0:0:C000:201/128Addresses submitted to
->newin ipV6 notation will remain in that notation permanently, whereas the same address in dotted quad notation prints as IPv4:print NetAddr::IP::Lite->new('::192.0.2.1'), "\n"; # 0:0:0:0:0:0:C000:201/128 print NetAddr::IP::Lite->new('192.0.2.1'), "\n"; # 192.0.2.1/32The
addr()value is what stringifies as the first part.$addrcan be almost anything that can be resolved to an IP address. It can optionally contain the mask in CIDR notation. If the optional module Socket6 is installed, ipV6 host names are resolved as well as ipV4 ones; without it, only the ipV4 path runs.prefix notation is understood, with the limitation that the range specified by the prefix must match with a valid subnet.
Addresses in the packed format returned by
inet_atonorgethostbynameare understood only under the deprecated:atontag, and no mask can be specified for them. Even then a packed string is read as text first and looked up as a host name second, so one whose bytes also spell text comes back as a different address or as undef; see:atonunder "DEPRECATED". Usenew_from_atonfor a packed IPv4 address.$addrcan be any of the following and possibly more...n.n n.n/mm n.n mm n.n.n n.n.n/mm n.n.n mm n.n.n.n n.n.n.n/mm 32 bit cidr notation n.n.n.n mm n.n.n.n/m.m.m.m n.n.n.n m.m.m.m default, any, broadcast, loopback (keywords, see below) host, as a mask keyword x.x.x.x/host x:x:x/host 0xABCDEF, 0b111111000101011110, (a bcd number) a netaddr as returned by 'inet_aton', but only with the deprecated :aton tag, and only when its bytes do not also read as one of these forms or as a host name; without the tag a packed string returns undefAny RFC 4291 s2.2 notation
::n.n.n.n ::n.n.n.n/mmm 128 bit cidr notation ::n.n.n.n/::m.m.m.m ::x:x ::x:x/mmm x:x:x:x:x:x:x:x x:x:x:x:x:x:x:x/mmm x:x:x:x:x:x:x:x/m:m:m:m:m:m:m:m with a mask default, any, loopback, unspecified (keywords, see below) ::x:x/host 0xABCDEF, 0b111111000101011110 within the limits of perl's number resolution 123456789012 a 'big' bcd number (bigger than perl likes) and Math::BigIntA Fully Qualified Domain Name which returns an ipV4 address or an ipV6 address, embodied in that order. This previously undocumented feature may be disabled with:
use NetAddr::IP::Lite qw(:nofqdn);Called with no arguments, 'default' is assumed. An explicit undef argument returns undef, and an empty string returns undef.
Accepted forms in full
The list above is abbreviated. These are the forms worth knowing about, all verified on both builds.
Range and prefix notation, where the prefix has to name a valid subnet:
NetAddr::IP::Lite->new('192.0.2.0-192.0.2.255'); # 192.0.2.0/24
NetAddr::IP::Lite->new('192.0.2.4-7'); # 192.0.2.4/30
NetAddr::IP::Lite->new('192.0.2.'); # 192.0.2.0/24
NetAddr::IP::Lite->new('192.0.'); # 192.0.0.0/16
NetAddr::IP::Lite->new('10.'); # 10.0.0.0/8
NetAddr::IP::Lite->new('192.0-3.'); # 192.0.0.0/14
Short dotted forms change meaning when a mask argument is given, which is the one trap here worth writing out. On its own the short form is a host address; with a mask it is the network of that size:
NetAddr::IP::Lite->new('10.1'); # 10.0.0.1/32
NetAddr::IP::Lite->new('10.1', 8); # 10.1.0.0/8
NetAddr::IP::Lite->new('10.1.2'); # 10.1.0.2/32
NetAddr::IP::Lite->new('10.1.2', 24); # 10.1.2.0/24
RFC 3986 brackets around an IPv6 literal, which is how a URI carries one:
NetAddr::IP::Lite->new('[2001:db8::1]/64'); # 2001:DB8:0:0:0:0:0:1/64
NetAddr::IP::Lite->new('[2001:db8::1]'); # 2001:DB8:0:0:0:0:0:1/128
Brackets around an IPv4 literal are not accepted and return undef.
Keywords. The set is not the same for both constructors, which is worth knowing before reaching for one:
NetAddr::IP::Lite->new('broadcast'); # 255.255.255.255/32
NetAddr::IP::Lite->new('unspecified'); # 0:0:0:0:0:0:0:0/128
NetAddr::IP::Lite->new('any'); # 0.0.0.0/0
NetAddr::IP::Lite->new('default'); # 0.0.0.0/0
NetAddr::IP::Lite->new('loopback'); # 127.0.0.1/8
NetAddr::IP::Lite->new('localhost'); # 127.0.0.1/32, via the resolver
The broadcast keyword is IPv4 only: new6('broadcast') returns undef, while new6('unspecified') gives an IPv6 unspecified address. The loopback keyword gives a /8, not a /32. The name localhost is not a keyword at all: it is resolved, so it is undef under :nofqdn and resolver-dependent otherwise.
Address and mask
->addr()-
Returns a scalar with the address part of the object as an IPv4 or IPv6 text string as appropriate. This is useful for printing or for passing the address part of the NetAddr::IP::Lite object to other components that expect an IP address. If the object is an ipV6 address or was created using ->new6($ip) it will be reported in ipV6 hex format otherwise it will be reported in dot quad format only if it resides in ipV4 address space.
->mask()-
Returns a scalar with the mask as an IPv4 or IPv6 text string as described above.
->masklen()-
Returns a scalar the number of one bits in the mask.
->bits()-
Returns the width of the address in bits. Normally 32 for v4 and 128 for v6.
->version()-
Returns the version of the address or subnet. Currently this can be either 4 or 6.
->cidr()-
Returns a scalar with the address and mask in CIDR notation. A NetAddr::IP::Lite object stringifies to the result of this function. (see comments about ->new6() and ->addr() for output formats)
->aton()-
Returns the address part of the NetAddr::IP::Lite object in the same format as the
inet_aton()oripv6_atonfunction respectively. If the object was created using ->new6($ip), the address returned will always be in ipV6 format, even for addresses in ipV4 address space.
Boundaries
->network()-
Returns a new object referring to the network address of a given subnet. A network address has all zero bits where the bits of the netmask are zero. Normally this is used to refer to a subnet.
->broadcast()-
Returns a new object referring to the broadcast address of a given subnet. The broadcast address has all ones in all the bit positions where the netmask has zero bits. This is normally used to address all the hosts in a given subnet.
->first()-
Returns a new object representing the first usable IP address within the subnet (ie, the first host address).
->last()-
Returns a new object representing the last usable IP address within the subnet (ie, one less than the broadcast address).
->range()-
Returns a scalar with the base address and the broadcast address separated by a dash and spaces. This is called range notation.
Numeric forms
->numeric()-
When called in a scalar context, will return a numeric representation of the address part of the IP address. When called in an array context, it returns a list of two elements. The first element is as described, the second element is the numeric representation of the netmask.
This method is essential for serializing the representation of a subnet.
The ipV6 value has more digits than a Perl number holds, so
==,<=>andsorton twonumeric()results compare them as floats and call distinct addresses equal:my $x = NetAddr::IP::Lite->new('2001:db8::1'); my $y = NetAddr::IP::Lite->new('2001:db8::2'); print scalar $x->numeric, "\n"; # 42540766411282592856903984951653826561 print $x->numeric == $y->numeric ? 'same' : 'different'; # same, though the addresses differ in the last digitCompare the objects directly, since both operators are overloaded, or use
->bigint():print $x == $y ? 'same' : 'different'; # different print $x <=> $y; # -1 print $x->bigint == $y->bigint ? 'same' : 'different'; # different ->bigint()-
When called in scalar context, will return a Math::BigInt representation of the address part of the IP address. When called in an array context, it returns a list of two elements, The first element is as described, the second element is the Math::BigInt representation of the netmask.
Containment
$me->contains($other)-
Returns true when
$mecompletely contains$other. False is returned otherwise andundefis returned if$meand$otherare not bothNetAddr::IP::Liteobjects. $me->within($other)-
The complement of
->contains(). Returns true when$meis completely contained within$other, undef if$meand$otherare not bothNetAddr::IP::Liteobjects.An IPv4 object and an IPv6 object never contain each other, even when the IPv6 address is the IPv4 address in
::a.b.c.dor::ffff:a.b.c.dform. Compare->addr()of the two to see why: they print as different addresses. ->is_rfc1918()-
Returns true when
$meis an RFC 1918 address.10.0.0.0 - 10.255.255.255 (10/8 prefix) 172.16.0.0 - 172.31.255.255 (172.16/12 prefix) 192.168.0.0 - 192.168.255.255 (192.168/16 prefix) ->is_local()-
Returns true when
$meis a local network address.i.e. ipV4 127.0.0.0 - 127.255.255.255 or ipV6 === ::1 or ipV6 ::127.0.0.0 - ::127.255.255.255 or ipV6 ::ffff:127.0.0.0 - ::ffff:127.255.255.255An IPv4 loopback address held in an IPv6 object, whether from
new6or as a mapped address, is local, the same as its IPv4 form.
Hosts
->num()-
Returns the number of usable addresses in the subnet: the host count, excluding the network and broadcast addresses. A /31 or /127 counts as 2 usable addresses per RFC 3021, and a /32 or /128 counts as 1:
print NetAddr::IP::Lite->new('192.0.2.0/31')->num(); # 2 print NetAddr::IP::Lite->new('2001:db8::/127')->num(); # 2 print NetAddr::IP::Lite->new('192.0.2.0/30')->num(); # 2 print NetAddr::IP::Lite->new('192.0.2.0/28')->num(); # 14 print NetAddr::IP::Lite->new('192.0.2.1/32')->num(); # 1To use the old behavior for
->nth($index)and->num():use NetAddr::IP::Lite qw(:old_nth);WARNING:
NetAddr::IP will calculate and return a numeric string for network ranges as large as 2**128. These values are TEXT strings and perl can treat them as integers for numeric calculations.
Perl on 32 bit platforms only handles integer numbers up to 2**32 and on 64 bit platforms to 2**64.
If you wish to manipulate numeric strings returned by NetAddr::IP that are larger than 2**32 or 2**64, respectively, you must load additional modules such as Math::BigInt, bignum or some similar package to do the integer math.
->nth($index)-
Returns a new object representing the n-th usable IP address within the subnet (ie, the n-th host address). If no address is available (for example, when the network is too small for
$indexhosts),undefis returned.See "DEPRECATED" and the Changes file for the change, and the
:old_nthtag for the old behaviour.To use the old behavior for
->nth($index)and->num():use NetAddr::IP::Lite qw(:old_nth); old behavior: NetAddr::IP::Lite->new('192.0.2.0/32')->nth(0) == undef NetAddr::IP::Lite->new('192.0.2.0/32')->nth(1) == undef NetAddr::IP::Lite->new('192.0.2.0/31')->nth(0) == undef NetAddr::IP::Lite->new('192.0.2.0/31')->nth(1) == 192.0.2.1/31 NetAddr::IP::Lite->new('192.0.2.0/30')->nth(0) == undef NetAddr::IP::Lite->new('192.0.2.0/30')->nth(1) == 192.0.2.1/30 NetAddr::IP::Lite->new('192.0.2.0/30')->nth(2) == 192.0.2.2/30 NetAddr::IP::Lite->new('192.0.2.0/30')->nth(3) == 192.0.2.3/30Note that in each case, the broadcast address is represented in the output set and that the 'zero'th index is always undef.
new behavior: NetAddr::IP::Lite->new('192.0.2.0/32')->nth(0) == 192.0.2.0/32 NetAddr::IP::Lite->new('192.0.2.1/32')->nth(0) == 192.0.2.1/32 NetAddr::IP::Lite->new('192.0.2.0/31')->nth(0) == 192.0.2.0/31 NetAddr::IP::Lite->new('192.0.2.0/31')->nth(1) == 192.0.2.1/31 NetAddr::IP::Lite->new('192.0.2.0/30')->nth(0) == 192.0.2.1/30 NetAddr::IP::Lite->new('192.0.2.0/30')->nth(1) == 192.0.2.2/30 NetAddr::IP::Lite->new('192.0.2.0/30')->nth(2) == undefNote that a /32 net always has 1 usable address while a /31 has exactly two usable addresses for point-to-point addressing. The first index (0) returns the address immediately following the network address except for a /31 or /127 when it return the network address.
FUNCTIONS
Zeros, Zero, Ones, V4mask and V4net
use NetAddr::IP::Lite qw(Ones V4mask V4net Zeros);
use NetAddr::IP::Util qw(ipv6_n2x);
print ipv6_n2x(Zeros()), "\n"; # 0:0:0:0:0:0:0:0
print ipv6_n2x(Ones()), "\n"; # FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF
print ipv6_n2x(V4mask()), "\n"; # FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:0:0
print ipv6_n2x(V4net()), "\n"; # 0:0:0:0:0:0:FFFF:FFFF
Each returns a 128 bit string, the form an object keeps its address and mask in. The first is all zero bits and the second all one bits. The IPv4 pair, V4mask and V4net, has ones above the low 32 bits and in them respectively. Another name for Zeros is Zero.
EXPORT_OK
Zeros
Zero
Ones
V4mask
V4net
IMPORT TAGS
Five tags are accepted by this module. All of them are process-wide: they change behaviour for the whole program, not for one object, so an import in an unrelated package changes the output for everyone.
:lower-
Return IPv6 text in lowercase, which RFC 5952 s4.3 recommends.
:upper-
Return IPv6 text in uppercase, which is the default.
:upperwins if both:lowerand:upperare given, whichever order they are in:use NetAddr::IP::Lite qw(:lower :upper); print NetAddr::IP::Lite->new('2001:db8::1')->addr, "\n"; # 2001:DB8:0:0:0:0:0:1 use NetAddr::IP::Lite qw(:upper :lower); print NetAddr::IP::Lite->new('2001:db8::1')->addr, "\n"; # 2001:DB8:0:0:0:0:0:1Note that :lower and :upper set one process-wide variable shared by NetAddr::IP, NetAddr::IP::Lite, NetAddr::IP::Util and NetAddr::IP::InetBase. Importing either tag in one module changes the output of every other module in the same program. The last import wins.
:nofqdn-
Do not resolve a fully qualified domain name in the constructor, which is otherwise done for you.
:old_nth-
Restore the pre-4.00
nth()andnum()behaviour. Deprecated; see "DEPRECATED". :aton-
Accept a raw packed address in
new(). Deprecated; see "DEPRECATED".
NetAddr::IP accepts two more, :old_storable and :rfc3021, and rejects nothing that this module accepts.
DEPRECATED
Everything listed here is deprecated and will be removed in version 5.
:aton-
Enables
->new()to accept a raw packed address of four or sixteen bytes, and stops it stripping surrounding whitespace, which a packed address may begin or end with. Plaininet_atonnotation is accepted without this tag.The length of the string does not mark it as packed. Every text form listed under "Constructors" is tried first, then a host name lookup, and the string is read as packed only when all of them fail. A packed address whose bytes also spell text comes back as that text, or as undef:
string packed address result of new() under :aton "1 23" 49.32.50.51 1.0.0.0/23, an address and a mask "a bc" 97.32.98.99 undef, a mask that is not valid "1234" 49.50.51.52 0.0.4.210/32, a decimal integer "1.23" 49.46.50.51 1.0.0.23/32, a short dotted form "0x1f" 48.120.49.102 0.0.0.31/32, a hex literal "::1f" 58.58.49.102 0:0:0:0:0:0:0:1F/128, IPv6 textStrings of digits with dots, hyphens, or an x or b after a leading zero can read as integers, short dotted forms, ranges and hex or binary literals. A space, tab, newline, carriage return, vertical tab, form feed or slash between two runs of letters, digits, dots, colons and hyphens splits the string into an address and a mask.
Any byte 0x3A, an ASCII colon, sends the string to the IPv6 text parser. Unless the whole string is IPv6 text, as in the last row above, the result is undef. Packed IPv4 addresses with an octet of 58, such as 192.0.2.58, fall into this group, as does 2001:db8::3a packed into sixteen bytes.
A string made only of ASCII letters, digits, dots, hyphens and underscores is looked up as a host name before it is read as packed. A packed address such as 109.97.105.108, the bytes "mail", makes the call wait for the resolver: one lookup, or three when Socket6 is installed. If the name resolves, the answer is returned in place of the packed address.
The order also affects text. A four or sixteen character string that is not valid text and does not resolve, a mistyped host name for example, can come back as the address its bytes spell instead of undef.
Use
new_from_atonfor a packed IPv4 address: it reads every four byte string as packed and makes no lookup. There is no replacement for the packed sixteen byte case.use NetAddr::IP::Lite qw(:aton); new_cisandnew_cis6-
Accept the Cisco address and mask notation, with a space separator in place of a slash.
->new()and->new6()do the same.->new('192.0.2.0 24') in place of ->new_cis('192.0.2.0 24') ->new6('::192.0.2.0 120') in place of ->new_cis6('::192.0.2.0 120')
SEE ALSO
NetAddr::IP, NetAddr::IP::Util, NetAddr::IP::InetBase
AUTHORS
Dean Hamstead <dean@fragfest.com.au>
Luis E. Muñoz <luismunoz@cpan.org>
Michael Robinton <miker@cpan.org>
COPYRIGHT AND LICENSE
This software is Copyright (c) 2026 by Dean Hamstead.
This is free software, licensed under:
The GNU General Public License, Version 2, June 1991
ADDITIONAL LICENSE
This file is also available to redistribute it and/or modify it under the terms of the "Artistic License" which comes with this distribution, in the file named "Artistic".