C code for CIDR comparison

C code for CIDR comparison

Post by Jem Berke » Sat, 14 Feb 2004 13:31:38



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.

http://www.pc-tools.net/beta/cidr/cidr.c

Cheers,

--
Jem Berkes
http://www.sysdesign.ca/

 
 
 

C code for CIDR comparison

Post by Jem Berke » Sun, 15 Feb 2004 17:04:13


Quote:> 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/

 
 
 

1. Telnet won't work with dhcp or CIDR?

I have RS/6000 7025-F50, running 4.2.1. Installed y2k updates, as well as a new
PC-to-Unix tool created by Syntax that allows our Unix machine to emulate a
bindery Netware server. Upon reboot, the prompt (via telnet) comes up only
after a minute or two of sitting at a blank screen or time out. FTP was timing
out. The interface netmask was set to 255.255.248.0, which is our normal
network netmask at least for netware. I changed it to 255.255.255.0 and then
the machines that have static addresses could get a login prompt right away.(
the xxx.xxx.79.xxx part) but those on dhcp cannot get in or it is slow for
them. The netware network is using CIDR and I had thought that AIX 4.2.1 does
not support CIDR. Is this true?  How would this have worked before? Anyways,
removed the y2k updates as well as the Syntax Tas server software but the
problem remains. Another server is performing the dhcp task for this server.
Clients on the netware network are not having problems with dhcp. Any help on
getting dhcp clients back up so I don't have to run around and give out 150
static IP addresses will be GREATLY appreciated.
CKG

2. replace duplicates script

3. DNS -- reverse zone delegation on a CIDR subnet

4. FTP batch

5. Help with CIDR notation

6. Cert for Apache and IMAP

7. CIDR and AIX 4.2.1

8. Removing NVidia drivers? (Caught signal 11)

9. mod_rewrite with CIDR-style IP addresses?

10. CIDR Shorthand Question

11. CIDR and Solaris2

12. iptables and cidr blocks...

13. Help - Win98/2000 and CIDR