aboutsummaryrefslogtreecommitdiffstats
path: root/lib/kernel/test/inet_SUITE.erl
diff options
context:
space:
mode:
Diffstat (limited to 'lib/kernel/test/inet_SUITE.erl')
-rw-r--r--lib/kernel/test/inet_SUITE.erl117
1 files changed, 64 insertions, 53 deletions
diff --git a/lib/kernel/test/inet_SUITE.erl b/lib/kernel/test/inet_SUITE.erl
index c93b10fa1c..f60c13d2e3 100644
--- a/lib/kernel/test/inet_SUITE.erl
+++ b/lib/kernel/test/inet_SUITE.erl
@@ -139,11 +139,13 @@ t_gethostbyaddr(Config) when is_list(Config) ->
ok;
_ ->
io:format("alias list: ~p", [HEnt#hostent.h_aliases]),
- io:format("check alias list: ~p", [[Aliases,[Rname]]]),
+ io:format(
+ "check alias list: ~p", [[Aliases,tl(Aliases),[Rname]]]),
io:format("name: ~p", [HEnt#hostent.h_name]),
io:format("check name: ~p", [[Name,FullName]]),
- check_elems([{HEnt#hostent.h_name,[Name,FullName]},
- {HEnt#hostent.h_aliases,[[],Aliases,[Rname]]}])
+ check_elems(
+ [{HEnt#hostent.h_name,[Name,FullName]},
+ {HEnt#hostent.h_aliases,[[],Aliases,tl(Aliases),[Rname]]}])
end,
{_DName, _DFullName, DIPStr, DIP, _, _, _} = ct:get_config(test_dummy_host),
@@ -171,8 +173,9 @@ t_gethostbyaddr_v6(Config) when is_list(Config) ->
h_length = 16,
h_addr_list = [IP6]},
HEnt6_ = HEnt6,
- check_elems([{HEnt6#hostent.h_name,[Name6,FullName6]},
- {HEnt6#hostent.h_aliases,[[],Aliases6]}]),
+ check_elems(
+ [{HEnt6#hostent.h_name,[Name6,FullName6]},
+ {HEnt6#hostent.h_aliases,[[],Aliases6,tl(Aliases6)]}]),
{_DName6, _DFullName6, DIPStr6, DIP6, _} =
ct:get_config(test_dummy_ipv6_host),
@@ -195,14 +198,14 @@ t_gethostbyname(Config) when is_list(Config) ->
HEnt_ = HEnt,
check_elems([{HEnt#hostent.h_name,[Name,FullName]},
- {HEnt#hostent.h_aliases,[[],Aliases]}]),
+ {HEnt#hostent.h_aliases,[[],Aliases,tl(Aliases)]}]),
{ok,HEntF} = inet:gethostbyname(FullName),
HEntF_ = HEntF#hostent{h_name = FullName,
h_addrtype = inet,
h_length = 4,
h_addr_list = [IP]},
HEntF_ = HEntF,
- check_elems([{HEnt#hostent.h_aliases,[[],Aliases]}]),
+ check_elems([{HEnt#hostent.h_aliases,[[],Aliases,tl(Aliases)]}]),
%%
FullNameU = toupper(FullName),
{ok,HEntU} = inet:gethostbyname(FullNameU),
@@ -237,7 +240,7 @@ t_gethostbyname_v6(Config) when is_list(Config) ->
h_length = 16} = HEnt,
check_elems(
[{HEnt#hostent.h_name,[Name,FullName]},
- {HEnt#hostent.h_aliases,[[],Aliases]}]);
+ {HEnt#hostent.h_aliases,[[],Aliases,tl(Aliases)]}]);
[IP46] -> % IPv4 compatible address
{ok,HEnt4} = inet:gethostbyname(Name, inet),
#hostent{h_addrtype = inet,
@@ -257,7 +260,7 @@ t_gethostbyname_v6(Config) when is_list(Config) ->
h_addrtype = inet6,
h_length = 16} = HEntF,
check_elems(
- [{HEnt#hostent.h_aliases,[[],Aliases]}]);
+ [{HEnt#hostent.h_aliases,[[],Aliases,tl(Aliases)]}]);
[IP46F] -> % IPv4 compatible address
{ok,HEnt4F} = inet:gethostbyname(FullName, inet),
#hostent{h_addrtype = inet,
@@ -363,7 +366,7 @@ ipv4_to_ipv6(Config) when is_list(Config) ->
h_addr_list = [IP_46]},
HEnt_ = HEnt,
check_elems([{HEnt#hostent.h_name,[IP_46_Str,IPStr]},
- {HEnt#hostent.h_aliases,[[],Aliases]}]);
+ {HEnt#hostent.h_aliases,[[],Aliases,tl(Aliases)]}]);
{_,IP4to6Res} -> ok
end,
ok.
@@ -1002,12 +1005,12 @@ getifaddrs(Config) when is_list (Config) ->
[check_addr(Addr) || Addr <- Addrs],
ok.
-check_addr(Addr)
+check_addr({addr,Addr})
when tuple_size(Addr) =:= 8,
element(1, Addr) band 16#FFC0 =:= 16#FE80 ->
io:format("Addr: ~p link local; SKIPPED!~n", [Addr]),
ok;
-check_addr(Addr) ->
+check_addr({addr,Addr}) ->
io:format("Addr: ~p.~n", [Addr]),
Ping = "ping",
Pong = "pong",
@@ -1021,74 +1024,82 @@ check_addr(Addr) ->
ok = gen_tcp:close(S1),
{ok,Pong} = gen_tcp:recv(S2, length(Pong)),
ok = gen_tcp:close(S2),
- ok = gen_tcp:close(L),
- ok.
+ ok = gen_tcp:close(L).
-record(ifopts, {name,flags,addrs=[],hwaddr}).
ifaddrs([]) -> [];
ifaddrs([{If,Opts}|IOs]) ->
- #ifopts{flags=Flags} = Ifopts =
- check_ifopts(Opts, #ifopts{name=If}),
- case Flags =/= undefined andalso lists:member(up, Flags) of
- true ->
- Ifopts#ifopts.addrs;
- false ->
- []
- end++ifaddrs(IOs).
+ #ifopts{flags=F} = Ifopts = check_ifopts(Opts, #ifopts{name=If}),
+ case F of
+ {flags,Flags} ->
+ case lists:member(up, Flags) of
+ true ->
+ Ifopts#ifopts.addrs;
+ false ->
+ []
+ end ++ ifaddrs(IOs);
+ undefined ->
+ ifaddrs(IOs)
+ end.
-check_ifopts([], #ifopts{name=If,flags=Flags,addrs=Raddrs}=Ifopts) ->
+check_ifopts([], #ifopts{flags=F,addrs=Raddrs}=Ifopts) ->
Addrs = lists:reverse(Raddrs),
R = Ifopts#ifopts{addrs=Addrs},
io:format("~p.~n", [R]),
%% See how we did...
- if is_list(Flags) -> ok;
- true ->
- ct:fail({flags_undefined,If})
- end,
+ {flags,Flags} = F,
case lists:member(broadcast, Flags) of
true ->
[case A of
- {_,_,_} -> A;
- {T,_} when tuple_size(T) =:= 8 -> A;
- _ ->
- ct:fail({broaddr_missing,If,A})
+ {{addr,_},{netmask,_},{broadaddr,_}} ->
+ A;
+ {{addr,T},{netmask,_}} when tuple_size(T) =:= 8 ->
+ A
end || A <- Addrs];
false ->
- [case A of {_,_} -> A;
- _ ->
- ct:fail({should_have_netmask,If,A})
- end || A <- Addrs]
+ case lists:member(pointtopoint, Flags) of
+ true ->
+ [case A of
+ {{addr,_},{netmask,_},{dstaddr,_}} ->
+ A
+ end || A <- Addrs];
+ false ->
+ [case A of
+ {{addr,_},{netmask,_}} ->
+ A
+ end || A <- Addrs]
+ end
end,
R;
-check_ifopts([{flags,Flags}|Opts], #ifopts{flags=undefined}=Ifopts) ->
- check_ifopts(Opts, Ifopts#ifopts{flags=Flags});
-check_ifopts([{flags,Fs}|Opts], #ifopts{flags=Flags}=Ifopts) ->
- case Fs of
+check_ifopts([{flags,_}=F|Opts], #ifopts{flags=undefined}=Ifopts) ->
+ check_ifopts(Opts, Ifopts#ifopts{flags=F});
+check_ifopts([{flags,_}=F|Opts], #ifopts{flags=Flags}=Ifopts) ->
+ case F of
Flags ->
- check_ifopts(Opts, Ifopts#ifopts{});
+ check_ifopts(Opts, Ifopts);
_ ->
- ct:fail({multiple_flags,Fs,Ifopts})
+ ct:fail({multiple_flags,F,Ifopts})
end;
check_ifopts(
- [{addr,Addr},{netmask,Netmask},{broadaddr,Broadaddr}|Opts],
+ [{addr,_}=A,{netmask,_}=N,{dstaddr,_}=D|Opts],
#ifopts{addrs=Addrs}=Ifopts) ->
- check_ifopts(Opts, Ifopts#ifopts{addrs=[{Addr,Netmask,Broadaddr}|Addrs]});
+ check_ifopts(Opts, Ifopts#ifopts{addrs=[{A,N,D}|Addrs]});
check_ifopts(
- [{addr,Addr},{netmask,Netmask},{dstaddr,_}|Opts],
+ [{addr,_}=A,{netmask,_}=N,{broadaddr,_}=B|Opts],
#ifopts{addrs=Addrs}=Ifopts) ->
- check_ifopts(Opts, Ifopts#ifopts{addrs=[{Addr,Netmask}|Addrs]});
+ check_ifopts(Opts, Ifopts#ifopts{addrs=[{A,N,B}|Addrs]});
check_ifopts(
- [{addr,Addr},{netmask,Netmask}|Opts],
+ [{addr,_}=A,{netmask,_}=N|Opts],
#ifopts{addrs=Addrs}=Ifopts) ->
- check_ifopts(Opts, Ifopts#ifopts{addrs=[{Addr,Netmask}|Addrs]});
-check_ifopts([{addr,Addr}|Opts], #ifopts{addrs=Addrs}=Ifopts) ->
- check_ifopts(Opts, Ifopts#ifopts{addrs=[{Addr}|Addrs]});
-check_ifopts([{hwaddr,Hwaddr}|Opts], #ifopts{hwaddr=undefined}=Ifopts)
+ check_ifopts(Opts, Ifopts#ifopts{addrs=[{A,N}|Addrs]});
+check_ifopts([{addr,_}=A|Opts], #ifopts{addrs=Addrs}=Ifopts) ->
+ check_ifopts(Opts, Ifopts#ifopts{addrs=[{A}|Addrs]});
+check_ifopts([{hwaddr,Hwaddr}=H|Opts], #ifopts{hwaddr=undefined}=Ifopts)
when is_list(Hwaddr) ->
- check_ifopts(Opts, Ifopts#ifopts{hwaddr=Hwaddr});
-check_ifopts([{hwaddr,HwAddr}|_], #ifopts{}=Ifopts) ->
- ct:fail({multiple_hwaddrs,HwAddr,Ifopts}).
+ check_ifopts(Opts, Ifopts#ifopts{hwaddr=H});
+check_ifopts([{hwaddr,_}=H|_], #ifopts{}=Ifopts) ->
+ ct:fail({multiple_hwaddrs,H,Ifopts}).
%% Works just like lists:member/2, except that any {127,_,_,_} tuple
%% matches any other {127,_,_,_}. We do this to handle Linux systems