aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorFredrik Gustafsson <[email protected]>2013-07-30 16:06:40 +0200
committerFredrik Gustafsson <[email protected]>2013-07-30 16:06:40 +0200
commite547c997a4e516d3474e577bd4747e249303a7c7 (patch)
tree01fe9326f74ba6f1bf58f9dbd0d71a17e8bcb60c /lib
parentd794ba8845619322639f24602624b9acd71efc98 (diff)
downloadotp-e547c997a4e516d3474e577bd4747e249303a7c7.tar.gz
otp-e547c997a4e516d3474e577bd4747e249303a7c7.tar.bz2
otp-e547c997a4e516d3474e577bd4747e249303a7c7.zip
kernel: added ntoa documentation and exported it in inet.erl
Diffstat (limited to 'lib')
-rw-r--r--lib/kernel/doc/src/inet.xml7
-rw-r--r--lib/kernel/src/inet.erl9
-rw-r--r--lib/kernel/src/inet_parse.erl4
3 files changed, 18 insertions, 2 deletions
diff --git a/lib/kernel/doc/src/inet.xml b/lib/kernel/doc/src/inet.xml
index f33ea3c57d..254dfbf034 100644
--- a/lib/kernel/doc/src/inet.xml
+++ b/lib/kernel/doc/src/inet.xml
@@ -375,6 +375,13 @@ fe80::204:acff:fe17:bf38
</desc>
</func>
<func>
+ <name name="ntoa" arity="1" />
+ <fsummary>Convert IPv6 / IPV4 adress to ascii</fsummary>
+ <desc>
+ <p>Parses an <a href="#type-ip_address">ip_address()</a> and returns an IPv4 or IPv6 address string.</p>
+ </desc>
+ </func>
+ <func>
<name name="parse_ipv4_address" arity="1" />
<fsummary>Parse an IPv4 address</fsummary>
<desc>
diff --git a/lib/kernel/src/inet.erl b/lib/kernel/src/inet.erl
index 3ea530a366..d0fddec058 100644
--- a/lib/kernel/src/inet.erl
+++ b/lib/kernel/src/inet.erl
@@ -32,7 +32,7 @@
ip/1, stats/0, options/0,
pushf/3, popf/1, close/1, gethostname/0, gethostname/1,
parse_ipv4_address/1, parse_ipv6_address/1, parse_ipv4strict_address/1,
- parse_ipv6strict_address/1, parse_address/1, parse_strict_address/1]).
+ parse_ipv6strict_address/1, parse_address/1, parse_strict_address/1, ntoa/1]).
-export([connect_options/2, listen_options/2, udp_options/2, sctp_options/2]).
@@ -529,6 +529,13 @@ getservbyname(Name, Protocol) when is_atom(Name) ->
Error -> Error
end.
+-spec ntoa(IpAddress) ->
+ {ok, Address} | {error, einval} when
+ Address :: string(),
+ IPv4Address :: ip_address().
+ntoa(Addr) ->
+ inet_parse:ntoa(Addr).
+
-spec parse_ipv4_address(Address) ->
{ok, IPv4Address} | {error, einval} when
Address :: string(),
diff --git a/lib/kernel/src/inet_parse.erl b/lib/kernel/src/inet_parse.erl
index 619c78a6ca..98bd8d386c 100644
--- a/lib/kernel/src/inet_parse.erl
+++ b/lib/kernel/src/inet_parse.erl
@@ -722,7 +722,9 @@ ntoa({0,0,0,0,0,16#ffff,A,B}) ->
"::FFFF:" ++ dig_to_dec(A) ++ "." ++ dig_to_dec(B);
ntoa({_,_,_,_,_,_,_,_}=T) ->
%% Find longest sequence of zeros, at least 2, to replace with "::"
- ntoa(tuple_to_list(T), []).
+ ntoa(tuple_to_list(T), []);
+ntoa(_) ->
+ {error, einval}.
%% Find first double zero
ntoa([], R) ->