anchor.diff:      #via{proto=ViaProto, host=Hostname, port=Port, param=Parameters}.
   
   %%--------------------------------------------------------------------
  +%% Function: add_record_route(URL, Header)
  +%%           URL    = sipurl record(), original Request-URI
  +%%           Header = keylist record()
  +%% Descrip.: Prepend a Record-Route header for this proxy, based on
  +%%           the original Request-URI, to Header.
  +%% Returns : NewHeader = keylist record()
  +%%--------------------------------------------------------------------
  +add_record_route(URL, Header) when is_record(URL, sipurl) ->
  +    add_record_route(URL#sipurl.proto, undefined, undefined, Header).
  +
  +%%--------------------------------------------------------------------
   %% Function: add_record_route(Proto, Hostname, Port, Header)
   %%           Proto      = "sips" | "sip" | string()
  -%%           Hostname   = string()
  -%%           Port       = integer() | none
  +%%           Hostname   = undefined | string()
  +%%           Port       = undefined | none | integer()
   %%           Header     = keylist record()
   %% Descrip.: Prepend a Record-Route header for Proto:Host:Port to the
   %%           Header keylist.
   %% Returns : NewHeader = keylist record()
   %%--------------------------------------------------------------------
  -add_record_route(Proto, Hostname, Port, Header) when is_list(Proto), is_list(Hostname), is_integer(Port);
  -						     Port == none ->
  -    RouteStr =
  -	case yxa_config:get_env(record_route_url) of
  -	    {ok, RRURL} ->
  -		case {Proto, RRURL#sipurl.proto} of
  -		    {"sips", "sip"} ->
  -			%% Proto is SIPS, but RRURL's Proto is SIP. Upgrade SIP to SIPS.
  -			sipurl:print( sipurl:set([{proto, Proto}], RRURL) );
  -		    _ ->
  -			sipurl:print(RRURL)
  -		end;
  -	    none ->
  -		%% we use 'lr=true' instead of just 'lr' since some SIP stacks are known
  -		%% to require that parameters are of the format 'key=value'.
  -		Param1 = ["lr=true"],
  -		RR_Elems =
  -		    case Port of
  -			none ->
  -			    %% It was requested that we don't include a port number.
  -			    [{proto, Proto}, {host, Hostname}, {param, Param1}];
  -			_ when is_integer(Port) ->
  -			    [{proto, Proto}, {host, Hostname}, {port, Port}, {param, Param1}]
  -		    end,
  -		sipurl:print(sipurl:new(RR_Elems))
  -	end,
  +add_record_route(Proto, Hostname, Port, Header) when is_list(Proto), is_list(Hostname); Hostname == undefined,
  +						     is_integer(Port); Port == none; Port == undefined ->
  +    RouteStr = construct_record_route(Proto, Hostname, Port),
   
       %% Check if our Record-Route (RouteStr) is already present as the first entry of
       %% the Record-Route set in Header.
       AlreadyPresent =
  -	case sipheader:record_route(Header) of
  -	    [FirstRoute | _] when is_record(FirstRoute, contact) ->
  +	case keylist:fetch('record-route', Header) of
  +	    [RouteStr | _] ->
   		%% We only do byte-by-byte matching since the purpose of this check is to
   		%% make sure that this function isn't used twice on a message - not to make sure
   		%% that there is no Record-Route that would resolve to this proxy/UA in there.
  -		case FirstRoute#contact.urlstr of
  -		    RouteStr -> true;
  -		    _ -> false
  -		end;
  +		true;
   	    _ ->
  -		%% No Record-Route in header
  +		%% No Record-Route in header, or not matching ours
   		false
   	end,
       case AlreadyPresent of
  
positive.code: 	 make_answerheader/1,
  	 add_record_route/2,
  	 add_record_route/4,
  	 myhostname/0,
  	 create_via/2,
  	 get_loop_cookie/3,
  
negative.code: 	    logger:log(debug, "Siprequest: NOT adding Record-Route since the first Record-Route matches mine"),
  	    Header;
  	false ->
  	    keylist:prepend({"Record-Route", [RouteStr]}, Header)
      end.
  
  %% Returns : RRStr = string(), URL enclosed in "<>"
  construct_record_route(Proto) when is_list(Proto) ->
      construct_record_route(Proto, undefined, undefined).
  
  construct_record_route(Proto, undefined, undefined) when is_list(Proto) ->
      {RRProto, MyPort} = 
  	case Proto of
  	    "sips" ->
  		{"sips", sipsocket:get_listenport(tls)};
  	    _ ->
  		%% Create sip: Record-Route for everything except SIPS-URIs
  		{"sip", sipsocket:get_listenport(udp)}
  	end,
      URLport = sipsocket:default_port(Proto, none),
      %% If we are listening on the default port for the protocol in URL, we don't
      %% need to set a port in the Record-Route. If not however, we need to set the
      %% port because otherwise Cisco 79xx phones (version 7.5) will put port 5060
  