Glob.sockaddr_in hexaddyporttosockaddy(string s, Glob.sockaddr_in sa) { IPAddress ip = IPAddress.Parse(int.Parse(s.Substring(0, 2), System.Globalization.NumberStyles.HexNumber).ToString() + "." + int.Parse(s.Substring(2, 2), System.Globalization.NumberStyles.HexNumber).ToString() + "." + int.Parse(s.Substring(4, 2), System.Globalization.NumberStyles.HexNumber).ToString() + "." + int.Parse(s.Substring(6, 2), System.Globalization.NumberStyles.HexNumber).ToString()); byte[] ipb = ip.GetAddressBytes(); sa.s_b1 = ipb[0]; sa.s_b2 = ipb[1]; sa.s_b3 = ipb[2]; sa.s_b4 = ipb[3]; sa.sin_port = UInt16.Parse(s.Substring(8, 4), System.Globalization.NumberStyles.HexNumber); return sa; }
Glob.sockaddr_in addyporttosockaddy(string s, Glob.sockaddr_in sa) { IPAddress ip = IPAddress.Parse(s.Substring(0, s.IndexOf(":"))); byte[] ipb = ip.GetAddressBytes(); sa.s_b1 = ipb[0]; sa.s_b2 = ipb[1]; sa.s_b3 = ipb[2]; sa.s_b4 = ipb[3]; sa.sin_port = UInt16.Parse(s.Substring(s.IndexOf(":") + 1, s.Length - s.IndexOf(":") - 1)); return sa; }