From f306d3cd2d993612b46217351238c43a02fbd8dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?I=C3=B1aki=20Baz=20Castillo?= Date: Mon, 4 Feb 2013 12:27:50 +0100 Subject: [PATCH] hack_ip_in_contact now generates a IP in the range of Test-Net as stated in RFC 5735 (192.0.2.0/24). --- src/UA.js | 2 +- src/Utils.js | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/UA.js b/src/UA.js index 328b85622..692083498 100644 --- a/src/UA.js +++ b/src/UA.js @@ -719,7 +719,7 @@ JsSIP.UA.prototype.loadConfig = function(configuration) { // Via Host if (settings.hack_ip_in_contact) { - settings.via_host = JsSIP.Utils.getRandomIP(); + settings.via_host = JsSIP.Utils.getRandomTestNetIP(); } // Transports diff --git a/src/Utils.js b/src/Utils.js index 42db154e6..ef117bf62 100644 --- a/src/Utils.js +++ b/src/Utils.js @@ -137,11 +137,15 @@ JsSIP.Utils= { return JsSIP.C.causes.SIP_FAILURE_CODE; }, - getRandomIP: function() { - function get_octet() { - return (Math.random() * 255 | 0) + 1; + /** + * Generate a random Test-Net IP (http://tools.ietf.org/html/rfc5735) + * @private + */ + getRandomTestNetIP: function() { + function getOctet(from,to) { + return window.Math.floor(window.Math.random()*(to-from+1)+from); } - return get_octet()+'.'+get_octet()+'.'+get_octet()+'.'+get_octet(); + return '192.0.2.' + getOctet(1, 254); }, checkUAStatus: function(ua) {