aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAsbjørn Sloth Tønnesen <ast@2e8.dk>2020-02-17 18:47:11 +0000
committerAsbjørn Sloth Tønnesen <ast@2e8.dk>2020-02-17 20:29:00 +0000
commit915121994184739af16b03b5b50212adda503a19 (patch)
tree860df50a55f3a9d17f65606568fe0d273f0e2f7a
parent1df3b14bdfd26470c007b8443979cd20df0ea649 (diff)
downloadlua-inet-915121994184739af16b03b5b50212adda503a19.tar.gz
lua-inet-915121994184739af16b03b5b50212adda503a19.tar.xz
lua-inet-915121994184739af16b03b5b50212adda503a19.zip
add :full_family()
Signed-off-by: Asbjørn Sloth Tønnesen <ast@2e8.dk>
-rw-r--r--README.rst63
-rw-r--r--lua/inet/core.lua4
2 files changed, 40 insertions, 27 deletions
diff --git a/README.rst b/README.rst
index 5779b0a..744cac6 100644
--- a/README.rst
+++ b/README.rst
@@ -59,33 +59,34 @@ Initially the set contains these well-known networks:
Common ``inet*`` API
--------------------
-================= ======================================
-Operator Description
-================= ======================================
-``+`` Addition
-``-`` Subtract
-``/`` Change mask (absolute)
-``^`` Change mask (relative)
-``*`` Move network
-``<`` is less than
-``<=`` is less than or equal
-``==`` equals
-``>=`` is greater or equal
-``>`` is greater than
-``~=`` not equals
-``#`` number of network bits
-``:contains()`` contains
-``:network()`` extract network part of address
-``tostring(net)`` convert to network
-``:ipstring()`` ip as string without prefix
-``:cidrstring()`` format CIDR notation
-``: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
-``:subnets()`` return the amount of /n subnets
-``:family()`` return the address family (number)
-================= ======================================
+================== ======================================
+Operator Description
+================== ======================================
+``+`` Addition
+``-`` Subtract
+``/`` Change mask (absolute)
+``^`` Change mask (relative)
+``*`` Move network
+``<`` is less than
+``<=`` is less than or equal
+``==`` equals
+``>=`` is greater or equal
+``>`` is greater than
+``~=`` not equals
+``#`` number of network bits
+``:contains()`` contains
+``:network()`` extract network part of address
+``tostring(net)`` convert to network
+``:ipstring()`` ip as string without prefix
+``:cidrstring()`` format CIDR notation
+``: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
+``:subnets()`` return the amount of /n subnets
+``:family()`` return the address family (number)
+``:full_family()`` return the address family (string)
+================== ======================================
Additional ``inet6`` methods
@@ -425,6 +426,14 @@ Valid values for ``n`` are ``1``, ``2``, ``4``, ``8``, ``16`` or ``32``.
inet('192.0.2.0/24'):family() -- returns 4
inet('2001:db8::/64'):family() -- returns 6
+``foo:full_family(n)``
+~~~~~~~~~~~~~~~~~~~~~~
+
+::
+
+ inet('192.0.2.0/24'):full_family() -- returns 'ipv4'
+ inet('2001:db8::/64'):full_family() -- returns 'ipv6'
+
Sets
----
diff --git a/lua/inet/core.lua b/lua/inet/core.lua
index 398bc66..2b36543 100644
--- a/lua/inet/core.lua
+++ b/lua/inet/core.lua
@@ -75,6 +75,10 @@ function inet:family()
return ret
end
+function inet:full_family()
+ return format('ipv%d', self:family())
+end
+
local ipv4_parser
local ipv6_parser
do