[RELEASE] host-setup(1): a dialog(1)-based utility for
configuring FreeBSD
Matthew Seaman
m.seaman at infracaninophile.co.uk
Sat Feb 12 10:48:58 UTC 2011
On 11/02/2011 18:08, Devin Teske wrote:
> $ time blen2netmask 26
> 255.255.255.192
>
> real 0m0.004s
> user 0m0.001s
> sys 0m0.004s
>
> That's pretty fast, I'd say ^_^ (faster than the other implementations
> -- especially considering that it doesn't have to fork anything).
There are only 33 possible netmasks -- did you evaluate simply
enumerating them all and simply looking up the result?
Hmmm...
blen2netmask() {
local nbits=$1
case $nbits in
0) echo '0.0.0.0' ;;
1) echo '128.0.0.0' ;;
2) echo '192.0.0.0' ;;
3) echo '224.0.0.0' ;;
4) echo '240.0.0.0' ;;
5) echo '248.0.0.0' ;;
6) echo '252.0.0.0' ;;
7) echo '254.0.0.0' ;;
8) echo '255.0.0.0' ;;
9) echo '255.128.0.0' ;;
10) echo '255.192.0.0' ;;
11) echo '255.224.0.0' ;;
12) echo '255.240.0.0' ;;
13) echo '255.248.0.0' ;;
14) echo '255.252.0.0' ;;
15) echo '255.254.0.0' ;;
16) echo '255.255.0.0' ;;
17) echo '255.255.128.0' ;;
18) echo '255.255.192.0' ;;
19) echo '255.255.224.0' ;;
20) echo '255.255.240.0' ;;
21) echo '255.255.248.0' ;;
22) echo '255.255.252.0' ;;
23) echo '255.255.254.0' ;;
24) echo '255.255.255.0' ;;
25) echo '255.255.255.128' ;;
26) echo '255.255.255.192' ;;
27) echo '255.255.255.224' ;;
28) echo '255.255.255.240' ;;
29) echo '255.255.255.248' ;;
30) echo '255.255.255.252' ;;
31) echo '255.255.255.254' ;;
32) echo '255.255.255.255' ;;
*) echo "$nbits -- not a valid IPv4 netmask length"
return -1 ;;
esac
return 0
}
Cheers,
Matthew
--
Dr Matthew J Seaman MA, D.Phil. 7 Priory Courtyard
Flat 3
PGP: http://www.infracaninophile.co.uk/pgpkey Ramsgate
JID: matthew at infracaninophile.co.uk Kent, CT11 9PW
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 267 bytes
Desc: OpenPGP digital signature
Url : http://lists.freebsd.org/pipermail/freebsd-hackers/attachments/20110212/8a1fcd30/signature.pgp
More information about the freebsd-hackers
mailing list