Help with Network Address Math

Top Page
Attachments:
Message as email
+ (text/plain)
Delete this message
Reply to this message
Author: Kurt Granroth
Date:  
Subject: Help with Network Address Math
On Thursday 07 August 2003 02:12 pm, Kurt Granroth wrote:
> AND the IP address with the mask
> C0A80164 & FFFF0000 = C0A80000
>
> AND the network with the mask
> C0A80000 & FFFF0000 = C0A80000


On further recollection, this step isn't necessary. Just compare the IP
address ANDed with the netmask with the network IP.

Also, that means that given any IP address and a netmask, you can compute what
network it's on.

192.168.127.25/18 is on network 192.168.64.0, for instance

C0A87F19 & FFFFC000 = C0A84000 (192.168.64.0)

I also did a very quick search on google and found the following two utilities
that do the conversion for you. Perhaps you can use them as a code example:

http://lpccomp.bc.ca/netmask/netmask.c
http://jabber.mpsnet.net.mx/ftp/linux/misc/ipcalc.pl