问个问题,vec函数是如何将1 ~ 32 转换成掩码的,比如24对应255.255.255.0.
foreach (1..32){
printf "$_ => %s\n", &cidr2mask($_);
}
exit 1;
sub cidr2mask{
my $length = shift;
my $mask = '';
vec( $mask, 0, 32 ) = 0x0; # 这里开始我就不是太懂了,vec函数的原理是什么?
foreach (1..$length){
vec( $mask, (32-$_), 1 ) = 0x01; #这里呢?
}
$mask = join( '.', reverse( split( /\./, sprintf( "%vd", $mask ) ) ) );
return $mask;
}
2011-05-23
perl01
没有评论:
发表评论