This is somewhat OT, but with the microscopic traffic on ph-perl, I
thought I'd rather send my question here.

The problem:
I have an IP address
I have a source mask length (e.g. prefix bits).

I want to convert this info into a A.B.C.D/M format.

e.g. I have IP address 202.47.132.42 and source mask length 24. The
correct answer is 202.47.132.0/24.

This is obtained by: 1) converting the IP address to host long format; 2)
doing a bitwise-AND with the network mask.

The question: how do I construct the network mask? here's a dumb way of
doing it:

--- snip ---
my $masklen = <some value>;
my $mask = 0;
while ($masklen > 0) {
        $mask += (1 << $masklen);
        $masklen--;
}
--- snip ---

Unfortunately, this is slow. I want maximal speed. Therefore, how to do
this, in Perl.


-- 
Orlando Andico <[EMAIL PROTECTED]>
Mosaic Communications, Inc.


_
Philippine Linux Users Group. Web site and archives at http://plug.linux.org.ph
To leave: send "unsubscribe" in the body to [EMAIL PROTECTED]

To subscribe to the Linux Newbies' List: send "subscribe" in the body to 
[EMAIL PROTECTED]

Reply via email to