Created
February 22, 2011 22:55
-
-
Save archaelus/839614 to your computer and use it in GitHub Desktop.
CIDR in/out net calculation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-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