diff --git a/src/sip-dialog-controller.cpp b/src/sip-dialog-controller.cpp index 35616dcc29..49ca29a3c8 100644 --- a/src/sip-dialog-controller.cpp +++ b/src/sip-dialog-controller.cpp @@ -137,6 +137,12 @@ namespace drachtio { } SipDialogController::~SipDialogController() { } + bool SipDialogController::isIPv6(const std::string &address) + { + return address.find(':') != std::string::npos; + } + + bool SipDialogController::sendRequestInsideDialog( const string& clientMsgId, const string& dialogId, const string& startLine, const string& headers, const string& body, string& transactionId ) { assert( dialogId.length() > 0 ) ; @@ -838,7 +844,24 @@ namespace drachtio { } else { url_t const * url = nta_outgoing_route_uri(orq); - string routeUri = string((url ? url->url_scheme : "sip")) + ":" + meta.getAddress() + ":" + meta.getPort(); + + + // Retrieve address and port from meta + std::string fetchedAddress = meta.getAddress(); + std::string fetchedPort = meta.getPort(); + + // Determine the scheme + std::string fetchedScheme = (url ? url->url_scheme : "sip"); + + // Construct routeUri based on IP version + std::string routeUri; + if (isIPv6(fetchedAddress)) { + routeUri = fetchedScheme + ":[" + fetchedAddress + "]:" + fetchedPort; + } else { + routeUri = fetchedScheme + ":" + fetchedAddress + ":" + fetchedPort; + } + + dlg->setRouteUri(routeUri); DR_LOG(log_info) << "SipDialogController::processResponseOutsideDialog - (UAC) detected nat setting route to: " << routeUri; } @@ -906,6 +929,7 @@ namespace drachtio { return 0 ; } + void SipDialogController::doRespondToSipRequest( SipMessageData* pData ) { string transactionId( pData->getTransactionId() ); string startLine( pData->getStartLine()) ; diff --git a/src/sip-dialog-controller.hpp b/src/sip-dialog-controller.hpp index fc48efb453..c7cf844345 100644 --- a/src/sip-dialog-controller.hpp +++ b/src/sip-dialog-controller.hpp @@ -176,6 +176,7 @@ namespace drachtio { bool sendRequestOutsideDialog( const string& clientMsgId, const string& startLine, const string& headers, const string& body, string& transactionId, string& dialogId, string& routeUrl ) ; bool respondToSipRequest( const string& msgId, const string& transactionId, const string& startLine, const string& headers, const string& body ) ; bool sendCancelRequest( const string& msgId, const string& transactionId, const string& startLine, const string& headers, const string& body ) ; + bool isIPv6(const std::string &address); //NB: doSendXXX correspond to the above, and are run in the stack thread void doSendRequestInsideDialog( SipMessageData* pData ) ;