Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl -w + use IO::Socket; use strict; + my ( $key, %new, $str1, $str2, $str3, $mask, $ip, $ip_disp, $mask_disp ); + $str1 = '202.6.145.136'; $str2 = '29'; $str3 = '29'; print "$str1, $str2, $str3\n"; $mask = pack ('B32', (1 x $str2), (1 x (32 - $str2))); $new {AA} {inet_aton ($str1) & $mask} = $mask . pack ('B32', (1 x $str3), (1 x (32 - $str3 +))); + for $ip ( keys %{$new{AA}} ) { $ip_disp = join('.',unpack('CCCC',$ip)); print "unpack ip CCCC = $ip_disp\n\n"; + $mask_disp = join('.',unpack('CCCC',$new{AA}{$ip})); print "unpack mask CCCC = $mask_disp\n\n"; + $mask_disp = join('.',unpack('CCCC',substr($new{AA}->{$ip},0,4))); print "substr/unpack CCCC mask = $mask_disp\n"; } exit;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Pack/Unpack with B32 and related query
by pg (Canon) on Jul 28, 2004 at 04:00 UTC | |
|
Re: Pack/Unpack with B32 and related query (fix)
by tye (Sage) on Jul 28, 2004 at 05:15 UTC | |
|
Re: Pack/Unpack with B32 and related query
by esskar (Deacon) on Jul 28, 2004 at 02:26 UTC | |
|
Re: Pack/Unpack with B32 and related query
by Anonymous Monk on Jul 28, 2004 at 04:13 UTC | |
|
Re: Pack/Unpack with B32 and related query
by Anonymous Monk on Jul 28, 2004 at 06:59 UTC |