[OpenSIPStack] STUN support bug?
Brought to you by:
joegenbaclor
From: H.Kropf <mai...@gl...> - 2007-07-26 07:35:02
|
Hi Now in my project STUN-support works correctly For this purpose i has made such changes of a code ********************************************************* SIPNATMethods.h ********************************************************* class SIPSTUNClient : public PNatMethod { ............... public: // [+] virtual BOOL GetExternalPort( WORD & externalPort ); ............... protected: // [+] WORD cachedExternalPort; ............... }; ********************************************************* SIPNATMethods.cxx ********************************************************* //------------------------------------------------------------------------------------- //------------------------------------------------------------------------------------- SIPSTUNClient::SIPSTUNClient(const PString & server, WORD portBase, WORD portMax, WORD portPairBase, WORD portPairMax) ................. cachedExternalPort(0), // [+] ................. { ..................... ..................... } //------------------------------------------------------------------------------------- //------------------------------------------------------------------------------------- SIPSTUNClient::SIPSTUNClient(const PIPSocket::Address & address, WORD port, WORD portBase, WORD portMax, WORD portPairBase, WORD portPairMax) ..................... cachedExternalPort(0), // [+] ..................... { ..................... } //------------------------------------------------------------------------------------- //------------------------------------------------------------------------------------- BOOL SIPSTUNClient::GetExternalAddress(PIPSocket::Address & externalAddress, const PTimeInterval & maxAge) { ..................... ..................... externalAddress = cachedExternalAddress = mappedAddress->GetIP(); // [+] cachedExternalPort = (WORD)mappedAddress->port; ..................... } ********************************************************* SIPTransportManager.h ********************************************************* class SIPTransportManager : public PObject, public Logger { ............... public: // [+] BOOL TranslateIPAddress( PIPSocket::Address & localAddress, WORD & localPort ); ............... protexted: // [+] WORD m_TranslationPort; ............... }; ********************************************************* SIPTransportManager.cxx ********************************************************* //------------------------------------------------------------------------------------- //------------------------------------------------------------------------------------- SIPSTUNClient::NatTypes SIPTransportManager::SetSTUNServer( const OString & server, WORD udpPortBase, WORD udpPortMax, WORD rtpPortBase, WORD rtpPortMax ) { ............................................. m_STUNClient = new SIPSTUNClient(server, udpPortBase, udpPortMax, rtpPortBase, rtpPortMax ); SIPSTUNClient::NatTypes type = m_STUNClient->GetNatType(); if (type != SIPSTUNClient::BlockedNat && type != SIPSTUNClient::OpenNat) { m_STUNClient->GetExternalAddress(m_TranslationAddress); // [+] m_STUNClient->GetExternalPort(m_TranslationPort); } ............................................. ............................................. ............................................. } //------------------------------------------------------------------------------------- //------------------------------------------------------------------------------------- BOOL SIPTransportManager::TranslateIPAddress( PIPSocket::Address & localAddress, WORD & localPort ) { ............................................. ............................................. //if (SIPTransport::IsLocalAddress(remoteAddress)) // return FALSE; // Does not need to be translated // Tranlsate it! localAddress = m_TranslationAddress; // [+] localPort = m_TranslationPort; return TRUE; } ********************************************************* SoftPhone.cxx ********************************************************* BOOL SoftPhoneManager::InitializeSIP() { ............................................. ............................................. ............................................. ............................................. BOOL ok = TRUE; if( !m_IsInitialized ) { // [+] begin NAT::SIPSTUNClient::NatTypes ntNatType = SetSTUNServer("stun.mysrv.com"); if(ntNatType == NAT::SIPSTUNClient::ConeNat) GetSoftPhoneInterface()->Event_STUNInit(( true, (char)ntNatType ); else { SetSTUNServer(""); flip_core::Event_STUNInit( false , (char)ntNatType ); GetSoftPhoneInterface()->Event_STUNInit(( false , (char)ntNatType ); } // [+] end m_SIPEndPoint->GetProfile().GetTransportProfile().EnableUDP( sipIface, sipPort ); #if ENABLE_TCP_TRANSPORT m_SIPEndPoint->GetProfile().GetTransportProfile().EnableTCP( sipIface, sipPort); #endif ............................................. ............................................. ............................................. ............................................. } |