// Token: 0x06000019 RID: 25 RVA: 0x00009DBC File Offset: 0x00007FBC private static IPAddress GetNextAddress(ConnectAsyncExtension.DnsConnectState state, out Socket attempSocket) { IPAddress ipaddress = null; attempSocket = null; int nextAddressIndex = state.NextAddressIndex; while (attempSocket == null) { if (nextAddressIndex >= state.Addresses.Length) { return(null); } ipaddress = state.Addresses[nextAddressIndex++]; if (ipaddress.AddressFamily == AddressFamily.InterNetworkV6) { attempSocket = state.Socket6; } else if (ipaddress.AddressFamily == AddressFamily.InterNetwork) { attempSocket = state.Socket4; } } state.NextAddressIndex = nextAddressIndex; return(ipaddress); }
// Token: 0x0600001C RID: 28 RVA: 0x00009F5C File Offset: 0x0000815C private static void SocketConnectCompleted(object sender, SocketAsyncEventArgs e) { ConnectAsyncExtension.DnsConnectState dnsConnectState = e.UserToken as ConnectAsyncExtension.DnsConnectState; if (e.SocketError == SocketError.Success) { ConnectAsyncExtension.ClearSocketAsyncEventArgs(e); dnsConnectState.Callback((Socket)sender, dnsConnectState.State, e, null); return; } if (e.SocketError != SocketError.HostUnreachable && e.SocketError != SocketError.ConnectionRefused) { ConnectAsyncExtension.ClearSocketAsyncEventArgs(e); dnsConnectState.Callback(null, dnsConnectState.State, e, null); return; } Socket socket; IPAddress nextAddress = ConnectAsyncExtension.GetNextAddress(dnsConnectState, out socket); if (nextAddress == null) { ConnectAsyncExtension.ClearSocketAsyncEventArgs(e); e.SocketError = SocketError.HostUnreachable; dnsConnectState.Callback(null, dnsConnectState.State, e, null); return; } e.RemoteEndPoint = new IPEndPoint(nextAddress, dnsConnectState.Port); if (!socket.ConnectAsync(e)) { ConnectAsyncExtension.SocketConnectCompleted(socket, e); } }
// Token: 0x0600001A RID: 26 RVA: 0x00002282 File Offset: 0x00000482 private static void CreateAttempSocket(ConnectAsyncExtension.DnsConnectState connectState) { if (Socket.OSSupportsIPv6) { connectState.Socket6 = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp); } connectState.Socket4 = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); }
// Token: 0x0600001B RID: 27 RVA: 0x00009E24 File Offset: 0x00008024 private static void OnGetHostAddresses(IAsyncResult result) { ConnectAsyncExtension.DnsConnectState dnsConnectState = result.AsyncState as ConnectAsyncExtension.DnsConnectState; IPAddress[] array; try { array = Dns.EndGetHostAddresses(result); } catch (Exception exception) { dnsConnectState.Callback(null, dnsConnectState.State, null, exception); return; } if (array == null || array.Length == 0) { dnsConnectState.Callback(null, dnsConnectState.State, null, new SocketException(11001)); return; } dnsConnectState.Addresses = array; ConnectAsyncExtension.CreateAttempSocket(dnsConnectState); Socket socket; IPAddress nextAddress = ConnectAsyncExtension.GetNextAddress(dnsConnectState, out socket); if (nextAddress == null) { dnsConnectState.Callback(null, dnsConnectState.State, null, new SocketException(10047)); return; } if (dnsConnectState.LocalEndPoint != null) { try { socket.ExclusiveAddressUse = false; socket.Bind(dnsConnectState.LocalEndPoint); } catch (Exception exception2) { dnsConnectState.Callback(null, dnsConnectState.State, null, exception2); return; } } SocketAsyncEventArgs socketAsyncEventArgs = new SocketAsyncEventArgs(); socketAsyncEventArgs.Completed += ConnectAsyncExtension.SocketConnectCompleted; IPEndPoint remoteEndPoint = new IPEndPoint(nextAddress, dnsConnectState.Port); socketAsyncEventArgs.RemoteEndPoint = remoteEndPoint; socketAsyncEventArgs.UserToken = dnsConnectState; if (!socket.ConnectAsync(socketAsyncEventArgs)) { ConnectAsyncExtension.SocketConnectCompleted(socket, socketAsyncEventArgs); } }