diff options
author | Asbjørn Sloth Tønnesen <ast@2e8.dk> | 2019-07-19 21:43:02 +0000 |
---|---|---|
committer | Asbjørn Sloth Tønnesen <ast@2e8.dk> | 2019-07-19 21:43:02 +0000 |
commit | d42329c948cafec31250c8cdba028d116a76a709 (patch) | |
tree | 309a341171ef2275573c6f472fc746dda3ebbbe3 /README.rst | |
parent | 1d7959d798b367b96cf489d08623647587334821 (diff) | |
download | lua-inet-d42329c948cafec31250c8cdba028d116a76a709.tar.gz lua-inet-d42329c948cafec31250c8cdba028d116a76a709.tar.xz lua-inet-d42329c948cafec31250c8cdba028d116a76a709.zip |
add inet:bits()
Signed-off-by: Asbjørn Sloth Tønnesen <ast@2e8.dk>
Diffstat (limited to 'README.rst')
-rw-r--r-- | README.rst | 28 |
1 files changed, 28 insertions, 0 deletions
@@ -82,6 +82,7 @@ Operator Description ``:netmask()`` generate netmask as an address ``:hostmask()`` generate hostmask as an address ``:flip()`` flip the least significant network bit +``:bits()`` return the address bits in a table ================= ====================================== @@ -369,6 +370,33 @@ Like ``tostring(foo)``, but never uses mixed notation. inet('::ffff:192.0.2.24'):ipstring() -- returns '::ffff:192.0.2.24' inet('::ffff:192.0.2.24'):ipstring6() -- returns '::ffff:c000:218' + +``foo:bits(n)`` +~~~~~~~~~~~~~~~ + +Return the IP as a table with elements of ``n`` bits each. + +Valid values for ``n`` are ``1``, ``2``, ``4``, ``8``, ``16`` or ``32``. + +:: + + inet('192.0.2.24'):bits(32) -- returns { 3221226008 } + inet('192.0.2.24'):bits(16) -- returns { 49152, 536 } + inet('192.0.2.24'):bits(8) -- returns { 192, 0, 2, 24 } + inet('192.0.2.24'):bits(4) -- returns { 12, 0, 0, 0, 0, 2, 1, 8 } + inet('192.0.2.24'):bits(1) -- returns + { 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0 } + + inet('2001:db8::42/64'):bits(32) -- returns { 536939960, 0, 0, 66 } + inet('::ffff:192.0.2.24'):bits(32) -- returns { 0, 0, 65535, 3221226008 } + inet('2001:db8::42/64'):bits(16) -- returns { 8193, 3512, 0, 0, 0, 0, 0, 66 } + inet('2001:db8::42/64'):bits(8) -- returns + { 32, 1, 13, 184, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 66 } + inet('2001:db8::42/64'):bits(4) -- returns + { 2, 0, 0, 1, 0, 13, 11, 8, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 2 } + Sets ---- |