MscmpSystNetwork.Guards (mscmp_syst_network v0.1.0)

Provides guards which can do basic IP address tuple and IP address struct validation.

Summary

Functions

A guard function which returns true when the passed value is either a valid MscmpSystNetwork.Types.IpV4.t/0 or MscmpSystNetwork.Types.IpV6.t/0 struct.

A guard function which returns true when a passed value is either an Erlang style IPv4 or IPv6 tuple.

A guard function which returns true when the passed value is a valid MscmpSystNetwork.Types.IpV4.t/0 value.

A guard function which returns true when the passed value is an integer which is a valid IPv4 subnet mask length.

A guard function which indicates whether a passed value is an Erlang style IPv4 tuple.

A guard function which returns true when the passed value is a valid MscmpSystNetwork.Types.IpV6.t/0 value.

A guard function which returns true when the passed value is an integer which is a valid IPv6 subnet mask length.

A guard function which indicates whether a passed value is an Erlang style IPv6 tuple.

Functions

Link to this macro

is_ip(addr)

(macro)

A guard function which returns true when the passed value is either a valid MscmpSystNetwork.Types.IpV4.t/0 or MscmpSystNetwork.Types.IpV6.t/0 struct.

Examples

IPv4 Examples

iex> import MscmpSystNetwork.Guards
iex> alias MscmpSystNetwork.Types.IpV4
iex> host_addr = %IpV4{address: {10, 1, 1, 10}, mask: 32}
iex> is_ip(host_addr)
true
iex> subnet_addr = %IpV4{address: {10, 1, 0, 0}, mask: 16}
iex> is_ip(subnet_addr)
true
iex> bad_addr = {10, 1, 1, 10}
iex> is_ip(bad_addr)
false

IPv6 Examples

iex> import MscmpSystNetwork.Guards
iex> alias MscmpSystNetwork.Types.IpV6
iex> host_addr = %IpV6{address: {64923, 30712, 29005, 51899, 0, 0, 0, 32}, mask: 128}
iex> is_ip(host_addr)
true
iex> subnet_addr =
...>   %IpV6{
...>     address: {64923, 30712, 29005, 51899, 0, 0, 0, 0},
...>     mask: 64
...>   }
iex> is_ip(subnet_addr)
true
iex> bad_addr = {64923, 30712, 29005, 51899, 0, 0, 0, 32}
iex> is_ip(bad_addr)
false
Link to this macro

is_ip_tuple(addr)

(macro)

A guard function which returns true when a passed value is either an Erlang style IPv4 or IPv6 tuple.

Examples

IPv4 Examples

iex> import MscmpSystNetwork.Guards
iex> is_ip_tuple({10, 1, 1, 20})
true
iex> is_ip_tuple({10, 1, 1, 0})
true
iex> is_ip_tuple(:foo)
false

IPv6 Examples

iex> import MscmpSystNetwork.Guards
iex> is_ip_tuple({64923, 30712, 29005, 51899, 0, 0, 0, 32})
true
iex> is_ip_tuple({64923, 30712, 29005, 51899, 0, 0, 0, 0})
true
iex> is_ip_tuple({0x10000, 0, 0, 0, 0, 0, 0, 1})
false
Link to this macro

is_ipv4(addr)

(macro)

A guard function which returns true when the passed value is a valid MscmpSystNetwork.Types.IpV4.t/0 value.

Examples

iex> import MscmpSystNetwork.Guards
iex> alias MscmpSystNetwork.Types.IpV4
iex> host_addr = %IpV4{address: {10, 1, 1, 10}, mask: 32}
iex> is_ipv4(host_addr)
true
iex> subnet_addr = %IpV4{address: {10, 1, 0, 0}, mask: 16}
iex> is_ipv4(subnet_addr)
true
iex> bad_addr = {10, 1, 1, 10}
iex> is_ipv4(bad_addr)
false
Link to this macro

is_ipv4_mask(mask)

(macro)

A guard function which returns true when the passed value is an integer which is a valid IPv4 subnet mask length.

Examples

iex> import MscmpSystNetwork.Guards
iex> is_ipv4_mask(24)
true
iex> is_ipv4_mask(32)
true
iex> is_ipv4_mask(64)
false
iex> is_ipv4_mask(:"24")
false
Link to this macro

is_ipv4_tuple(addr)

(macro)

A guard function which indicates whether a passed value is an Erlang style IPv4 tuple.

Examples

iex> import MscmpSystNetwork.Guards
iex> is_ipv4_tuple({10, 0, 0, 1})
true
iex> is_ipv4_tuple(:foo)
false
iex> is_ipv4_tuple({256, 0, 0, 0})
false
Link to this macro

is_ipv6(addr)

(macro)

A guard function which returns true when the passed value is a valid MscmpSystNetwork.Types.IpV6.t/0 value.

Examples

iex> import MscmpSystNetwork.Guards
iex> alias MscmpSystNetwork.Types.IpV6
iex> host_addr = %IpV6{address: {64923, 30712, 29005, 51899, 0, 0, 0, 32}, mask: 128}
iex> is_ipv6(host_addr)
true
iex> subnet_addr =
...>   %IpV6{
...>     address: {64923, 30712, 29005, 51899, 0, 0, 0, 0},
...>     mask: 64
...>   }
iex> is_ipv6(subnet_addr)
true
iex> bad_addr = {64923, 30712, 29005, 51899, 0, 0, 0, 32}
iex> is_ipv6(bad_addr)
false
Link to this macro

is_ipv6_mask(prefix)

(macro)

A guard function which returns true when the passed value is an integer which is a valid IPv6 subnet mask length.

Examples

iex> import MscmpSystNetwork.Guards
iex> is_ipv6_mask(64)
true
iex> is_ipv6_mask(128)
true
iex> is_ipv6_mask(68)
true
iex> is_ipv6_mask(:"68")
false
Link to this macro

is_ipv6_tuple(addr)

(macro)

A guard function which indicates whether a passed value is an Erlang style IPv6 tuple.

Examples

iex> import MscmpSystNetwork.Guards
iex> is_ipv6_tuple({0, 0, 0, 0, 0, 0, 0, 1})
true
iex> is_ipv6_tuple(:foo)
false
iex> is_ipv6_tuple({0x10000, 0, 0, 0, 0, 0, 0, 1})
false