diff --git a/daemon/src/sip/sipaccount.cpp b/daemon/src/sip/sipaccount.cpp index 031bda7cbf136e30d87deefafba8eba68df7431c..fd5b198a41aca767d2263778f3536b369c39b470 100644 --- a/daemon/src/sip/sipaccount.cpp +++ b/daemon/src/sip/sipaccount.cpp @@ -99,6 +99,7 @@ SIPAccount::SIPAccount(const std::string& accountID) , keepAliveTimer_() , link_(SIPVoIPLink::instance()) , receivedParameter_() + , rPort_(-1) {} void SIPAccount::serialize(Conf::YamlEmitter &emitter) diff --git a/daemon/src/sip/sipaccount.h b/daemon/src/sip/sipaccount.h index 007c4cab156ca8e9b08f797de07067d30bf978b3..6b97d5b1cc49aa8a5736d45ee8f18b4568e3f830 100644 --- a/daemon/src/sip/sipaccount.h +++ b/daemon/src/sip/sipaccount.h @@ -505,6 +505,15 @@ class SIPAccount : public Account { return receivedParameter_; } + int getRPort() const { + if (rPort_ == -1) + return localPort_; + else + return rPort_; + } + + void setRPort(int rPort) { rPort_ = rPort; } + /** * Timer used to periodically send re-register request based * on the "Expire" sip header (or the "expire" Contact parameter) @@ -734,9 +743,14 @@ class SIPAccount : public Account { SIPVoIPLink* link_; /** - * Received via parameters + * Optional: "received" parameter from VIA header */ std::string receivedParameter_; + + /** + * Optional: "rport" parameter from VIA header + */ + int rPort_; }; #endif diff --git a/daemon/src/sip/sipvoiplink.cpp b/daemon/src/sip/sipvoiplink.cpp index c8773ca594a38be3e2653d27cb184cb1353e0c21..a1a0c0469cdb107de1735dad065920b33e733a01 100644 --- a/daemon/src/sip/sipvoiplink.cpp +++ b/daemon/src/sip/sipvoiplink.cpp @@ -519,11 +519,12 @@ void SIPVoIPLink::sendRegister(Account *a) std::string contact = account->getContactHeader(); pj_str_t pjContact = pj_str((char*) contact.c_str()); - if(!received.empty()) { + if (!received.empty()) { // Set received parameter string to empty in order to avoid creating new transport for each register account->setReceivedParameter(""); // Explicitely set the bound address port to 0 so that pjsip determine a random port by itself - account->transport_= sipTransport.createUdpTransport(account->getLocalInterface(), 0, received, account->getLocalPort()); + account->transport_= sipTransport.createUdpTransport(account->getLocalInterface(), 0, received, account->getRPort()); + account->setRPort(-1); if(account->transport_ == NULL) { ERROR("UserAgent: Could not create new udp transport with public address: %s:%d", received.c_str(), account->getLocalPort()); } @@ -1582,6 +1583,8 @@ void lookForReceivedParameter(pjsip_regc_cbparam *param, SIPAccount *account) DEBUG("Cool received received parameter... uhhh?, the value is %s", publicIpFromReceived.c_str()); account->setReceivedParameter(publicIpFromReceived); } + + account->setRPort(param->rdata->msg_info.via->rport_param); } void registration_cb(pjsip_regc_cbparam *param)