BitwiseIp.parse
You're seeing just the function
parse
, go back to BitwiseIp module for more information.
Specs
Parses a string into a bitwise IP.
This function parses IPv4 and IPv6 strings in their respective notations and
produces an encoded BitwiseIp
struct. This is done in an error-safe way by
returning a tagged tuple. To raise an error, use parse!/1
instead.
BitwiseIp
implements the String.Chars
protocol, so parsing can be undone
using to_string/1
.
Examples
iex> BitwiseIp.parse("127.0.0.1")
{:ok, %BitwiseIp{proto: :v4, addr: 2130706433}}
iex> BitwiseIp.parse("::1")
{:ok, %BitwiseIp{proto: :v6, addr: 1}}
iex> BitwiseIp.parse("not an ip")
{:error, "Invalid IP address \"not an ip\""}
iex> BitwiseIp.parse("192.168.0.1") |> elem(1) |> to_string()
"192.168.0.1"
iex> BitwiseIp.parse("fc00::") |> elem(1) |> to_string()
"fc00::"