Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes to support ipv6 when nating #399

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion src/sip-dialog-controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) ;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -906,6 +929,7 @@ namespace drachtio {

return 0 ;
}

void SipDialogController::doRespondToSipRequest( SipMessageData* pData ) {
string transactionId( pData->getTransactionId() );
string startLine( pData->getStartLine()) ;
Expand Down
1 change: 1 addition & 0 deletions src/sip-dialog-controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) ;
Expand Down