Search documentation of jhn_stdlib

# jhn_ip_addr (jhn_stdlib v5.10.3)

View Source

A IP library based on: IP Version 6 Addressing Architecture (rfc4291) A Recommendation for IPv6 Address Text Representation (rfc5952) Classless Inter-domain Routing (CIDR): (rfc4632) The Internet Address Assignment and Aggregation Plan

# Summary

## Types

ip/0
ipv4/0
ipv6/0
opt/0
range/0

## Functions

bounds(Range)

Determines the IP bounds for a range Equivalent of bounds(IOData, []).

bounds(Binary, Opts)

Determines the IP bounds for a range Bounds will give an exception if the binary is not well formed IP. Options are: integer -> an integer is returned (Default) tuple -> a tuple of integers is returned ipv6ipv4 -> with tuple the two last parts are returned as an IPv4 tuple

decode(Binary)

Decodes the binary into an Integer. Equivalent of decode(IOData, []) -> Integer.

decode(Binary, Opts)

Decodes the binary into a structured Erlang. Decode will give an exception if the binary is not well formed IP. Options are: integer -> an integer is returned (Default) tuple -> a tuple of integers is returned ipv6ipv4 -> with tuple the two last parts are returned as an IPv4 tuple range -> a IP range is being decoded continue -> all remaining indata is returned

encode(Term)

Encodes the structured Erlang term as an iolist. Equivalent of encode(Term, []) -> IP.

encode(Term, Opts)

Encodes the structured Erlang term as an iolist or binary. Encode will give an exception if the erlang term is not well formed. Options are: binary -> a binary is returned list -> a flat list is returned iolist -> an iolist is returned (Default) ipv4 -> an ipv4 address is encoded when the Term is an integer ipv6 -> an ipv6 address is encoded when the Term is an integer ipv6ipv4 -> encoded IPv6 host address has the two least sigificant segments repesented in IPv4 address format compact -> the most compact encoding of IPv6 used (collapsed zeros)

# Types

# ip/0

    -type ip() :: ipv4() | ipv6().

# ipv4/0

    -type ipv4() :: integer() | {integer(), integer(), integer(), integer()}.

# ipv6/0

    -type ipv6() ::
              integer() |
              {integer(), integer(), integer(), integer(), integer(), integer(), integer(), integer()} |
              {integer(),
               integer(),
               integer(),
               integer(),
               integer(),
               integer(),
               {integer(), integer(), integer(), integer()}}.

# opt/0

    -type opt() :: _.

# range/0

    -type range() :: integer().

# Functions

# bounds(Range)

    -spec bounds(iodata() | {ip(), range()}) -> {integer(), integer()}.

Determines the IP bounds for a range Equivalent of bounds(IOData, []).

# bounds(Binary, Opts)

    -spec bounds(iodata() | {ip(), range()},
                 [opt()] |
                 #opts{format :: ipv4 | ipv6,
                       ipv6ipv4 :: boolean(),
                       continue :: boolean(),
                       range :: boolean(),
                       compact :: boolean(),
                       return_type :: iolist | list | binary | tuple | integer}) ->
                    {ip(), ip()}.

Determines the IP bounds for a range Bounds will give an exception if the binary is not well formed IP. Options are: integer -> an integer is returned (Default) tuple -> a tuple of integers is returned ipv6ipv4 -> with tuple the two last parts are returned as an IPv4 tuple

# decode(Binary)

    -spec decode(iodata()) -> ip() | {ip(), iodata()}.

Decodes the binary into an Integer. Equivalent of decode(IOData, []) -> Integer.

# decode(Binary, Opts)

    -spec decode(iodata(),
                 [opt()] |
                 #opts{format :: ipv4 | ipv6,
                       ipv6ipv4 :: boolean(),
                       continue :: boolean(),
                       range :: boolean(),
                       compact :: boolean(),
                       return_type :: iolist | list | binary | tuple | integer}) ->
                    ip() | {ip(), range()} | {ip(), iodata()} | {ip(), range(), iodata()}.

Decodes the binary into a structured Erlang. Decode will give an exception if the binary is not well formed IP. Options are: integer -> an integer is returned (Default) tuple -> a tuple of integers is returned ipv6ipv4 -> with tuple the two last parts are returned as an IPv4 tuple range -> a IP range is being decoded continue -> all remaining indata is returned

# encode(Term)

    -spec encode(ip() | {ip(), range()}) -> iolist().

Encodes the structured Erlang term as an iolist. Equivalent of encode(Term, []) -> IP.

# encode(Term, Opts)

    -spec encode(ip() | {ip(), range()},
                 [opt()] |
                 #opts{format :: ipv4 | ipv6,
                       ipv6ipv4 :: boolean(),
                       continue :: boolean(),
                       range :: boolean(),
                       compact :: boolean(),
                       return_type :: iolist | list | binary | tuple | integer}) ->
                    iolist() | binary().

Encodes the structured Erlang term as an iolist or binary. Encode will give an exception if the erlang term is not well formed. Options are: binary -> a binary is returned list -> a flat list is returned iolist -> an iolist is returned (Default) ipv4 -> an ipv4 address is encoded when the Term is an integer ipv6 -> an ipv6 address is encoded when the Term is an integer ipv6ipv4 -> encoded IPv6 host address has the two least sigificant segments repesented in IPv4 address format compact -> the most compact encoding of IPv6 used (collapsed zeros)