Graham Hares writes:
>      if [ $oct1 -lt 128 ]&&[ $oct2 -eq   0 ]&&[ $oct3 -eq   0 ]&&[ $oct4 -eq  
>  0 ];then cidr=0;

You can do most of this with:

perl -e 'use Socket; print unpack("%32b*",inet_aton($ARGV[0])), "\n";' $nm

If you really want to make sure that unsupported non-contiguous
netmasks are all transformed into /24 as this script does (not sure
why that's a good thing), then:

perl -e 'use Socket;
        $addr = inet_aton($ARGV[0]);
        $bits = unpack("%32b*",$addr);
        $contig = pack("N",~((1<<(32-$bits))-1));
        print (($contig eq $addr ? $bits : 24), "\n");' $nm

> cidr2dot() {
>    cidr=$1
>      if [ $cidr -ge 32 ];then netmask='255.255.255.255'

Similarly:

perl -e 'use Socket;
        ($c1,$c2,$c3,$c4) = unpack("C4",pack("N",~((1<<(32-$ARGV[0]))-1)));
        print "$c1.$c2.$c3.$c4\n";' $cidr

There probably ought to be better ways of handling IP values in your
shell of choice.

-- 
James Carlson, Solaris Networking              <[EMAIL PROTECTED]>
Sun Microsystems / 1 Network Drive         71.232W   Vox +1 781 442 2084
MS UBUR02-212 / Burlington MA 01803-2757   42.496N   Fax +1 781 442 1677
_______________________________________________
zones-discuss mailing list
zones-discuss@opensolaris.org

Reply via email to