|
@@ -15,18 +15,29 @@ namespace STUN.Utils
|
|
|
|
|
|
public static IPEndPoint ParseEndpoint(string str)
|
|
|
{
|
|
|
- //TODO:IPv6
|
|
|
var ipPort = str.Trim().Split(':');
|
|
|
- if (ipPort.Length == 2)
|
|
|
+ if (ipPort.Length < 2) return null;
|
|
|
+ IPAddress ip = null;
|
|
|
+ if (ipPort.Length == 2 && IPAddress.TryParse(ipPort[0], out ip))
|
|
|
{
|
|
|
- if (IPAddress.TryParse(ipPort[0], out var ip))
|
|
|
+ if (!IPAddress.TryParse(ipPort[0], out ip))
|
|
|
{
|
|
|
- if (ushort.TryParse(ipPort[1], out var port))
|
|
|
- {
|
|
|
- return new IPEndPoint(ip, port);
|
|
|
- }
|
|
|
+ return null;
|
|
|
}
|
|
|
}
|
|
|
+ else if (ipPort.Length > 2)
|
|
|
+ {
|
|
|
+ var ipStr = string.Join(@":", ipPort, 0, ipPort.Length - 1);
|
|
|
+ if (!ipStr.StartsWith(@"[") || !ipStr.EndsWith(@"]") || !IPAddress.TryParse(ipStr, out ip))
|
|
|
+ {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (ip != null && ushort.TryParse(ipPort.Last(), out var port))
|
|
|
+ {
|
|
|
+ return new IPEndPoint(ip, port);
|
|
|
+ }
|
|
|
|
|
|
return null;
|
|
|
}
|