Iptrie.Iana (Iptrie v0.7.0) View Source

Functions to access or retrieve a snapshot of the IANA IPv4/6 Special-Purpose Address Registries.

They include:

There are only two functions:

See Pfx.iana_special/2 for more information.

Examples

iex> Iptrie.Iana.lookup("10.10.10.10")
{"10.0.0.0/8",
 %{
   allocation: "1996-02",
   destination: true,
   forward: true,
   global: false,
   name: "private-use",
   prefix: "10.0.0.0/8",
   reserved: false,
   source: true,
   spec: ["rfc1918"]
 }}

 iex> Iptrie.Iana.lookup("fc00::", :global)
 false

 iex> Iptrie.Iana.lookup("fc00::", :name)
 "unique-local"

Link to this section Summary

Functions

Returns the list of IPv4 or IPv6 prefixes and their IANA special purpose address properties in a map.

Returns either nil, a property value or property map for given prefix

Link to this section Functions

Specs

get(:ip4 | :ip6) :: [{Pfx.t(), map()}]

Returns the list of IPv4 or IPv6 prefixes and their IANA special purpose address properties in a map.

Examples

iex> get(:ip4) |> length()
25

iex> get(:ip4) |> hd()
{%Pfx{bits: <<0, 0, 0, 0>>, maxlen: 32},
 %{
   allocation: "1981-09",
   destination: false,
   forward: false,
   global: false,
   name: "this-host-on-this-network",
   prefix: "0.0.0.0/32",
   reserved: true,
   source: true,
   spec: ["rfc1122"]
 }}

iex> get(:ip6) |> length()
20

iex> get(:ip6) |> hd()
{%Pfx{bits: <<0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0>>, maxlen: 128},
 %{
   allocation: "2006-02",
   destination: false,
   forward: false,
   global: false,
   name: "unspecified-address", 
   prefix: "::/128",
   reserved: true,
   source: true,
   spec: ["rfc4291"]
 }}

# get all non-globally-routed IPv4 prefixes
iex> get(:ip4)
...> |> Enum.filter(fn {_, m} -> m.global != true end)
...> |> Enum.map(fn {pfx, _} -> "#{pfx}" end)
[
  "0.0.0.0", "0.0.0.0/8", "10.0.0.0/8", "100.64.0.0/10", "127.0.0.0/8",
  "169.254.0.0/16", "172.16.0.0/12", "192.0.0.0/29", "192.0.0.0/24", "192.0.0.8",
  "192.0.0.170", "192.0.0.171", "192.0.2.0/24", "192.88.99.0/24",
  "192.168.0.0/16", "198.18.0.0/15", "198.51.100.0/24", "203.0.113.0/24",
  "240.0.0.0/4", "255.255.255.255"
]
Link to this function

lookup(prefix, property \\ nil)

View Source

Specs

lookup(Pfx.prefix(), atom() | nil) :: nil | map() | any()

Returns either nil, a property value or property map for given prefix

Examples

iex> lookup("10.10.10.10")
{"10.0.0.0/8",
 %{
   allocation: "1996-02",
   destination: true,
   forward: true,
   global: false,
   name: "private-use",
   prefix: "10.0.0.0/8",
   reserved: false,
   source: true,
   spec: ["rfc1918"]
 }}

# non-existing property
iex> lookup("10.10.10.10", :missing)
nil

iex> lookup("::ffff:0:0/96", :global)
false

iex> lookup("::ffff:0:0/96", :name)
"ipv4-mapped-address"