IPEndPoint

Aug 16, 2008 at 12:39 AM
I had to modify this function to the following as it threw an exception because the "address += Convert.ToInt32 (r.Match(text).Result("${h4}")) << 24;" on larger numbers exceeds the size of a 32bit value and becomes negative.

private

 

IPEndPoint ParseIPEndPoint (string text)
{
Regex r = new Regex(@"\((?<h1>[\S]*),(?<h2>[\S]*),(?<h3>[\S]*),(?<h4>[\S]*),(?<p1>[\S]*),(?<p2>[\S]*)\)", RegexOptions.Compiled);
if (r.IsMatch (text) == true)
{
//r.Match(text).Result("${h1}:${h2}:${h3}:${h4}:${p1}:${p2}"));
System.Int64 address = 0;
address +=
Convert.ToInt64 (r.Match(text).Result("${h1}")) << 0;
address +=
Convert.ToInt64 (r.Match(text).Result("${h2}")) << 8;
address +=
Convert.ToInt64 (r.Match(text).Result("${h3}")) << 16;
address +=
Convert.ToInt64 (r.Match(text).Result("${h4}")) << 24;
int port = 0;
port +=
Convert.ToInt32 (r.Match(text).Result("${p1}")) << 8;
port +=
Convert.ToInt32 (r.Match(text).Result("${p2}")) << 0;
IPEndPoint ipe = new IPEndPoint (address, port);
return ipe;
}
return null;
}