Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

steve's scratchpad

by steve (Deacon)
on Jul 30, 2008 at 13:38 UTC ( #701135=scratchpad: print w/replies, xml ) Need Help??

sub _in_cidr_dns { my ($cidr,$addr) = @_; my ($start, $range) = split /\//, $cidr; require DNS; my $start_dec = DNS::aton($start); my $addr_dec = DNS::aton($addr); return $addr_dec >= $start_dec && $addr_dec < $start_dec + 2 ** (3 +2 - $range); } sub _in_cidr_aton { my ($cidr,$addr) = @_; my ($start, $range) = split /\//, $cidr; my $start_dec = unpack("N", pack("C4", split m/\./x, $start)); my $addr_dec = unpack("N", pack("C4", split m/\./x, $addr)); return $addr_dec >= $start_dec && $addr_dec < $start_dec + 2 ** (3 +2 - $range); } sub _in_cidr_socket { my ($cidr,$addr) = @_; my ($start, $range) = split /\//, $cidr; require Socket; my $start_dec = unpack("N*",Socket::inet_aton($start)); my $addr_dec = unpack("N*",Socket::inet_aton($addr)); return $addr_dec >= $start_dec && $addr_dec < $start_dec + 2 ** (3 +2 - $range); } sub _in_cidr_bin { my ($cidr,$addr) = @_; my ($start, $range) = split /\//, $cidr; my $start_binary = _ipv4_to_32bitbinary($start); my $addr_binary = _ipv4_to_32bitbinary($addr); my $starts_with = substr($start_binary,0,$range); return $addr_binary =~ /^$starts_with/; } sub _ipv4_to_32bitbinary { join "", map {sprintf "%08b", $_} split /\. +/, shift; }
         Rate    bin    dns   aton socket
bin     595/s     --   -54%   -64%   -73%
dns    1282/s   115%     --   -23%   -41%
aton   1667/s   180%    30%     --   -23%
socket 2174/s   265%    70%    30%     --
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (6)
As of 2021-11-29 17:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?