aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZandra Hird <[email protected]>2016-06-14 11:04:58 +0200
committerZandra Hird <[email protected]>2016-06-16 11:19:10 +0200
commitc1b70a725a2cc5a64ff793b5f3ec79e82da3eff2 (patch)
treebb73903be54d2e0b7689f2466b250799eaadf784
parentdb21a04892e7cfd8d4ebad668a666b789604fcfb (diff)
downloadotp-c1b70a725a2cc5a64ff793b5f3ec79e82da3eff2.tar.gz
otp-c1b70a725a2cc5a64ff793b5f3ec79e82da3eff2.tar.bz2
otp-c1b70a725a2cc5a64ff793b5f3ec79e82da3eff2.zip
Test: Try ipv6 versions of localhost if it fails for inet6
Most systems alias localhost to both the ipv4 and ipv6 localhost address, but in some cases localhost6 is used instead.
-rw-r--r--lib/kernel/test/gen_tcp_api_SUITE.erl19
-rw-r--r--lib/kernel/test/gen_udp_SUITE.erl18
2 files changed, 30 insertions, 7 deletions
diff --git a/lib/kernel/test/gen_tcp_api_SUITE.erl b/lib/kernel/test/gen_tcp_api_SUITE.erl
index 54298e6309..8079a31a9a 100644
--- a/lib/kernel/test/gen_tcp_api_SUITE.erl
+++ b/lib/kernel/test/gen_tcp_api_SUITE.erl
@@ -279,9 +279,7 @@ t_implicit_inet6(Host, Addr) ->
implicit_inet6(S1, Loopback),
ok = gen_tcp:close(S1),
%%
- Localhost = "localhost",
- Localaddr = ok(inet:getaddr(Localhost, inet6)),
- io:format("~s ~p~n", [Localhost,Localaddr]),
+ Localaddr = ok(get_localaddr()),
S2 = ok(gen_tcp:listen(0, [{ip,Localaddr}])),
implicit_inet6(S2, Localaddr),
ok = gen_tcp:close(S2),
@@ -369,8 +367,21 @@ unused_ip(A, B, C, D) ->
{error, _} -> {ok, {A, B, C, D}}
end.
-ok({ok,V}) -> V.
+get_localaddr() ->
+ get_localaddr(["localhost", "localhost6", "ip6-localhost"]).
+
+get_localaddr([]) ->
+ {error, localaddr_not_found};
+get_localaddr([Localhost|Ls]) ->
+ case inet:getaddr(Localhost, inet6) of
+ {ok, LocalAddr} ->
+ io:format("~s ~p~n", [Localhost, LocalAddr]),
+ {ok, LocalAddr};
+ _ ->
+ get_localaddr(Ls)
+ end.
+ok({ok,V}) -> V.
getsockfd() -> undefined.
closesockfd(_FD) -> undefined.
diff --git a/lib/kernel/test/gen_udp_SUITE.erl b/lib/kernel/test/gen_udp_SUITE.erl
index 44539bf44c..bc5bf02456 100644
--- a/lib/kernel/test/gen_udp_SUITE.erl
+++ b/lib/kernel/test/gen_udp_SUITE.erl
@@ -599,9 +599,7 @@ implicit_inet6(Host, Addr) ->
implicit_inet6(S1, Active, Loopback),
ok = gen_udp:close(S1),
%%
- Localhost = "localhost",
- Localaddr = ok(inet:getaddr(Localhost, inet6)),
- io:format("~s ~p~n", [Localhost,Localaddr]),
+ Localaddr = ok(get_localaddr()),
S2 = ok(gen_udp:open(0, [{ip,Localaddr},Active])),
implicit_inet6(S2, Active, Localaddr),
ok = gen_udp:close(S2),
@@ -630,4 +628,18 @@ implicit_inet6(S1, Active, Addr) ->
{Addr,P2,"pong"} = ok(gen_udp:recv(S1, 1024)),
ok = gen_udp:close(S2).
+get_localaddr() ->
+ get_localaddr(["localhost", "localhost6", "ip6-localhost"]).
+
+get_localaddr([]) ->
+ {error, localaddr_not_found};
+get_localaddr([Localhost|Ls]) ->
+ case inet:getaddr(Localhost, inet6) of
+ {ok, LocalAddr} ->
+ io:format("~s ~p~n", [Localhost, LocalAddr]),
+ {ok, LocalAddr};
+ _ ->
+ get_localaddr(Ls)
+ end.
+
ok({ok,V}) -> V.