perl and network addresses

Jason Stephenson jason at sigio.com
Tue Mar 28 10:51:22 EST 2006


Paul Lussier wrote:
> Python <python at venix.com> writes:
> 
> 
>>Would it help to convert to 32-bit integers?  
> 
> 
> I might.  I'll try that.

It will definitely help. If you get the "netmask" and address both in 
32-bit integers, then calculating the network and broadcast addresses is 
very straightforward. Here's some sample code:

network = address & netmask;
broadcast = address | ~netmask;

The above is C, but should work in Perl, too.

Of course, after looking back through the thread, I see Ben has already 
pretty much answered the above. ;)

> 
> 
>>I think I understand the arithmetic.  I do not really understand what
>>you are trying to do.
> 
> 
> That's okay, neither do I ;)
> 
> (If you really want the long convoluted discussion, I'll be glad to
> post it, I just figured no on would care.  Of course, I also often
> misunderstimate the intellectual curiosity of fellow geeks :)

I think Paul explained it pretty well in his first post. Let me explain 
to see if I really understand.

Paul is using a network that is restricted to using a /19 netmask for 
addressing, but it is really using a /16 when configured. So, he wants 
to limit address to 10.0.32.0/19 but needs to configure broadcast and 
network addresses for 10.0.32.0/16. Why he needs to do that, I have no 
idea and wouldn't need to know. ;)

Ben's previous message pretty much explains how to solve this.

It seems to me that the answer is that your IP addresses are limited to 
the range of 10.0.32.0 to 10.0.63.255 with 10.0.0.0 being the network 
address and 10.255.255.255 being the broadcast address, no?

Cheers,
Jason



More information about the gnhlug-discuss mailing list