diff --git a/plugins/sip/calls-sip-call.c b/plugins/sip/calls-sip-call.c index 889c25d..3fc48d6 100644 --- a/plugins/sip/calls-sip-call.c +++ b/plugins/sip/calls-sip-call.c @@ -29,6 +29,7 @@ #include "calls-message-source.h" #include "calls-sip-media-manager.h" #include "calls-sip-media-pipeline.h" +#include "calls-sip-util.h" #include "calls-call.h" #include @@ -73,6 +74,7 @@ answer (CallsCall *call) { CallsSipCall *self; g_autofree gchar *local_sdp = NULL; + guint local_port = get_port_for_rtp (); g_assert (CALLS_IS_CALL (call)); g_assert (CALLS_IS_SIP_CALL (call)); @@ -87,10 +89,10 @@ answer (CallsCall *call) } /* XXX dynamically get free ports */ - calls_sip_call_setup_local_media (self, 19042, 19043); + calls_sip_call_setup_local_media (self, local_port, local_port + 1); local_sdp = calls_sip_media_manager_static_capabilities (self->manager, - 19042, + local_port, FALSE); g_assert (local_sdp); diff --git a/plugins/sip/calls-sip-origin.c b/plugins/sip/calls-sip-origin.c index 15c35f4..978bf45 100644 --- a/plugins/sip/calls-sip-origin.c +++ b/plugins/sip/calls-sip-origin.c @@ -646,15 +646,16 @@ add_call (CallsSipOrigin *self, CallsSipCall *sip_call; CallsCall *call; g_autofree gchar *local_sdp = NULL; + guint local_port = get_port_for_rtp (); sip_call = calls_sip_call_new (address, inbound, handle); g_assert (sip_call != NULL); /* XXX dynamically get/probe free ports */ - calls_sip_call_setup_local_media (sip_call, 19042, 19043); + calls_sip_call_setup_local_media (sip_call, local_port, local_port + 1); local_sdp = calls_sip_media_manager_static_capabilities (self->media_manager, - 19042, + local_port, check_sips (address)); g_assert (local_sdp); diff --git a/plugins/sip/calls-sip-util.c b/plugins/sip/calls-sip-util.c index 20534d1..2033397 100644 --- a/plugins/sip/calls-sip-util.c +++ b/plugins/sip/calls-sip-util.c @@ -53,3 +53,17 @@ protocol_is_valid (const gchar *protocol) g_strcmp0 (protocol, "TCP") == 0 || g_strcmp0 (protocol, "TLS") == 0; } + +#define RTP_PORT_MIN 20000 +#define RTP_PORT_MAX 65534 +guint +get_port_for_rtp (void) +{ + const guint rand_range = RTP_PORT_MAX - RTP_PORT_MIN; + guint rand = (g_random_int () % rand_range) + RTP_PORT_MIN; + + /* RTP ports must be even */ + return rand % 2 == 0 ? rand : rand + 1; +} +#undef RTP_PORT_MIN +#undef RTP_PORT_MAX diff --git a/plugins/sip/calls-sip-util.h b/plugins/sip/calls-sip-util.h index b796fe4..9767e7a 100644 --- a/plugins/sip/calls-sip-util.h +++ b/plugins/sip/calls-sip-util.h @@ -82,3 +82,4 @@ typedef enum gboolean check_sips (const gchar *addr); const gchar *get_protocol_prefix (const gchar *protocol); gboolean protocol_is_valid (const gchar *protocol); +guint get_port_for_rtp (void);