BitwiseIp.Block.member-question-mark
You're seeing just the function
member-question-mark
, go back to BitwiseIp.Block module for more information.
Specs
member?(t(), BitwiseIp.t()) :: boolean()
Efficiently checks if a bitwise IP is within a block.
In effect, we're testing if the given IP address has the same prefix as the
block. This involves a single bitwise AND
and an integer comparison. We
extract the prefix from the IP by applying the block's bitmask, then check if
it's equal to the block's starting address. If the block and the IP have
different protocols, this function will return false
.
Because BitwiseIp.Block
implements the Enumerable
protocol, you may also
use in/2
to test for membership.
Examples
iex> BitwiseIp.Block.parse!("192.168.0.0/16")
...> |> BitwiseIp.Block.member?(BitwiseIp.parse!("192.168.10.1"))
true
iex> BitwiseIp.Block.parse!("192.168.0.0/16")
...> |> BitwiseIp.Block.member?(BitwiseIp.parse!("172.16.0.1"))
false
iex> BitwiseIp.parse!("d:e:a:d:b:e:e:f") in BitwiseIp.Block.parse!("d::/16")
true
iex> BitwiseIp.parse!("127.0.0.1") in BitwiseIp.Block.parse!("::/0")
false