anchor.diff:  combine_srvresults([{error, What} | T], Res, Errors) ->
       combine_srvresults(T, Res, [{error, What} | Errors]);
   combine_srvresults([H | T], Res, Errors) when is_record(H, srventry) ->
  -    {_Order, _Weight, Port, Host} = H#srventry.dnsrrdata,
  -    This = #sipdns_srv{proto=H#srventry.proto, host=Host, port=Port},
  +    This = #sipdns_srv{proto = H#srventry.proto,
  +		       host  = H#srventry.host,
  +		       port  = H#srventry.port
  +		      },
       combine_srvresults(T, [This | Res], Errors).
   
  -
  -%%--------------------------------------------------------------------
  -%% Function: sortsrv(A, B)
  -%%           A = srventry record()
  -%%           B = srventry record()
  +%%--------------------------------------------------------------------
  +%% Function: sort_srvlist(In)
  +%%           In = list() of srventry record() | {error, R} tuple()
   %% 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.
  +%%           of the errors. The weight sorting is proportional for
  +%%           entrys of the same order, not fixed.
   %% Returns : list() of srventry record()
  -%% Note    : XXX weight should be proportional somehow, not just
  -%%           sorted
  -%%--------------------------------------------------------------------
  +%%--------------------------------------------------------------------
  +sort_srvlist(In) when is_list(In) ->
  +    Sorted = lists:sort(fun sortsrv/2, In),
  +    {T1, T2, T3} = erlang:now(),
  +    random:seed(T1, T2, T3),
  +    make_weight_proportional(Sorted).
  +
  +%% part of sort_svrlist, a lists:sort function for SRV records
   sortsrv(A, B) when is_record(A, srventry), is_record(B, srventry) ->
  -    {Order1, Weight1, _Port1, _Host1} = A#srventry.dnsrrdata,
  -    {Order2, Weight2, _Port2, _Host2} = B#srventry.dnsrrdata,
  +    #srventry{order = Order1, weight = Weight1} = A,
  +    #srventry{order = Order2, weight = Weight2} = B,
  +
       if
   	Order1 < Order2 ->
   	    true;
   	Order1 == Order2 ->
  -	    %% XXX weight should be proportional somehow, not just sorted
  +	    %% Weight is really a proportional thing, but we sort on it for the same
  +	    %% order here, to make sortsrv/2 deterministic (for test cases)
   	    if
   		Weight1 > Weight2 ->
   		    true;
  
positive.code: 
      %% test combine_srvresults(In)
      %%--------------------------------------------------------------------
      CombineSRV_1 = #srventry{dnsrrdata = {0, 21, 5060, "example.org"}, proto=tcp},
      CombineSRV_2 = #srventry{dnsrrdata = {0, 21, 5061, "example.net"}, proto=tls},
      CombineSRV_3 = {error, undefined},
  
      autotest:mark(?LINE, "combine_srvresults/1 - 1"),
  
negative.code: %%
  %% Empty regexp
  %%
  naptr_to_srvlist2([#naptrrecord{regexp = ""} = H | T], Res) ->
      Proto = case H#naptrrecord.services of
  		"SIP+D2U"  ++ _ -> udp;
  		"SIP+D2T"  ++ _ -> tcp;
  		"SIPS+D2T" ++ _ -> tls
  	    end,
      %% Regexp should be empty for domain NAPTR - RFC3263 #4.1. The interesting thing is
      %% the replacement. (We make sure the regexp is empty in the function declaration)
      This = srvlookup(Proto, H#naptrrecord.replacement),
      Sorted = sort_srvlist(This),
      naptr_to_srvlist2(T, lists:flatten([Res, Sorted]));
  %%
  %% Non-empty regexp, or not a domain NAPTR - skip
  %%
  naptr_to_srvlist2([H | T], Res) when is_record(H, naptrrecord) ->
      naptr_to_srvlist2(T, Res);
  