diff -rupN pjproject-2.5.5/pjsip/src/pjsip/sip_transport.c pjproject-2.5.5-new/pjsip/src/pjsip/sip_transport.c --- pjproject-2.5.5/pjsip/src/pjsip/sip_transport.c 2016-02-25 05:38:34.000000000 +0100 +++ pjproject-2.5.5-new/pjsip/src/pjsip/sip_transport.c 2017-01-05 14:15:09.069519967 +0100 @@ -1248,22 +1248,22 @@ PJ_DEF(pj_status_t) pjsip_tpmgr_register pj_lock_acquire(mgr->lock); - /* Check that no factory with the same type has been registered. */ + /* Check that no factory with the same type and bound address has been registered. */ status = PJ_SUCCESS; for (p=mgr->factory_list.next; p!=&mgr->factory_list; p=p->next) { - if (p->type == tpf->type) { - status = PJSIP_ETYPEEXISTS; - break; - } - if (p == tpf) { - status = PJ_EEXISTS; - break; - } + if (p->type == tpf->type && !pj_sockaddr_cmp(&tpf->local_addr, &p->local_addr)) { + status = PJSIP_ETYPEEXISTS; + break; + } + if (p == tpf) { + status = PJ_EEXISTS; + break; + } } if (status != PJ_SUCCESS) { - pj_lock_release(mgr->lock); - return status; + pj_lock_release(mgr->lock); + return status; } pj_list_insert_before(&mgr->factory_list, tpf); @@ -2047,13 +2047,11 @@ PJ_DEF(pj_status_t) pjsip_tpmgr_acquire_ pj_memcpy(&key.rem_addr, remote, addr_len); transport = (pjsip_transport*) - pj_hash_get(mgr->table, &key, key_len, NULL); - + pj_hash_get(mgr->table, &key, key_len, NULL); + unsigned flag = pjsip_transport_get_flag_from_type(type); if (transport == NULL) { - unsigned flag = pjsip_transport_get_flag_from_type(type); const pj_sockaddr *remote_addr = (const pj_sockaddr*)remote; - /* Ignore address for loop transports. */ if (type == PJSIP_TRANSPORT_LOOP || type == PJSIP_TRANSPORT_LOOP_DGRAM) @@ -2135,6 +2133,11 @@ PJ_DEF(pj_status_t) pjsip_tpmgr_acquire_ } } else { + /* Make sure we don't use another factory than the one given if secure flag is set */ + if (flag & PJSIP_TRANSPORT_SECURE) { + TRACE_((THIS_FILE, "Can't create new TLS transport with no provided suitable TLS listener.")); + return PJSIP_ETPNOTSUITABLE; + } /* Find factory with type matches the destination type */ factory = mgr->factory_list.next;