Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 12 Feb 2011 10:48:37 +0000
From:      Matthew Seaman <m.seaman@infracaninophile.co.uk>
To:        Devin Teske <dteske@vicor.com>
Cc:        freebsd-hackers@freebsd.org, Ian Smith <smithi@nimnet.asn.au>
Subject:   Re: [RELEASE] host-setup(1): a dialog(1)-based utility for configuring FreeBSD
Message-ID:  <4D566585.7020802@infracaninophile.co.uk>
In-Reply-To: <1297447687.9144.6.camel@dt.vicor.com>
References:  <20110211120031.9D37510656E5@hub.freebsd.org>	<20110212015155.I96449@sola.nimnet.asn.au> <1297447687.9144.6.camel@dt.vicor.com>

next in thread | previous in thread | raw e-mail | index | archive | help
This is an OpenPGP/MIME signed message (RFC 2440 and 3156)
--------------enig77090BAEC66020CB072AD5EF
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: quoted-printable

On 11/02/2011 18:08, Devin Teske wrote:
> $ time blen2netmask 26
> 255.255.255.192
>=20
> real    0m0.004s
> user    0m0.001s
> sys     0m0.004s
>=20
> 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=3D$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

--=20
Dr Matthew J Seaman MA, D.Phil.                   7 Priory Courtyard
                                                  Flat 3
PGP: http://www.infracaninophile.co.uk/pgpkey     Ramsgate
JID: matthew@infracaninophile.co.uk               Kent, CT11 9PW


--------------enig77090BAEC66020CB072AD5EF
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: OpenPGP digital signature
Content-Disposition: attachment; filename="signature.asc"

-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.16 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk1WZZUACgkQ8Mjk52CukIygCgCggPxCCvtv757bdavBR0dZy8fW
xo8AnRV9d+ChTfQ90G4v6ycvSTtCRQRE
=vvKn
-----END PGP SIGNATURE-----

--------------enig77090BAEC66020CB072AD5EF--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4D566585.7020802>