aboutsummaryrefslogtreecommitdiffstats
path: root/lib/kernel/src
diff options
context:
space:
mode:
authorFredrik Gustafsson <[email protected]>2012-11-19 17:54:08 +0100
committerFredrik Gustafsson <[email protected]>2012-11-19 17:54:08 +0100
commite367eb44969b00cac910c8eb14e7b3ce3ee0cc91 (patch)
treed67392bdda99a969384abc1a986fe138ebcfab7e /lib/kernel/src
parent1ecc870573b37491e9dd7965d29d20efea557c01 (diff)
downloadotp-e367eb44969b00cac910c8eb14e7b3ce3ee0cc91.tar.gz
otp-e367eb44969b00cac910c8eb14e7b3ce3ee0cc91.tar.bz2
otp-e367eb44969b00cac910c8eb14e7b3ce3ee0cc91.zip
Exported ipv4address and ipv6address functions to inet module, changed and made testcases
Diffstat (limited to 'lib/kernel/src')
-rw-r--r--lib/kernel/src/inet.erl22
-rw-r--r--lib/kernel/src/inet_parse.erl13
2 files changed, 33 insertions, 2 deletions
diff --git a/lib/kernel/src/inet.erl b/lib/kernel/src/inet.erl
index 1a03424f88..133cc523fa 100644
--- a/lib/kernel/src/inet.erl
+++ b/lib/kernel/src/inet.erl
@@ -30,7 +30,9 @@
ifget/3, ifget/2, ifset/3, ifset/2,
getstat/1, getstat/2,
ip/1, stats/0, options/0,
- pushf/3, popf/1, close/1, gethostname/0, gethostname/1]).
+ pushf/3, popf/1, close/1, gethostname/0, gethostname/1,
+ ipv4_address/1, ipv6_address/1, ipv4strict_address/1,
+ ipv6strict_address/1, parse_address/1, parse_strict_address/1]).
-export([connect_options/2, listen_options/2, udp_options/2, sctp_options/2]).
@@ -527,6 +529,24 @@ getservbyname(Name, Protocol) when is_atom(Name) ->
Error -> Error
end.
+ipv4_address(Addr) ->
+ inet_parse:ipv4_address(Addr).
+
+ipv6_address(Addr) ->
+ inet_parse:ipv6_address(Addr).
+
+ipv4strict_address(Addr) ->
+ inet_parse:ipv4strict_address(Addr).
+
+ipv6strict_address(Addr) ->
+ inet_parse:ipv6strict_address(Addr).
+
+parse_address(Addr) ->
+ inet_parse:address(Addr).
+
+parse_strict_address(Addr) ->
+ inet_parse:strict_address(Addr).
+
%% Return a list of available options
options() ->
[
diff --git a/lib/kernel/src/inet_parse.erl b/lib/kernel/src/inet_parse.erl
index 65edddcb46..98390d1dcc 100644
--- a/lib/kernel/src/inet_parse.erl
+++ b/lib/kernel/src/inet_parse.erl
@@ -37,7 +37,7 @@
-export([ipv4_address/1, ipv6_address/1]).
-export([ipv4strict_address/1, ipv6strict_address/1]).
--export([address/1]).
+-export([address/1, strict_address/1]).
-export([visible_string/1, domain/1]).
-export([ntoa/1, dots/1]).
-export([split_line/1]).
@@ -472,6 +472,17 @@ address(Cs) when is_list(Cs) ->
address(_) ->
{error, einval}.
+%%Parse ipv4 strict address or ipv6 strict address
+strict_address(Cs) when is_list(Cs) ->
+ case ipv4strict_address(Cs) of
+ {ok,IP} ->
+ {ok,IP};
+ _ ->
+ ipv6strict_address(Cs)
+ end;
+strict_address(Cs) ->
+ {error, einval}.
+
%%
%% Parse IPv4 address:
%% d1.d2.d3.d4