diff --git a/daemon/src/sip/sipaccount.cpp b/daemon/src/sip/sipaccount.cpp index 3e25e38af8ef51c844ccd7902354f3118cf2fa05..45e0fc06a905d5ca1a50fc84da6f043191bcb480 100644 --- a/daemon/src/sip/sipaccount.cpp +++ b/daemon/src/sip/sipaccount.cpp @@ -66,7 +66,8 @@ const char *const TRUE_STR = "true"; const char *const FALSE_STR = "false"; } -bool SIPAccount::portsInUse_[MAX_PORT]; +// we force RTP ports to be even, so we only need HALF_MAX_PORT booleans +bool SIPAccount::portsInUse_[HALF_MAX_PORT]; SIPAccount::SIPAccount(const std::string& accountID) : Account(accountID) @@ -1396,16 +1397,16 @@ SIPAccount::getRandomEvenNumber(const std::pair<uint16_t, uint16_t> &range) uint16_t result; do { result = 2 * (halfLower + rand() % (halfUpper - halfLower + 1)); - } while (portsInUse_[result]); + } while (portsInUse_[result / 2]); - portsInUse_[result] = true; + portsInUse_[result / 2] = true; return result; } void SIPAccount::releasePort(uint16_t port) { - portsInUse_[port] = false; + portsInUse_[port / 2] = false; } uint16_t diff --git a/daemon/src/sip/sipaccount.h b/daemon/src/sip/sipaccount.h index 096af78c0f0b412ba68cdddb9a2d4656e5049253..7cf564faddf2b84b2bb30a58c1987a46da8b4fe2 100644 --- a/daemon/src/sip/sipaccount.h +++ b/daemon/src/sip/sipaccount.h @@ -105,6 +105,7 @@ class SIPVoIPLink; * @brief A SIP Account specify SIP specific functions and object = SIPCall/SIPVoIPLink) */ enum {MAX_PORT = 65536}; +enum {HALF_MAX_PORT = MAX_PORT / 2}; class SIPAccount : public Account { public: @@ -789,7 +790,7 @@ class SIPAccount : public Account { */ std::pair<uint16_t, uint16_t> videoPortRange_; #endif - static bool portsInUse_[MAX_PORT]; + static bool portsInUse_[HALF_MAX_PORT]; static uint16_t getRandomEvenNumber(const std::pair<uint16_t, uint16_t> &range); };