anchor.diff:  
   
   %%--------------------------------------------------------------------
  -%% Function: sortsrv/2
  -%% Description: Walk through a list of srventry records or {error, R}
  -%%              tuples and sort them according to order and secondly
  -%%              preference. Sort errors last, but put nxdomain errors
  -%%              first of the errors.
  -%% Returns: SRVList
  +%% Function: sortsrv(A, B)
  +%%           A = srventry record()
  +%%           B = srventry record()
  +%% Descrip.: Walk through a list of srventry records or {error, R}
  +%%           tuples and sort them according to order and secondly by
  +%%           weight. Sort errors last, but put nxdomain errors first
  +%%           of the errors.
  +%% Returns : list() of srventry record()
   %%--------------------------------------------------------------------
   sortsrv(A, B) when record(A, srventry), record(B, srventry) ->
  -    {Order1, Preference1, Port1, Host1} = A#srventry.dnsrrdata,
  -    {Order2, Preference2, Port2, Host2} = B#srventry.dnsrrdata,
  +    {Order1, Weight1, Port1, Host1} = A#srventry.dnsrrdata,
  +    {Order2, Weight2, Port2, Host2} = B#srventry.dnsrrdata,
       if
   	Order1 < Order2 ->
   	    true;
   	Order1 == Order2 ->
   	    if
  -		Preference1 < Preference2 ->
  +		Weight1 > Weight2 ->
  +		    %% XXX Verify this sort order!
   		    true;
  -		Preference1 == Preference2 ->
  +		Weight1 == Weight2 ->
   		    %% This string sorting is just to make the process deterministic
   		    %% so that a stateless proxy always chooses the same destination
   		    Str1 = Host1 ++ ":" ++ integer_to_list(Port1),
  
positive.code: -include_lib("kernel/src/inet_dns.hrl").
  
  %% For debugging
  -compile(export_all).
  
  %% These records is entirely internal to this module
  -record(srventry, {proto, dnsrrdata}).
  
negative.code: 		       "compatible lookup for SIP SRV records under that domain name", [Domain]),
  	    TCP = srvlookup(tcp, "_sip._tcp." ++ Domain),
  	    UDP = srvlookup(udp, "_sip._udp." ++ Domain),
  	    TLS = srvlookup(tls, "_sips._tcp." ++ Domain),
  	    R = combine_srvresults(lists:sort(fun sortsrv/2, lists:flatten([TCP, UDP, TLS]))),
  	    logger:log(debug, "Resolver: Result of RFC2543 compatible SIP SRV query for domain ~p :~n~p",
  		       [Domain, R]),
  	    R;
  	Res ->
  	    %% siplookup_naptr does it's own sorting
  	    combine_srvresults(Res)
  