anchor.diff:  %%           UDP or have to do TCP only.
   %% Returns : list() of sipdst record() | {error, Reason}
   %%--------------------------------------------------------------------
  +url_to_dstlist(URL, ApproxMsgSize) when is_record(URL, sipurl), is_integer(ApproxMsgSize) ->
  +    url_to_dstlist(URL, ApproxMsgSize, URL).
  +
   url_to_dstlist(URL, ApproxMsgSize, ReqURI) when is_record(URL, sipurl), is_integer(ApproxMsgSize),
   						is_record(ReqURI, sipurl) ->
  +    url_to_dstlist(URL, ApproxMsgSize, ReqURI, false).
  +
  +url_to_dstlist(URL, ApproxMsgSize, ReqURI, Test) when is_record(URL, sipurl), is_integer(ApproxMsgSize),
  +						      is_record(ReqURI, sipurl), is_boolean(Test) ->
       case url_param:find(URL#sipurl.param_pairs, "maddr") of
   	[MAddr] ->
   	    %% RFC3261 #16.5 (Determining Request Targets) says that we MUST use maddr if
   	    %% it is set. We do that carefully by checking that it is usable and falling
   	    %% back to non-maddr routing if it is not.
   	    logger:log(debug, "url_to_dstlist: URL has maddr parameter, trying to make use of it"),
  -	    NewURL = sipurl:set([{host, MAddr}], URL),
  -	    case url_to_dstlist_not_maddr(NewURL, ApproxMsgSize, ReqURI) of
  -		{error, _Reason} ->
  -		    logger:log(normal, "Warning: Unusable 'maddr' parameter in URI ~p, ignoring",
  -			       [sipurl:print(URL)]),
  -		    url_to_dstlist_not_maddr(URL, ApproxMsgSize, ReqURI);
  +	    MAddrURL = sipurl:set([{host, MAddr}], URL),
  +	    case url_to_dstlist2(MAddrURL, ApproxMsgSize, ReqURI, Test) of
  +		{error, Reason} ->
  +		    logger:log(normal, "Warning: Unusable 'maddr' parameter in URI ~p, ignoring : ~p",
  +			       [sipurl:print(URL), Reason]),
  +		    url_to_dstlist2(URL, ApproxMsgSize, ReqURI, Test);
   		L when is_list(L) ->
   		    L
   	    end;
   	_ ->
  -	    url_to_dstlist_not_maddr(URL, ApproxMsgSize, ReqURI)
  +	    url_to_dstlist2(URL, ApproxMsgSize, ReqURI, Test)
       end.
   
   %%--------------------------------------------------------------------
  -%% Function: url_to_dstlist_not_maddr(URL, ApproxMsgSize, ReqURI)
  +%% Function: url_to_dstlist2(URL, ApproxMsgSize, ReqURI, Test)
   %%           URL           = sipurl record(), the destination we
   %%                           should resolve
   %%           ApproxMsgSize = integer()
  -%%           ReqURI        = sipurl record(), the Request-URI to use
  +%%           ReqURI_in     = sipurl record(), the Request-URI to use
   %%                           when sending a request to this transport-
   %%                           layer destination
  +%%           Test          = bool(), testing or not?
   %% Descrip.: Make a list of sipdst records from an URL. We need the
   %%           approximate message size to determine if we can use
   %%           UDP or have to do TCP only.
   %% Returns : list() of sipdst record() | {error, Reason}
   %%--------------------------------------------------------------------
  -url_to_dstlist_not_maddr(URL, ApproxMsgSize, ReqURI) when is_record(URL, sipurl), is_integer(ApproxMsgSize),
  -							  is_record(ReqURI, sipurl) ->
  +url_to_dstlist2(URL, ApproxMsgSize, ReqURI_in, Test) when is_record(URL, sipurl), is_integer(ApproxMsgSize),
  +                                                          is_record(ReqURI_in, sipurl) ->
  +    DstList = url_to_dstlist3(URL, ApproxMsgSize, ReqURI_in, Test),
  +
  +    %% For SIPS URI, we MUST remove any destination that is not TLS or known to be
  +    %% protected through some TLS equivalent mechanism (like IPsec). We should never
  +    %% end up with any non-TLS destinations for a SIPS URL, but we play it safe here.
  +    case (URL#sipurl.proto == "sips") of
  +	true ->
  +	    remove_non_tls_destinations(DstList);
  +	false ->
  +	    DstList
  +    end.
  +
  +url_to_dstlist3(URL, ApproxMsgSize, ReqURI_in, Test) when is_record(URL, sipurl), is_integer(ApproxMsgSize),
  +							  is_record(ReqURI_in, sipurl) ->
  +    %% Upgrade ReqURI to SIPS if URL is SIPS
  +    ReqURI =
  +	case {URL#sipurl.proto, ReqURI_in#sipurl.proto} of
  +	    {"sips", "sip"} -> sipurl:set([{proto, "sips"}], ReqURI_in);
  +	    {"sips", "sips"} -> ReqURI_in;
  +	    {"sips", _} ->
  +		Msg = io_lib:format("Can't upgrade unknown protocol ~p to SIPS", [ReqURI_in#sipurl.proto]),
  +		erlang:error({error, lists:flatten(Msg)});
  +	    _ ->
  +		ReqURI_in
  +	end,
  +
       Host = URL#sipurl.host,
       %% Check if URL host is either IPv4 or IPv6 address.
       %% Note: inet_parse:address/1 is not a supported Erlang/OTP function
  
positive.code: 
  remove_tls_destinations2([], Res) ->
      lists:reverse(Res);
  remove_tls_destinations2([#sipdns_srv{proto=Proto}=H | T], Res) when Proto /= tls, Proto /= tls6 ->
      remove_tls_destinations2(T, [H | Res]);
  remove_tls_destinations2([H | T], Res) when is_record(H, sipdns_srv) ->
      %% Proto is tls or tls6
      {Proto, Host, Port} = {H#sipdns_srv.proto, H#sipdns_srv.host, H#sipdns_srv.port},
      logger:log(debug, "Resolver: Removing TLS destination ~p:~s:~p from result set since "
  	       "experimental TLS is not enabled", [Proto, Host, Port]),
      remove_tls_destinations2(T, Res).
  
  
  %%--------------------------------------------------------------------
  %% Function: remove_non_tls_destinations(In)
  %%           In = list() of sipdns_srv record()
  %% Descrip.: Remove all records NOT having proto 'tls' | tls6 from In,
  %%           and return a new list() of sipdns_srv record().
  %% Returns : DstList = list() of sipdns_srv record()
  %%--------------------------------------------------------------------
  remove_non_tls_destinations(In) ->
      case remove_non_tls_destinations2(In, 0, []) of
  
negative.code:     [Dst1, Dst2_2] =
  	make_sipdst_from_hostport(tcp, URL, ["ssl1"], [HostPort1, HostPort2]),
  
      autotest:mark(?LINE, "make_sipdst_from_hostport/3 - 4"),
      %% SSL names
      HostPortL_4 = [#sipdns_hostport{family = inet, addr="secure", port=90}],
      [#sipdst{proto = tls,
  	     addr  = "secure",
  	     port  = 90,
  	     uri   = URL,
  	     ssl_names = ["secure", "test"]
  	    }] = make_sipdst_from_hostport(tls, URL, ["secure", "test"], HostPortL_4),
  
      autotest:mark(?LINE, "make_sipdst_from_hostport/3 - 5"),
      HostPortL_5 = [#sipdns_hostport{family = inet6, addr="test6", port = 1}],
      %% Make sure we turn proto into v6 variants like we should
      [#sipdst{proto = tcp6}] = make_sipdst_from_hostport(tcp, URL, [], HostPortL_5),
      [#sipdst{proto = udp6}] = make_sipdst_from_hostport(udp, URL, [], HostPortL_5),
      [#sipdst{proto = tls6}] = make_sipdst_from_hostport(tls, URL, [], HostPortL_5),
      [#sipdst{proto = yxa_test6}] = make_sipdst_from_hostport(yxa_test, URL, [], HostPortL_5),
  
  
      %% test get_response_host_proto(TopVia)
      %% NOTE: We can currently only test with IPv4 addresses since IPv6 is
      %% off by default, so when the tests are run enable_v6 might not be
      %% 'true'.
      %%--------------------------------------------------------------------
      GetVia = fun(ViaStr) -> 
  		     [Res] = sipheader:via([ViaStr]),
  		     Res
  	     end,
  
      autotest:mark(?LINE, "get_response_host_proto/1 - 1"),
      %% straight forward, no received= parameter
      {ok, "192.0.2.1", tcp} = get_response_host_proto(GetVia("SIP/2.0/TCP 192.0.2.1")),
  
      autotest:mark(?LINE, "get_response_host_proto/1 - 2"),
      %% straight forward, address in received= parameter
      {ok, "192.0.2.1", tcp} = get_response_host_proto(GetVia("SIP/2.0/TCP phone.example.org;received=192.0.2.1")),
  
      autotest:mark(?LINE, "get_response_host_proto/1 - 3"),
      %% error, hostname in Via host and no received= parameter
      error = get_response_host_proto(GetVia("SIP/2.0/TCP phone.example.org")),
  
      autotest:mark(?LINE, "get_response_host_proto/1 - 4"),
      %% invalid received= parameter, but luckily valid IP address in Via host
      put(dnsutil_test_res, [{{get_ip_port, "X", none}, {error, timeout}}]),
      {ok, "192.0.2.1", tls} = get_response_host_proto(GetVia("SIP/2.0/TLS 192.0.2.1;received=X")),
  
      autotest:mark(?LINE, "get_response_host_proto/1 - 5"),
      %% test with invalid received= parameter, and hostname not found in DNS
      put(dnsutil_test_res, [{{get_ip_port, "X", none},			{error, timeout}},
  			   {{get_ip_port, "test.example.com", none},	{error, nomatch}}]),
      error = get_response_host_proto(GetVia("SIP/2.0/TLS test.example.com;received=X")),
  
  
      %% test get_response_destination(TopVia)
      %%--------------------------------------------------------------------
      autotest:mark(?LINE, "get_response_destination/1 - 1"),
      %% test normal case, no port
      #sipdst{proto = tls,
  	    addr  = "192.0.2.1",
  	    port  = 5061
  	    } =
  	get_response_destination(GetVia("SIP/2.0/TLS example.com;received=192.0.2.1")),
  
      autotest:mark(?LINE, "get_response_destination/1 - 2"),
      %% test non-default port
      #sipdst{proto = tcp,
  	    addr  = "192.0.2.1",
  	    port  = 5012
  	    } =
  	get_response_destination(GetVia("SIP/2.0/TCP example.com:5012;received=192.0.2.1")),
  
      autotest:mark(?LINE, "get_response_destination/1 - 3"),
      %% test rport specified
      #sipdst{proto = tcp,
  	    addr  = "192.0.2.1",
  	    port  = 50121
  	    } =
  	get_response_destination(GetVia("SIP/2.0/TCP example.com:5012;rport=50121;received=192.0.2.1")),
  
      autotest:mark(?LINE, "get_response_destination/1 - 4"),
      %% test rport requested but apparently not filled in (should go to default port)
      #sipdst{proto = udp,
  	    addr  = "192.0.2.1",
  	    port  = 5060
  	    } =
  	get_response_destination(GetVia("SIP/2.0/UDP example.com;rport;received=192.0.2.1")),
  
      autotest:mark(?LINE, "get_response_destination/1 - 5"),
      %% test with invalid hostname and no received
      put(dnsutil_test_res, [{{get_ip_port, "example.com", none}, {error, timeout}}]),
      error = get_response_destination(GetVia("SIP/2.0/UDP example.com")),
  
  
      %% test format_siplookup_result(InPort, ReqURI, SSLHost, DstList, Test)
      %%--------------------------------------------------------------------
      autotest:mark(?LINE, "format_siplookup_result/5 - 1"),
      %% InPort 'none', use the one from DNS
      SRV3 = #sipdns_srv{proto=tcp, host="192.0.2.1", port=1234},
      Dst3 = #sipdst{proto=tcp, addr="192.0.2.1", port=1234, uri=URL, ssl_names=[]},
      [Dst3] = format_siplookup_result(none, URL, "192.0.2.1", [SRV3], NotTesting),
  
      autotest:mark(?LINE, "format_siplookup_result/5 - 2"),
      %% InPort 2345, overrides the one in DNS (1234 in Tuple3)
      Dst4 = #sipdst{proto=tcp, addr="192.0.2.1", port=2345, uri=URL, ssl_names=[]},
      [Dst4] = format_siplookup_result(2345, URL, undefined, [SRV3], NotTesting),
  
      autotest:mark(?LINE, "format_siplookup_result/5 - 3"),
      SRV5 = #sipdns_srv{proto=tcp, host="192.0.2.2", port=5065},
      Dst5 = #sipdst{proto=tcp, addr="192.0.2.2", port=5065, uri=URL, ssl_names=[]},
      %% more than one tuple in
      [Dst3, Dst5] = format_siplookup_result(none, URL, undefined, [SRV3, SRV5], NotTesting),
  
      %% test format_siplookup_result2(InPort, ReqURI, SSLNames, SSL_AddHost, DstList, Test)
      %%--------------------------------------------------------------------
      autotest:mark(?LINE, "format_siplookup_result2/6 - 1"),
      %% test with hostnames, InPort present and SSL_AddHost set
      FSR2_URL_1 = sipurl:parse("sip:u@example.com"),
      FSR2_DNS_1 = [{{get_ip_port, "test.example.com", 100},
  		   [#sipdns_hostport{family = inet,
  				     addr   = "192.0.2.2",
  				     port   = 99
  				    }]
  		  },
  		  {{get_ip_port, "ssl.example.com", 100},
  		   [#sipdns_hostport{family = inet,
  				     addr   = "192.0.2.3",
  				     port   = 99
  				    }]
  		  }],
      put(dnsutil_test_res, FSR2_DNS_1),
      FSR2_SrvList1 = [#sipdns_srv{proto = udp, host = "test.example.com", port = 99},
  		     #sipdns_srv{proto = tls, host = "ssl.example.com", port = 99}],
      [#sipdst{proto	= udp,
  	     addr	= "192.0.2.2",
  	     port	= 99,
  	     uri	= FSR2_URL_1,
  	     ssl_names	= []
  	    },
       #sipdst{proto	= tls,
  	     addr	= "192.0.2.3",
  	     port	= 99,
  	     uri	= FSR2_URL_1,
  	     ssl_names	= ["example.com", "ssl.example.com"]
  	    }] =
  	format_siplookup_result(100, FSR2_URL_1, "example.com", FSR2_SrvList1, Testing),
  
      autotest:mark(?LINE, "format_siplookup_result2/6 - 2"),
      %% test with hostnames, InPort present and SSL_AddHost set
      FSR2_URL_1 = sipurl:parse("sip:u@example.com"),
      FSR2_DNS_2 = [{{get_ip_port, "test.example.com", 5060},
  		   [#sipdns_hostport{family = inet,
  				     addr   = "192.0.2.2",
  				     port   = 5060
  				    }]
  		  },
  		  {{get_ip_port, "ssl.example.com", 5061},
  		   [#sipdns_hostport{family = inet,
  				     addr   = "192.0.2.3",
  				     port   = 5061
  				    }]
  		  }],
      put(dnsutil_test_res, FSR2_DNS_2),
      FSR2_SrvList2 = [#sipdns_srv{proto = udp, host = "test.example.com", port = 5060},
  		     #sipdns_srv{proto = tls, host = "ssl.example.com", port = 5061}],
      [#sipdst{proto	= udp,
  	     addr	= "192.0.2.2",
  	     port	= 5060,
  	     uri	= FSR2_URL_1,
  	     ssl_names	= []
  	    },
       #sipdst{proto	= tls,
  	     addr	= "192.0.2.3",
  	     port	= 5061,
  	     uri	= FSR2_URL_1,
  	     ssl_names	= ["example.com", "ssl.example.com"]
  	    }] =
  	format_siplookup_result(none, FSR2_URL_1, "example.com", FSR2_SrvList2, Testing),
  
      %% test combine_host_portres(In)
      %%--------------------------------------------------------------------
  