NAME

Net::Silk::CIDR - SiLK IP CIDR class

SYNOPSIS

use Net::Silk::CIDR;

my $r = Net::Silk::CIDR->new('1.1.1.0' => 27); # or "1.1.1.0/27"

$r->contains("1.1.1.2"); # true

print "$r\n";                            # 1.1.1.0/27
print join('/', $r->ip, $r->prefix), "\n"; # 1.1.1.0/27
print join('/', @$r, "\n";               # 1.1.1.0/27

my $size = $r->cardinality; # 32

use Net::Silk::IPSet;
my $s = Net::Silk::IPSet->load("my.set");
my $iter = $s->iter_cidr;
while (my $r = $iter->()) {
  ... # $r is a Net::Silk::CIDR
}

use Net::Silk::Pmap;
my $s = Net::Silk::Pmap->load("my.pmap");
my $iter = $s->iter_cidr;
while (my($k, $v) = each %$s) {
  ... # $k is a Net::Silk::CIDR
}

DESCRIPTION

Net::Silk::CIDR is a lightweight wrapper around a CIDR block specified by an IP and prefix bits. It is returned by iterators in Net::Silk::IPSet and Net::Silk::Pmap.

METHODS

new($addr, $prefix)
new([$addr, $prefix])
new($string)

Returns a new Net::Silk::CIDR object represented by the given IP base and prefix bits. The two values can be provided either as separate arguments, in an array ref, or a string representation.

ip()

Return the base of this CIDR as a Net::Silk::IPAddr. This can alternately be accessed via $r->[0].

prefix()

Return the prefix bits of this CIDR. This can alternately be accessed via $r->[1].

first()

Return the first address in the CIDR range, same as ip().

last()

Return the last address in the CIDR range.

carinality()

Return the number of elements in this block.

contains($item)

Return whether or not the given item is contained in this block.

as_range()

Returns a Net::Silk::Range representing this block.

as_str()

Return a string in the form of "ip/prefix". This method gets invoked automatically when the block is used in string context.

iter()

Return a sub ref that iterates over all elements of this block. Treating the object like a filehandle <$r> yields the same results.

OVERLOADED OPERATORS

The following operators are overloaded:

<>     ""
eq     ==
ne     !=

SEE ALSO

Net::Silk, Net::Silk::RWRec, Net::Silk::IPSet, Net::Silk::Bag, Net::Silk::Pmap, Net::Silk::IPWildcard, Net::Silk::Range, Net::Silk::IPAddr, Net::Silk::TCPFlags, Net::Silk::ProtoPort, Net::Silk::File, Net::Silk::Site, silk(7)

COPYRIGHT & LICENSE

Copyright (C) 2016 by Carnegie Mellon University

Use of the Net-Silk library and related source code is subject to the terms of the following licenses:

GNU Public License (GPL) Rights pursuant to Version 2, June 1991 Government Purpose License Rights (GPLR) pursuant to DFARS 252.227.7013

NO WARRANTY

See GPL.txt and LICENSE.txt for more details.