anchor.diff:  	    false
       end;
   %% SRV record always beats error
  -sortsrv({SipProto, {Order, Preference, Port, Host}}, {error, _}) ->
  +sortsrv(A, {error, _}) when record(A, srventry) ->
       true;
   %% SRV record always beats error
  -sortsrv({error, _}, {SipProto, {Order, Preference, Port, Host}}) ->
  +sortsrv({error, _}, B) when record(B, srventry)->
       false;
   %% NXDOMAIN always beats other errors
   sortsrv({error, nxdomain}, {error, _}) ->
  
positive.code: -export([siplookup/1, enumlookup/1, enumlookup/2, get_ip_port/2]).
  
  -include("inet_dns.hrl").
  
  srvlookup(Proto, Name) ->
      case inet_res:nslookup(Name, in, srv) of
  	{ok, Rec} ->
  	    ParseSRV = fun(Entry) ->
  			       {Proto, Entry#dns_rr.data}
  			  end,
  	    lists:map(ParseSRV, Rec#dns_rec.anlist);
  	{error, What} ->
  	    logger:log(debug, "dns resolver: Error ~p when resolving ~p IN SRV", [What, Name]),
  	    {error, What}
      end.
  
  siplookup([]) ->
      none;
  siplookup(Domain) ->
      TCP = srvlookup(tcp, "_sip._tcp." ++ Domain),
      UDP = srvlookup(udp, "_sip._udp." ++ Domain),
      combine_srvresults(lists:sort(fun sortsrv/2, lists:flatten([TCP, UDP]))).
  
  combine_srvresults(List) ->
      combine_srvresults(List, [], []).
  
  
negative.code:     logger:log(error, "Resolver: ENUM lookup on non-E.164 number (~p)", [Foo]),
      none.
  
  %%--------------------------------------------------------------------
  %% Function: enumlookup/2
  %% Description: Do ENUM (RFC2916 and 2916bis) lookup on a E.164 number
  %%              in a set of domains. Returns the result of ENUM regexp
  %%              rewrite as a string.
  %% Returns:
  %%--------------------------------------------------------------------
  enumlookup("+" ++ Number, DomainList) ->
      %% XXX remove dashes and spaces etc. from Number
      logger:log(debug, "Resolver: ENUM query for ~p in ~p", ["+" ++ Number, DomainList]),
      L1 = enumalldomains(Number, DomainList),
      %% SIP+E2U is RFC2916 and E2U+SIP is 2916bis
      L2 = lists:append([chooseenum(L1, "SIP+E2U"), chooseenum(L1, "E2U+SIP")]),
      L3 = lists:sort(fun sortenum/2, L2),
      L4 = naptr_regexp(L3),
      applyregexp("+" ++ Number, L4).
  
  
  %%--------------------------------------------------------------------
  %% Function: isnaptr/1
  %% Description: Evaluate if a dns_rr is of type NAPTR or not. To be
  %%              used with lists:filter.
  %% Returns: true  |
  %%          false
  %%--------------------------------------------------------------------
  isnaptr(Entry) when record(Entry, dns_rr) ->
      if
  	Entry#dns_rr.type == ?T_NAPTR ->
  	    true;
  	true ->
  	    false
      end;
  isnaptr(_) ->
      false.
  
  
  %%--------------------------------------------------------------------
  %% Function: naptrlookup/1
  %% Description: Look up and return all NAPTR records for a given DNS
  %%              domain name.
  %% Returns: NAPTRList
  %%--------------------------------------------------------------------
  naptrlookup(Name) ->
      case inet_res:nslookup(Name, in, ?T_NAPTR) of
  	{ok, Rec} ->
  