using System; using System.IO; using System.Text; namespace System.Net.Sockets { // Token: 0x020001F3 RID: 499 internal static class SocketPolicyClient { // Token: 0x060010BE RID: 4286 RVA: 0x00030878 File Offset: 0x0002EA78 private static void Log(string msg) { Console.WriteLine(string.Concat(new object[] { "SocketPolicyClient", SocketPolicyClient.session, ": ", msg })); } // Token: 0x060010BF RID: 4287 RVA: 0x000308AC File Offset: 0x0002EAAC private static Stream GetPolicyStreamForIP(string ip, int policyport, int timeout) { SocketPolicyClient.session++; SocketPolicyClient.Log("Incoming GetPolicyStreamForIP"); IPEndPoint ipendPoint = new IPEndPoint(IPAddress.Parse(ip), policyport); Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); byte[] array = new byte[5000]; MemoryStream memoryStream = new MemoryStream(); try { SocketPolicyClient.Log("About to BeginConnect to " + ipendPoint); IAsyncResult asyncResult = socket.BeginConnect(ipendPoint, null, null, false); SocketPolicyClient.Log("About to WaitOne"); DateTime now = DateTime.Now; if (!asyncResult.AsyncWaitHandle.WaitOne(timeout)) { SocketPolicyClient.Log("WaitOne timed out. Duration: " + (DateTime.Now - now).TotalMilliseconds); socket.Close(); throw new Exception("BeginConnect timed out"); } socket.EndConnect(asyncResult); SocketPolicyClient.Log("Socket connected"); byte[] bytes = Encoding.ASCII.GetBytes("\0"); SocketError socketError; socket.Send_nochecks(bytes, 0, bytes.Length, SocketFlags.None, out socketError); if (socketError != SocketError.Success) { SocketPolicyClient.Log("Socket error: " + socketError); return memoryStream; } int num = socket.Receive_nochecks(array, 0, array.Length, SocketFlags.None, out socketError); if (socketError != SocketError.Success) { SocketPolicyClient.Log("Socket error: " + socketError); return memoryStream; } try { socket.Shutdown(SocketShutdown.Both); socket.Close(); } catch (SocketException) { } memoryStream = new MemoryStream(array, 0, num); } catch (Exception ex) { SocketPolicyClient.Log("Caught exception: " + ex.Message); return memoryStream; } memoryStream.Seek(0L, SeekOrigin.Begin); return memoryStream; } // Token: 0x04000F1C RID: 3868 private const string policy_request = "\0"; // Token: 0x04000F1D RID: 3869 private static int session; } }