Skip to content

Instantly share code, notes, and snippets.

@archaelus
Created February 22, 2011 22:55
Show Gist options
  • Save archaelus/839614 to your computer and use it in GitHub Desktop.
Save archaelus/839614 to your computer and use it in GitHub Desktop.
CIDR in/out net calculation
-module(netmask).
-export([in_network/3]).
in_network(Net, CIDR, IP)
when is_binary(Net), is_binary(IP), is_integer(CIDR) ->
<<NetworkPrefix:CIDR/bits, _/bits>> = Net,
case IP of
<<NetworkPrefix:CIDR/bits, _Host/bits>> ->
in_net;
_ -> not_in_net
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment