anchor.diff:  	    lists:nth(1, Hostnames)
       end.
   
  +%% Function: create_via/2
  +%% Description: Create a Via for this proxy, given the protocol.
  +%% Returns: Via
  +%%--------------------------------------------------------------------
  +create_via(Proto, Parameters) ->
  +    Hostname = siprequest:myhostname(),
  +    Port = sipserver:get_listenport(Proto),
  +    ViaProto = sipsocket:proto2viastr(Proto),
  +    #via{proto=ViaProto, host=Hostname, port=Port, param=Parameters}.
  +
   add_record_route(Proto, Hostname, Port, Header) ->
       Param1 = ["maddr=" ++ siphost:myip(), "lr=true"],
       Param2 = case Proto of
  
positive.code: 		{error, E1} ->
  		    logger:log(debug, "Warning: Malformed received= parameter (~p) : ~p", [E1, Received]),
  		    %% received= parameter not usable, try host part of Via instead
  		    case address_to_address_and_proto(Host, Proto) of
  			{error, E2} ->
  			    logger:log(debug, "Warning: Invalid host part of Via (~p) : ~p", [E1, Host]),
  
negative.code: send_auth_req(Header, Socket, Auth, Stale) ->
      ExtraHeaders = [{"WWW-Authenticate",
  		     sipheader:auth_print(Auth, Stale)}],
      Response = #response{status=401, reason="Authentication Required",
  			 header=standardcopy(Header, ExtraHeaders), body=""},
      send_response(Socket, Response).
  
  send_proxyauth_req(Header, Socket, Auth, Stale) ->
      ExtraHeaders = [{"Proxy-Authenticate",
  		     sipheader:auth_print(Auth, Stale)}],
      Response = #response{status=407, reason="Proxy Authentication Required",
                           header=standardcopy(Header, ExtraHeaders), body=""},
      send_response(Socket, Response).
  
  send_redirect(Location, Header, Socket) when record(Location, sipurl) ->
      Contact = [{none, Location}],
      ExtraHeaders = [{"Contact",
  		     sipheader:contact_print(Contact)}],
      Response = #response{status=302, reason="Moved Temporarily",
  			 header=standardcopy(Header, ExtraHeaders), body=""},
      send_response(Socket, Response).
  
  send_notfound(Header, Socket) ->
      Response = #response{status=404, reason="Not found",
  			 header=standardcopy(Header, []), body=""},
      send_response(Socket, Response).
  
  send_notavail(Header, Socket) ->
      %% XXX CHECK THIS! SUSPECT IT SHOULD BE ["180"]
      ExtraHeaders = [{"Retry-After", "180"}],
      Response = #response{status=480, reason="Temporarily unavailable",
                           header=standardcopy(Header, ExtraHeaders), body=""},
      send_response(Socket, Response).
  
  send_answer(Header, Socket, Body) ->
      %% XXX CHECK THIS! SUSPECT IT SHOULD BE ["application/sdp"] AND [integer_to_list(length(Body))]
      ExtraHeaders = [{"Content-Type", "application/sdp"},
  		    {"Content-Length",
  		     integer_to_list(length(Body))}],
      Response = #response{status=200, reason="OK",
  			 header=standardcopy(Header, ExtraHeaders), body=""},
      send_response(Socket, Response).
  
  send_result(RequestHeader, Socket, Body, Status, Reason) ->
      Response = #response{status=Status, reason=Reason,
  			 header=standardcopy(RequestHeader, []), body=Body},
      send_response(Socket, Response).
  
  send_result(RequestHeader, Socket, Body, Status, Reason, ExtraHeaders) ->
      Response = #response{status=Status, reason=Reason,
  			 header=standardcopy(RequestHeader, ExtraHeaders), body=Body},
      send_response(Socket, Response).
  
  send_proxy_response(Socket, Response) when record(Response, response) ->
      case sipheader:via(keylist:fetch("Via", Response#response.header)) of
  	[Self] ->
  	    logger:log(error, "Can't proxy response ~p ~s because it contains just one or less Via and that should be mine!",
  		       [Response#response.status, Response#response.reason]),
  	    {error, invalid_Via};
  	[Self | Via] ->
  	    %% Remove Via matching me (XXX should check that it does)
  	    NewHeader = keylist:set("Via", sipheader:via_print(Via), Response#response.header),
  	    %% Now look for the correct "server transaction" to use when sending this response upstreams
  	    [NextVia | _] = Via,
  	    NewResponse = Response#response{header=NewHeader},
  	    send_response(Socket, NewResponse)
      end.
  
  make_response(Status, Reason, Body, ExtraHeaders, ViaParameters, SipSocket, Request) when record(SipSocket, sipsocket) ->
      make_response(Status, Reason, Body, ExtraHeaders, ViaParameters, SipSocket#sipsocket.proto, Request);
  make_response(Status, Reason, Body, ExtraHeaders, ViaParameters, Proto, Request) when record(Request, request) ->
      ReqHeader = Request#request.header,
      AnswerHeader1 = keylist:appendlist(keylist:copy(ReqHeader, ["Via", "From", "To", "Call-ID", "CSeq",
  								"Record-Route", "Timestamp", "Content-Type"]),
  				       ExtraHeaders),
  