diff --git a/daemon/src/sip/siptransport.cpp b/daemon/src/sip/siptransport.cpp index e3340f4c2bedfdff8506d429fb11b431e1e86b58..e1736927942734566e9f028792c74e300a3a7d53 100644 --- a/daemon/src/sip/siptransport.cpp +++ b/daemon/src/sip/siptransport.cpp @@ -61,6 +61,8 @@ #include "dbus/callmanager.h" #include "dbus/configurationmanager.h" +static const char * const DEFAULT_INTERFACE = "default"; + static pjsip_transport *localUDPTransport_ = NULL; /** The default transport (5060) */ std::string SipTransport::getSIPLocalIP() @@ -245,7 +247,7 @@ pj_status_t SipTransport::destroyStunResolver(const std::string &serverName) } -void SipTransport::createTlsListener(pj_uint16_t tlsListenerPort, pjsip_tls_setting *tlsSetting, pjsip_tpfactory **listener) +void SipTransport::createTlsListener(const std::string &interface, pj_uint16_t tlsListenerPort, pjsip_tls_setting *tlsSetting, pjsip_tpfactory **listener) { pj_sockaddr_in local_addr; pj_sockaddr_in_init(&local_addr, 0, 0); @@ -261,13 +263,22 @@ void SipTransport::createTlsListener(pj_uint16_t tlsListenerPort, pjsip_tls_sett return; } + std::string listeningAddress; + if (interface == DEFAULT_INTERFACE) + listeningAddress = getSIPLocalIP(); + else + listeningAddress = getInterfaceAddrFromName(interface); + + if (listeningAddress.empty()) { + ERROR("SipTransport: Could not determine ip address for this transport"); + } + pj_str_t pjAddress; pj_cstr(&pjAddress, PJ_INADDR_ANY); pj_sockaddr_in_set_str_addr(&local_addr, &pjAddress); - std::string localIP(getSIPLocalIP()); pjsip_host_port a_name = { - pj_str((char*) localIP.c_str()), + pj_str((char*) listeningAddress.c_str()), local_addr.sin_port }; @@ -277,6 +288,7 @@ void SipTransport::createTlsListener(pj_uint16_t tlsListenerPort, pjsip_tls_sett pjsip_transport * SipTransport::createTlsTransport(const std::string &remoteAddr, + const std::string &interface, pj_uint16_t tlsListenerPort, pjsip_tls_setting *tlsSettings) { @@ -292,7 +304,7 @@ SipTransport::createTlsTransport(const std::string &remoteAddr, static pjsip_tpfactory *localTlsListener = NULL; if (localTlsListener == NULL) - createTlsListener(tlsListenerPort, tlsSettings, &localTlsListener); + createTlsListener(interface, tlsListenerPort, tlsSettings, &localTlsListener); pjsip_endpt_acquire_transport(endpt_, PJSIP_TRANSPORT_TLS, &rem_addr, sizeof rem_addr, NULL, &transport); @@ -319,7 +331,7 @@ void SipTransport::createSipTransport(SIPAccount *account) size_t trns = remoteSipUri.find(";transport"); std::string remoteAddr(remoteSipUri.substr(sips, trns-sips)); - pjsip_transport *transport = createTlsTransport(remoteAddr, account->getTlsListenerPort(), account->getTlsSetting()); + pjsip_transport *transport = createTlsTransport(remoteAddr, account->getLocalInterface(), account->getTlsListenerPort(), account->getTlsSetting()); account->transport_ = transport; } else if (account->isStunEnabled()) { pjsip_transport *transport = createStunTransport(account->getStunServerName(), account->getStunPort()); @@ -392,7 +404,6 @@ SipTransport::createUdpTransport(const std::string &interface, unsigned int port DEBUG("SipTransport: Create UDP transport on %s:%d", interface.c_str(), port); // determine the ip address for this transport - static const char * const DEFAULT_INTERFACE = "default"; std::string listeningAddress; if (interface == DEFAULT_INTERFACE) listeningAddress = getSIPLocalIP(); diff --git a/daemon/src/sip/siptransport.h b/daemon/src/sip/siptransport.h index 21e2c8780157f153f81f01f5357afca75a97a0fd..7b2d4d107e15c0e77005f728e06cbbd2c96cc34c 100644 --- a/daemon/src/sip/siptransport.h +++ b/daemon/src/sip/siptransport.h @@ -131,6 +131,7 @@ class SipTransport { /** * Create The default TLS listener which is global to the application. This means that * only one TLS connection can be established for the momment. + * @param the interface to bind this listener to * @param the port number to create the TCP socket * @param pjsip's tls settings for the transport to be created which contains: * - path to ca certificate list file @@ -140,7 +141,7 @@ class SipTransport { * - the TLS method * @param a pointer to store the listener created, in our case this is a static pointer */ - void createTlsListener(pj_uint16_t, pjsip_tls_setting *, pjsip_tpfactory **); + void createTlsListener(const std::string &interface, pj_uint16_t, pjsip_tls_setting *, pjsip_tpfactory **); /** * Create a connection oriented TLS transport and register to the specified remote address. @@ -153,6 +154,7 @@ class SipTransport { */ pjsip_transport * createTlsTransport(const std::string &remoteAddr, + const std::string &interface, pj_uint16_t tlsListenerPort, pjsip_tls_setting *tlsSetting); diff --git a/daemon/src/sip/sipvoiplink.cpp b/daemon/src/sip/sipvoiplink.cpp index ab728da21312511f7682b3ee36bb23a90d34efb9..57a046a44b7d7dbdfa8cceee2eadbab7a60a3ef4 100644 --- a/daemon/src/sip/sipvoiplink.cpp +++ b/daemon/src/sip/sipvoiplink.cpp @@ -1149,8 +1149,8 @@ bool SIPVoIPLink::SIPNewIpToIpCall(const std::string& id, const std::string& to) } sipTransport.shutdownSipTransport(account); - pjsip_transport *transport = sipTransport.createTlsTransport(remoteAddr, account->getTlsListenerPort(), - account->getTlsSetting()); + pjsip_transport *transport = sipTransport.createTlsTransport(account->getLocalInterface(), remoteAddr, + account->getTlsListenerPort(), account->getTlsSetting()); if (transport == NULL) { ERROR("Error could not create TLS transport for IP2IP call");