bool Opal::Sip::EndPoint::set_listen_port (unsigned port) { unsigned udp_min, udp_max; listen_iface.protocol = "udp"; listen_iface.voip_protocol = "sip"; listen_iface.id = "*"; manager.get_udp_ports (udp_min, udp_max); if (port > 0) { std::stringstream str; RemoveListener (NULL); str << "udp$*:" << port; if (!StartListeners (PStringArray (str.str ()))) { port = udp_min; str << "udp$*:" << port; while (port <= udp_max) { if (StartListeners (PStringArray (str.str ()))) { listen_iface.port = port; PTRACE (4, "Opal::Sip::EndPoint\tSet listen port to " << port); return true; } port++; } } else { listen_iface.port = port; PTRACE (4, "Opal::Sip::EndPoint\tSet listen port to " << port); return true; } } return false; }
bool Opal::Sip::EndPoint::StartListener (unsigned port) { unsigned udp_min = GetManager ().GetUDPPortBase (); unsigned udp_max = GetManager ().GetUDPPortMax (); unsigned tcp_min = GetManager ().GetTCPPortBase (); unsigned tcp_max = GetManager ().GetTCPPortMax (); const std::string protocols[] = { "udp", "tcp", "" }; const unsigned ports[][2] = { { udp_min, udp_max }, { tcp_min, tcp_max } }; if (port > 0) { RemoveListener (NULL); for (int i = 0 ; !protocols[i].empty () ; i++) { std::stringstream str; str << protocols[i] << "$*:" << port; if (!StartListeners (PStringArray (str.str ()))) { port = ports[i][0]; while (port <= ports[i][1]) { str << protocols[i] << "$*:" << port; if (StartListeners (PStringArray (str.str ()))) { PTRACE (4, "Opal::Sip::EndPoint\tSet listen port to " << port << " (" << protocols[i] << ")"); break; } port++; } } else PTRACE (4, "Opal::Sip::EndPoint\tSet listen port to " << port << " (" << protocols[i] << ")"); } } return false; }