> I wrote a C function for one of my projects in order to compare an IP
> address to a CIDR-style net specification (e.g. 66.54.64.0/19).
> Thought I'd post the code here, in case anyone needs it.
>
> It's in the form of a small utility that can be used as a stream
> filter, for extracting IPs from a list that match a CIDR
> specification.
An update, I've converted it into a more useful complete application:
http://www.pc-tools.net/unix/grepcidr/
grepcidr can be used as a stream filter when you need to compare a list of
IP addresses against one or more Classless Inter-Domain Routing (CIDR) mask
specifications. Think of grepcidr as a CIDR-aware grep; instead of using
'grep 1.2.3.4' you can use 'grepcidr 1.2.3.4/30', for example. Multiple
specifications, of arbitrary mask lengths, can be specified both on the
command line or loaded from a file.
--
Jem Berkes
http://www.sysdesign.ca/