BitwiseIp.Mask.parse
You're seeing just the function
parse
, go back to BitwiseIp.Mask module for more information.
Specs
parse(:v4, String.t()) :: {:ok, integer()} | {:error, String.t()}
parse(:v6, String.t()) :: {:ok, integer()} | {:error, String.t()}
Parses a string prefix length into a bitmask.
Given the protocol (either :v4
or :v6
) and the string representation of a
prefix length (without the leading slash), this function looks up the
corresponding bitmask. This is done in an error-safe way by returning a
tagged tuple. To raise an error, use parse!/2
instead.
Examples
iex> BitwiseIp.Mask.parse(:v4, "12")
{:ok, 4293918720}
iex> BitwiseIp.Mask.parse(:v6, "12")
{:ok, 340199290171201906221318119490500689920}
iex> BitwiseIp.Mask.parse(:v4, "128")
{:error, "Invalid IPv4 mask \"128\""}
iex> BitwiseIp.Mask.parse(:v6, "not a mask")
{:error, "Invalid IPv6 mask \"not a mask\""}