anchor.diff:      logger:log(error, "Siprequest: send_to_available_dst called with illegal dst ~p", [Dst]),
       send_to_available_dst(DstT, Request, ViaParam, SrvTHandler).
   
  -dst2str(Dst) when record(Dst, sipdst) ->
  -    lists:flatten(io_lib:format("~p:~s:~p (~s)", [Dst#sipdst.proto, Dst#sipdst.addr, Dst#sipdst.port,
  -						  sipurl:print(Dst#sipdst.uri)])).
   
   proxy_check_maxforwards(Header) ->
       MaxForwards =
  
positive.code:     Line1 = "SIP/2.0 " ++ integer_to_list(Status) ++ " " ++ Reason,
      Header = fix_content_length(HeaderIn, Body),
      Message = lists:flatten(Line1 ++ "\r\n" ++ sipheader:build_header(Header) ++ "\r\n" ++ Body),
      case get_response_destination(TopVia) of
  	{SendToHost, SendProto} ->
  	    {DestPort, Parameters} = {TopVia#via.port, TopVia#via.param},
  	    ParamDict = sipheader:param_to_dict(Parameters),
  	    Port = case dict:find("rport", ParamDict) of
  		       {ok, []} ->
  			   %% This must be an error response generated before the rport fix-up. Ignore rport.
  			   list_to_integer(default_port(SendProto, DestPort));
  		       {ok, Rport} ->
  			   list_to_integer(Rport);
  		       _ ->
  			   list_to_integer(default_port(SendProto, DestPort))
  		   end,
  	    case get_response_socket(DefaultSocket, SendProto, SendToHost, Port) of
  		SendSocket when record(SendSocket, sipsocket) ->
  		    CPid = SendSocket#sipsocket.pid,
  		    logger:log(debug, "send response(top Via: ~s, send to=~p:~s:~p (using ~p)) :~n~s~n",
  			       [sipheader:via_print([TopVia]), SendProto, SendToHost, Port, CPid, Message]),
  		    case sipsocket:send(SendSocket, SendProto, SendToHost, Port, Message) of
  			ok ->
  			    ok;
  			{error, E} ->
  			    logger:log(error, "Failed sending response to ~s:~p using socket ~p, error ~p",
  				       [SendToHost, Port, SendSocket, E]),
  			    {senderror, E}
  		    end;
  		{error, E} ->
  		    logger:log(error, "Failed to get socket to send response to ~s:~p, error ~p, response :~n~s~n",
  			       [SendToHost, Port, E, Message]),
  		    {senderror, "Could not get socket"}
  	    end;
  	_ ->
  	    {senderror, "Failed finding destination"}
      end.
  
  %%--------------------------------------------------------------------
  %% Function: get_response_destination/1
  %% Description: Argument is the top Via header in a response, this
  %%              function extracts the destination and protocol we
  %%              should use.
  %% Returns: {Address, Proto} | error
  %%
  %%   Address is a string that might be IPv4 address (from received=),
  %%   IPv6 address (from received=), or whatever was in the host part
  %%   of the Via.
  %%
  %%   Proto is an atom, tcp|udp|tcp6|udp6|tls|tls6.
  %%--------------------------------------------------------------------
  get_response_destination(TopVia) when record(TopVia, via) ->
      {Protocol, Host, Parameters} = {TopVia#via.proto, TopVia#via.host, TopVia#via.param},
      ParamDict = sipheader:param_to_dict(Parameters),
      Proto = sipsocket:viaproto2proto(Protocol),
      case dict:find("received", ParamDict) of
  	{ok, Received} ->
  	    case address_to_address_and_proto(Received, Proto) of
  		{error, E1} ->
  		    logger:log(debug, "Warning: Malformed received= parameter (~p) : ~p", [E1, Received]),
  		    %% received= parameter not usable, try host part of Via instead
  		    %% XXX try to resolve host part of Via if necessary
  		    case address_to_address_and_proto(Host, Proto) of
  			{error, E2} ->
  			    logger:log(debug, "Warning: Invalid host part of Via (~p) : ~p", [E1, Host]),
  			    logger:log(error, "Failed getting a response destination out of Via : ~p", [TopVia]),
  			    error;
  			R ->
  			    R
  		    end;
  		R ->
  		    R
  	    end;
  	Res ->
  	    %% There was no received= parameter. Do the same checks but on the Via
  	    %% hostname (which is then almost certainly an IP-address).
  	    case address_to_address_and_proto(Host, Proto) of
  		{error, E3} ->
  		    logger:log(debug, "Warning: No received= and invalid host part of Via (~p) : ~p", [E3, Host]),
  		    logger:log(error, "Failed getting a response destination out of Via : ~p", [TopVia]),
  		    error;
  		R ->
  		    R
  	    end
      end.
  
  get_response_socket(DefaultSocket, SendProto, SendToHost, Port) when integer(Port) ->
  
negative.code:     integer_to_list(Port);
  default_port(_, Port) ->
      Port.
  
  %% Function: process_route_header/2
  %% Description: Looks at the Route header. If it exists, we return a
  