public void NoMangleIPv6UnitTest() { logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name); SIPURI uri = SIPURI.ParseSIPURI("sip:user@[2001:730:3ec2::10]:5060?Replaces=xyz"); SIPURI mangled = SIPURI.Mangle(uri, IPSocket.Parse("67.222.131.147:5060")); Assert.Null(mangled); logger.LogDebug("-----------------------------------------"); }
public void NoMangleSameAddressUnitTest() { logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name); SIPURI uri = SIPURI.ParseSIPURI("sip:[email protected]:5060?Replaces=xyz"); SIPURI mangled = SIPURI.Mangle(uri, IPSocket.Parse("192.168.0.50:5060")); Assert.Null(mangled); logger.LogDebug("-----------------------------------------"); }
public void MangleReceiveOnIPv6UnitTest() { logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name); SIPURI uri = SIPURI.ParseSIPURI("sip:[email protected]:5060?Replaces=xyz"); SIPURI mangled = SIPURI.Mangle(uri, IPSocket.Parse("[2001:730:3ec2::10]:5090")); logger.LogDebug($"Mangled URI {mangled}."); Assert.NotNull(mangled); Assert.Equal("sip:user@[2001:730:3ec2::10]:5090?Replaces=xyz", mangled.ToString()); logger.LogDebug("-----------------------------------------"); }
public void MangleNoPortUnitTest() { logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name); SIPURI uri = SIPURI.ParseSIPURI("sip:[email protected]?Replaces=xyz"); SIPURI mangled = SIPURI.Mangle(uri, IPSocket.Parse("67.222.131.147:5090")); logger.LogDebug($"Mangled URI {mangled}."); Assert.NotNull(mangled); Assert.Equal("sip:[email protected]:5090?Replaces=xyz", mangled.ToString()); logger.LogDebug("-----------------------------------------"); }
private static DNSResponse MatchIPAddress(string hostname) { try { string host = null; int port = 0; if (IPSocket.Parse(hostname, out host, out port)) { DNSResponse result = new DNSResponse(IPAddress.Parse(host)); return(result); } if (!string.IsNullOrWhiteSpace(hostname)) { hostname = hostname.Trim(); if (Regex.Match(hostname, @"(\d+\.){3}\d+(:\d+$|$)").Success) { string ipAddress = Regex.Match(hostname, @"(?<ipaddress>(\d+\.){3}\d+)(:\d+$|$)") .Result("${ipaddress}"); DNSResponse result = new DNSResponse(IPAddress.Parse(ipAddress)); return(result); } else if (Regex.Match(hostname, @"^\[?[:a-fA-F0-9]+\]?(:\d+$|$)", RegexOptions.Singleline | RegexOptions.ExplicitCapture).Success) { string ipAddress = Regex.Match(hostname, @"^\[?(?<ipaddress>([:a-fA-F0-9]+))\]?(:\d+$|$)", RegexOptions.Singleline | RegexOptions.ExplicitCapture).Result("${ipaddress}"); DNSResponse result = new DNSResponse(IPAddress.Parse(ipAddress)); return(result); } else { return(null); } } else { return(null); } } catch (Exception excp) { logger.LogError("Exception DNSManager MatchIPAddress. " + excp); return(null); } }
/// <summary> /// Initialises the association state based on the echoed cookie (the cookie that we sent /// to the remote party and was then echoed back to us). An association can only be initialised /// from a cookie prior to it being used and prior to it ever having entered the established state. /// </summary> /// <param name="cookie">The echoed cookie that was returned from the remote party.</param> public void GotCookie(SctpTransportCookie cookie) { // The CookieEchoed state is allowed, even though a cookie should be creating a brand // new association rather than one that has already sent an INIT, in order to deal with // a race condition where both SCTP end points attempt to establish the association at // the same time using the same ports. if (_wasAborted || _wasShutdown) { logger.LogWarning($"SCTP association cannot initialise with a cookie after an abort or shutdown."); } else if (!(State == SctpAssociationState.Closed || State == SctpAssociationState.CookieEchoed)) { throw new ApplicationException($"SCTP association cannot initialise with a cookie in state {State}."); } else { _sctpSourcePort = cookie.SourcePort; _sctpDestinationPort = cookie.DestinationPort; VerificationTag = cookie.Tag; ARwnd = cookie.ARwnd; Destination = !string.IsNullOrEmpty(cookie.RemoteEndPoint) ? IPSocket.Parse(cookie.RemoteEndPoint) : null; if (_dataReceiver == null) { _dataReceiver = new SctpDataReceiver(ARwnd, _defaultMTU, cookie.RemoteTSN); } if (_dataSender == null) { _dataSender = new SctpDataSender(ID, this.SendChunk, _defaultMTU, cookie.TSN, cookie.RemoteARwnd); } InitRemoteProperties(cookie.RemoteTag, cookie.RemoteTSN, cookie.RemoteARwnd); var cookieAckChunk = new SctpChunk(SctpChunkType.COOKIE_ACK); SendChunk(cookieAckChunk); SetState(SctpAssociationState.Established); _dataSender.StartSending(); CancelTimers(); } }
public void ParseTest() { logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name); string host = null; int port = 0; string endpoint = "localhost:5060"; Assert.False(IPSocket.Parse(endpoint, out host, out port), $"'{endpoint}' Valid endpoint address"); Assert.True(host == "localhost", "The host was not parsed correctly."); Assert.True(port == 5060, "The port was not parsed correctly."); Assert.False(IPSocket.IsIPAddress(host), $"'{endpoint}' Valid ip address"); endpoint = "host.domain.tld:5060"; Assert.False(IPSocket.Parse(endpoint, out host, out port), $"'{endpoint}' Valid endpoint address"); Assert.True(host == "host.domain.tld", "The host was not parsed correctly."); Assert.True(port == 5060, "The port was not parsed correctly."); Assert.False(IPSocket.IsIPAddress(host), $"'{endpoint}' Valid ip address"); endpoint = "127.0.0.1:5060"; Assert.True(IPSocket.Parse(endpoint, out host, out port), $"'{endpoint}' Invalid endpoint address"); Assert.True(host == "127.0.0.1", "The host was not parsed correctly."); Assert.True(port == 5060, "The port was not parsed correctly."); Assert.True(IPSocket.IsIPAddress(host), $"'{endpoint}' Invalid ip address"); endpoint = "[::1]:5060"; Assert.True(IPSocket.Parse(endpoint, out host, out port), $"'{endpoint}' Invalid endpoint address"); Assert.True(host == "::1", "The host was not parsed correctly."); Assert.True(port == 5060, "The port was not parsed correctly."); Assert.True(IPSocket.IsIPAddress(host), $"'{endpoint}' Invalid ip address"); endpoint = "[::ffff:127.0.0.1]:5060"; Assert.True(IPSocket.Parse(endpoint, out host, out port), $"'{endpoint}' Invalid endpoint address"); Assert.True(host == "::ffff:127.0.0.1", "The host was not parsed correctly."); Assert.True(port == 5060, "The port was not parsed correctly."); Assert.True(IPSocket.IsIPAddress(host), $"'{endpoint}' Invalid ip address"); endpoint = "localhost"; Assert.False(IPSocket.Parse(endpoint, out host, out port), $"'{endpoint}' Valid endpoint address"); Assert.True(host == "localhost", "The host was not parsed correctly."); endpoint = "host.domain.tld"; Assert.False(IPSocket.Parse(endpoint, out host, out port), $"'{endpoint}' Valid endpoint address"); Assert.True(host == "host.domain.tld", "The host was not parsed correctly."); endpoint = "127.0.0.1"; Assert.True(IPSocket.Parse(endpoint, out host, out port), $"'{endpoint}' Invalid endpoint address"); Assert.True(host == "127.0.0.1", "The host was not parsed correctly."); Assert.True(IPSocket.IsIPAddress(host), $"'{endpoint}' Invalid ip address"); endpoint = "[::1]"; Assert.True(IPSocket.Parse(endpoint, out host, out port), $"'{endpoint}' Invalid endpoint address"); Assert.True(host == "::1", "The host was not parsed correctly."); Assert.True(IPSocket.IsIPAddress(host), $"'{endpoint}' Invalid ip address"); endpoint = "[::ffff:127.0.0.1]"; Assert.True(IPSocket.Parse(endpoint, out host, out port), $"'{endpoint}' Invalid endpoint address"); Assert.True(host == "::ffff:127.0.0.1", "The host was not parsed correctly."); Assert.True(IPSocket.IsIPAddress(host), $"'{endpoint}' Invalid ip address"); endpoint = "::1"; Assert.True(IPSocket.Parse(endpoint, out host, out port), $"'{endpoint}' Invalid endpoint address"); Assert.True(host == "::1", "The host was not parsed correctly."); Assert.True(IPSocket.IsIPAddress(host), $"'{endpoint}' Invalid ip address"); endpoint = "::ffff:127.0.0.1"; Assert.True(IPSocket.Parse(endpoint, out host, out port), $"'{endpoint}' Invalid endpoint address"); Assert.True(host == "::ffff:127.0.0.1", "The host was not parsed correctly."); Assert.True(IPSocket.IsIPAddress(host), $"'{endpoint}' Invalid ip address"); endpoint = "::ffff:127.0.0..1"; Assert.Throws <FormatException>(() => IPSocket.Parse(endpoint, out host, out port)); endpoint = "::ffff:"; Assert.Throws <FormatException>(() => IPSocket.Parse(endpoint, out host, out port)); endpoint = "127.0.0..1"; Assert.False(IPSocket.Parse(endpoint, out host, out port), $"'{endpoint}' Valid endpoint address"); Assert.False(IPSocket.IsIPAddress(host), $"'{endpoint}' Valid ip address"); endpoint = "127.0.0."; Assert.False(IPSocket.Parse(endpoint, out host, out port), $"'{endpoint}' Valid endpoint address"); Assert.False(IPSocket.IsIPAddress(host), $"'{endpoint}' Valid ip address"); endpoint = "328.0.0.1"; Assert.False(IPSocket.Parse(endpoint, out host, out port), $"'{endpoint}' Valid endpoint address"); Assert.False(IPSocket.IsIPAddress(host), $"'{endpoint}' Valid ip address"); endpoint = "\0"; Assert.False(IPSocket.Parse(endpoint, out host, out port), $"'{endpoint}' Valid endpoint address"); Assert.False(IPSocket.IsIPAddress(host), $"'{endpoint}' Valid ip address"); }
public void ParseEndpointTest() { logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name); System.Net.IPEndPoint ep = null; string endpoint = "localhost:5060"; ep = IPSocket.Parse(endpoint); Assert.NotNull(ep); Assert.True(System.Net.IPAddress.IsLoopback(ep.Address), "The host was not parsed correctly."); Assert.True(ep.Port == 5060, "The port was not parsed correctly."); endpoint = "host.domain.tld:5060"; Assert.Throws <FormatException>(() => IPSocket.Parse(endpoint)); endpoint = "127.0.0.1:5060"; ep = IPSocket.Parse(endpoint); Assert.NotNull(ep); Assert.True(ep.Address.ToString() == "127.0.0.1", "The host was not parsed correctly."); Assert.True(ep.Port == 5060, "The port was not parsed correctly."); endpoint = "[::1]:5060"; ep = IPSocket.Parse(endpoint); Assert.NotNull(ep); Assert.True(ep.Address.ToString() == "::1", "The host was not parsed correctly."); Assert.True(ep.Port == 5060, "The port was not parsed correctly."); endpoint = "[::ffff:127.0.0.1]:5060"; ep = IPSocket.Parse(endpoint); Assert.NotNull(ep); Assert.True(ep.Address.ToString() == "::ffff:127.0.0.1", "The host was not parsed correctly."); Assert.True(ep.Port == 5060, "The port was not parsed correctly."); endpoint = "localhost"; ep = IPSocket.Parse(endpoint); Assert.NotNull(ep); Assert.True(System.Net.IPAddress.IsLoopback(ep.Address), "The host was not parsed correctly."); endpoint = "host.domain.tld"; Assert.Throws <FormatException>(() => IPSocket.Parse(endpoint)); endpoint = "127.0.0.1"; ep = IPSocket.Parse(endpoint); Assert.NotNull(ep); Assert.True(ep.Address.ToString() == "127.0.0.1", "The host was not parsed correctly."); endpoint = "[::1]"; ep = IPSocket.Parse(endpoint); Assert.NotNull(ep); Assert.True(ep.Address.ToString() == "::1", "The host was not parsed correctly."); endpoint = "[::ffff:127.0.0.1]"; ep = IPSocket.Parse(endpoint); Assert.NotNull(ep); Assert.True(ep.Address.ToString() == "::ffff:127.0.0.1", "The host was not parsed correctly."); endpoint = "::1"; ep = IPSocket.Parse(endpoint); Assert.NotNull(ep); Assert.True(ep.Address.ToString() == "::1", "The host was not parsed correctly."); endpoint = "::ffff:127.0.0.1"; ep = IPSocket.Parse(endpoint); Assert.NotNull(ep); Assert.True(ep.Address.ToString() == "::ffff:127.0.0.1", "The host was not parsed correctly."); endpoint = "::ffff:127.0.0..1"; Assert.Throws <FormatException>(() => IPSocket.Parse(endpoint)); endpoint = "::ffff:"; Assert.Throws <FormatException>(() => IPSocket.Parse(endpoint)); endpoint = "127.0.0..1"; Assert.Throws <FormatException>(() => IPSocket.Parse(endpoint)); endpoint = "127.0.0."; Assert.Throws <FormatException>(() => IPSocket.Parse(endpoint)); endpoint = "328.0.0.1"; Assert.Throws <FormatException>(() => IPSocket.Parse(endpoint)); endpoint = "\0"; Assert.Throws <ArgumentException>(() => IPSocket.Parse(endpoint)); }