Permalink
Browse files

tracert: choose the first resolved address

If the resolver returns multiple address for a domain, choose the first.
  • Loading branch information...
1 parent 27942ab commit 045629cea049e99d373063d8b67d5e809220d506 @msantos committed May 19, 2012
Showing with 9 additions and 1 deletion.
  1. +1 −1 src/tracert.erl
  2. +8 −0 test/gen_icmp_tests.erl
View
2 src/tracert.erl
@@ -94,7 +94,7 @@ host(Host, Options) ->
Path.
host(Ref, Host, Options) ->
- {ok, _, [Daddr]} = gen_icmp:parse(Host),
+ {ok, _, [Daddr|_]} = gen_icmp:parse(Host),
State = proplist_to_record(Options),
ok = gen_server:call(Ref, {handler, State#state.handler}, infinity),
trace(Ref, State#state{daddr = Daddr}).
View
8 test/gen_icmp_tests.erl
@@ -89,3 +89,11 @@ traceroute_localhost_test() ->
traceroute_multiple_hops_test() ->
Path = tracert:host({8,8,8,8}),
true = is_list(tracert:path(Path)).
+
+traceroute_resolv_multiple_addresses_test() ->
+ Path = tracert:host("google.com"),
+ true = is_list(tracert:path(Path)).
+
+traceroute_resolv_single_address_test() ->
+ Path = tracert:host("erlang.org"),
+ true = is_list(tracert:path(Path)).

0 comments on commit 045629c

Please sign in to comment.