Host maddr = via.getMaddr(); String host = null; if (maddr != null) { host = maddr.getHostname(); } else {        host = via.getParameter(Via.RECEIVED); if (host == null) {      host = via.getHost(); } }    HopImpl hop = new HopImpl(host, port, transport); MessageChannel messageChannel = ((SIPTransactionStack) getSIPStack()) .createRawMessageChannel(this.getPort(),hop); messageChannel.sendMessage(transactionResponse); } }
} else { Via via = transactionResponse.getTopmostVia(); String transport = via.getTransport(); if (transport == null) throw new IOException("missing transport!");  int port = via.getRPort(); if (port == -1) port = via.getPort(); if (port == -1) { if (transport.equalsIgnoreCase("TLS")) port = 5061; else port = 5060; }         Host maddr = via.getMaddr(); String host = null; if (maddr != null) { host = maddr.getHostname(); } else {        host = via.getParameter(Via.RECEIVED); if (host == null) {      host = via.getHost(); } }  Hop hop = sipStack.addressResolver.resolveAddress(new HopImpl(host, port, transport));  MessageChannel messageChannel = ((SIPTransactionStack) getSIPStack()) .createRawMessageChannel(this.getPort(), hop); if (messageChannel != null) messageChannel.sendMessage(transactionResponse); else throw new IOException("Could not create a message channel for " + hop); } }
    private void sendResponse(SIPResponse transactionResponse)            throws IOException {        // RFC18.2.2. Sending Responses        //  The server transport uses the value of the top Via header field in        // order        //  to determine where to send a response.        //  It MUST follow the following process:        //  If the "sent-protocol" is a reliable transport        //  protocol such as TCP or SCTP,        //  or TLS over those, the response MUST be        //  sent using the existing connection        //  to the source of the original request        //  that created the transaction, if that connection is still open.        if (isReliable()) {            getMessageChannel().sendMessage(transactionResponse);            // If that connection attempt fails, the server SHOULD            // use SRV 3263 procedures            // for servers in order to determine the IP address            // and port to open the connection and send the response to.        } else {            Via via = transactionResponse.getTopmostVia();            String transport = via.getTransport();            if (transport == null)                throw new IOException("missing transport!");            //@@@ hagai Symmetric NAT support            int port = via.getrport();            if (port == -1)                port = via.getPort();            if (port == -1) {                if (transport.equalsIgnoreCase("TLS"))                    port = 5061;                else                    port = 5060;            }            // Otherwise, if the Via header field value contains a            // "maddr" parameter, the response MUST be forwarded to            // the address listed there, using the port indicated in "sent-by",            // or port 5060 if none is present. If the address is a multicast            // address, the response SHOULD be sent using            // the TTL indicated in the "ttl" parameter, or with a            // TTL of 1 if that parameter is not present.            Host maddr = via.getMaddr();            String host = null;            if (maddr != null) {                host = maddr.getHostname();            } else {                // Otherwise (for unreliable unicast transports),                // if the top Via has a "received" parameter, the response MUST                // be sent to the                // address in the "received" parameter, using the port indicated                // in the                // "sent-by" value, or using port 5060 if none is specified                // explicitly.                host = via.getParameter(Via.RECEIVED);                if (host == null) {                    // Otherwise, if it is not receiver-tagged, the response                    // MUST be                    // sent to the address indicated by the "sent-by" value,                    // using the procedures in Section 5                    // RFC 3263 PROCEDURE TO BE DONE HERE                    host = via.getHost();                }            }            // Changed by Daniel J. Martinez Manzano <dani@dif.um.es>            // Original code called constructor with concatenated            // parameters, which didn't work for IPv6 addresses.            HopImpl hop = new HopImpl(host, port, transport);            MessageChannel messageChannel = ((SIPTransactionStack) getSIPStack())                    .createRawMessageChannel(this.getPort(),hop);            messageChannel.sendMessage(transactionResponse);        }    }