perl and network addresses
Jason Stephenson
jason at sigio.com
Thu Mar 30 20:36:01 EST 2006
Paul Lussier wrote:
> Yes, more or less. Between you and Jason I've been able to come up
> with exactly what I need. Thanks a lot for all your help. Why I
> couldn't see this for myself is beyond me. Of course, this week has
> been full of me "missing the details" to the point where I somehow
> managed to mail my taxes to myself from work the other day rather than
> to my accountant :) So, just in case you wondered, the USPS system is
> working at peak efficiency !
You're very welcome to the help, and we all have those weeks. It took me
a while to realize what your real question was.
Once I figured out your question, it was actually rather interesting:
adding network addresses to interpolate between different networks.
Trying to answer it allowed me to discover some facts about IPv4
addresses and masks, so I got to learn something, too.
The thing that I found most interesting is if you use the one or two
digit kind of "mask," i.e. /19, you can determine how many addresses are
on the network via the following C code: addresses = 1 << (32 - n).
Where n is the part of the mask after the /.
I wish I could find a faster way to blit the bits to make the "real"
mask from the /N style than using a for loop. Only alternative I can
think of is to use a switch on the 33 possibilities (0-32).--Of course,
anything < /8 and > /30 doesn't make a "real" network.
Can anyone think of a better way to blit an arbitrary number of bits
from 0 to 1?
Now, I'm working on a network calculator application that will support
IPv6 as well. I should probably do it in JavaScript, uh, sorry, AJAX, so
that the "Web 2.0" people will notice. ;)
Cheers,
Jason
More information about the gnhlug-discuss
mailing list