Permalink
Browse files

Merge pull request #1 from martinrehfeld/rfc1918-fix

fix is_sitelocal_addr/1 for the 172.x range
  • Loading branch information...
2 parents 693c13c + 495bcd6 commit 9508a5ec9eafc0eead0a9c7ed7c992d590fdbfd1 @oujinliang committed Dec 9, 2012
Showing with 5 additions and 2 deletions.
  1. +1 −1 src/utils_inet.erl
  2. +4 −1 test/utils_inet_test.erl
View
@@ -26,7 +26,7 @@ is_loopback_addr(_) -> false.
%% Check if a ipv4 address is a site local address
-spec is_sitelocal_addr( ip4_address()) -> true | false.
is_sitelocal_addr({10,_,_,_}) -> true;
-is_sitelocal_addr({172,16,_,_}) -> true;
+is_sitelocal_addr({172,B,_,_}) -> B >= 16 andalso B =< 31;
is_sitelocal_addr({192,168,_,_}) -> true;
is_sitelocal_addr(_) -> false.
View
@@ -8,7 +8,10 @@ sample_test() ->
?assertEqual(false, utils_inet:is_loopback_addr({137,0,0,1})),
?assertEqual(true, utils_inet:is_sitelocal_addr({10,234,22,1})),
?assertEqual(true, utils_inet:is_sitelocal_addr({10,0,22,1})),
+ ?assertEqual(false, utils_inet:is_sitelocal_addr({172,15,22,1})),
?assertEqual(true, utils_inet:is_sitelocal_addr({172,16,22,1})),
+ ?assertEqual(true, utils_inet:is_sitelocal_addr({172,31,22,1})),
+ ?assertEqual(false, utils_inet:is_sitelocal_addr({172,32,22,1})),
?assertEqual(true, utils_inet:is_sitelocal_addr({192,168,22,1})),
?assertEqual(false, utils_inet:is_sitelocal_addr({129,168,22,1})),
ok.
@@ -21,4 +24,4 @@ format_address_test() ->
Str = utils_inet:format_address({192,168,1,1}),
?assertEqual("192.168.1.1", Str),
ok.
-
+

0 comments on commit 9508a5e

Please sign in to comment.