diff --git a/src/Renci.SshNet/Abstractions/DnsAbstraction.cs b/src/Renci.SshNet/Abstractions/DnsAbstraction.cs
deleted file mode 100644
index 30a10fe87..000000000
--- a/src/Renci.SshNet/Abstractions/DnsAbstraction.cs
+++ /dev/null
@@ -1,107 +0,0 @@
-using System;
-using System.Net;
-using System.Net.Sockets;
-using System.Threading.Tasks;
-
-#if FEATURE_DNS_SYNC
-#elif FEATURE_DNS_APM
-using Renci.SshNet.Common;
-#elif FEATURE_DNS_TAP
-#elif FEATURE_DEVICEINFORMATION_APM
-using System.Collections.Generic;
-using System.Linq;
-using System.Threading;
-using Microsoft.Phone.Net.NetworkInformation;
-#elif FEATURE_DATAGRAMSOCKET
-using System.Collections.Generic;
-using Windows.Networking;
-using Windows.Networking.Sockets;
-#endif
-
-namespace Renci.SshNet.Abstractions
-{
- internal static class DnsAbstraction
- {
- ///
- /// Returns the Internet Protocol (IP) addresses for the specified host.
- ///
- /// The host name or IP address to resolve.
- ///
- /// An array of type that holds the IP addresses for the host that
- /// is specified by the parameter.
- ///
- /// is .
- /// An error is encountered when resolving .
- public static IPAddress[] GetHostAddresses(string hostNameOrAddress)
- {
- /* TODO Eliminate sync variant, and implement timeout */
-
-#if FEATURE_DNS_SYNC
- return Dns.GetHostAddresses(hostNameOrAddress);
-#elif FEATURE_DNS_APM
- var asyncResult = Dns.BeginGetHostAddresses(hostNameOrAddress, null, null);
- if (!asyncResult.AsyncWaitHandle.WaitOne(Session.InfiniteTimeSpan))
- throw new SshOperationTimeoutException("Timeout resolving host name.");
- return Dns.EndGetHostAddresses(asyncResult);
-#elif FEATURE_DNS_TAP
- return Dns.GetHostAddressesAsync(hostNameOrAddress).GetAwaiter().GetResult();
-#else
- IPAddress address;
- if (IPAddress.TryParse(hostNameOrAddress, out address))
- return new [] { address};
-
-#if FEATURE_DEVICEINFORMATION_APM
- var resolveCompleted = new ManualResetEvent(false);
- NameResolutionResult nameResolutionResult = null;
- DeviceNetworkInformation.ResolveHostNameAsync(new DnsEndPoint(hostNameOrAddress, 0), result =>
- {
- nameResolutionResult = result;
- resolveCompleted.Set();
- }, null);
-
- // wait until address is resolved
- resolveCompleted.WaitOne();
-
- if (nameResolutionResult.NetworkErrorCode == NetworkError.Success)
- {
- var addresses = new List(nameResolutionResult.IPEndPoints.Select(p => p.Address).Distinct());
- return addresses.ToArray();
- }
- throw new SocketException((int)nameResolutionResult.NetworkErrorCode);
-#elif FEATURE_DATAGRAMSOCKET
-
- // TODO we may need to only return those IP addresses that are supported on the current system
- // TODO http://wojciechkulik.pl/csharp/winrt-how-to-detect-supported-ip-versions
-
- var endpointPairs = DatagramSocket.GetEndpointPairsAsync(new HostName(hostNameOrAddress), "").GetAwaiter().GetResult();
- var addresses = new List();
- foreach (var endpointPair in endpointPairs)
- {
- if (endpointPair.RemoteHostName.Type == HostNameType.Ipv4 || endpointPair.RemoteHostName.Type == HostNameType.Ipv6)
- addresses.Add(IPAddress.Parse(endpointPair.RemoteHostName.CanonicalName));
- }
- if (addresses.Count == 0)
- throw new SocketException((int) System.Net.Sockets.SocketError.HostNotFound);
- return addresses.ToArray();
-#else
- throw new NotSupportedException("Resolving hostname to IP address is not implemented.");
-#endif // FEATURE_DEVICEINFORMATION_APM
-#endif
- }
-
- ///
- /// Returns the Internet Protocol (IP) addresses for the specified host.
- ///
- /// The host name or IP address to resolve.
- ///
- /// A task with result of an array of type that holds the IP addresses for the host that
- /// is specified by the parameter.
- ///
- /// is .
- /// An error is encountered when resolving .
- public static Task GetHostAddressesAsync(string hostNameOrAddress)
- {
- return Dns.GetHostAddressesAsync(hostNameOrAddress);
- }
- }
-}
diff --git a/src/Renci.SshNet/Abstractions/SocketAbstraction.cs b/src/Renci.SshNet/Abstractions/SocketAbstraction.cs
index f5f840336..b44de4163 100644
--- a/src/Renci.SshNet/Abstractions/SocketAbstraction.cs
+++ b/src/Renci.SshNet/Abstractions/SocketAbstraction.cs
@@ -59,7 +59,6 @@ public static async Task ConnectAsync(Socket socket, IPEndPoint remoteEndpoint,
private static void ConnectCore(Socket socket, IPEndPoint remoteEndpoint, TimeSpan connectTimeout, bool ownsSocket)
{
-#if FEATURE_SOCKET_EAP
var connectCompleted = new ManualResetEvent(initialState: false);
var args = new SocketAsyncEventArgs
{
@@ -113,19 +112,6 @@ private static void ConnectCore(Socket socket, IPEndPoint remoteEndpoint, TimeSp
// dispose SocketAsyncEventArgs
args.Dispose();
-#elif FEATURE_SOCKET_APM
- var connectResult = socket.BeginConnect(remoteEndpoint, null, null);
- if (!connectResult.AsyncWaitHandle.WaitOne(connectTimeout, false))
- throw new SshOperationTimeoutException(string.Format(CultureInfo.InvariantCulture,
- "Connection failed to establish within {0:F0} milliseconds.", connectTimeout.TotalMilliseconds));
- socket.EndConnect(connectResult);
-#elif FEATURE_SOCKET_TAP
- if (!socket.ConnectAsync(remoteEndpoint).Wait(connectTimeout))
- throw new SshOperationTimeoutException(string.Format(CultureInfo.InvariantCulture,
- "Connection failed to establish within {0:F0} milliseconds.", connectTimeout.TotalMilliseconds));
-#else
- #error Connecting to a remote endpoint is not implemented.
-#endif
}
public static void ClearReadBuffer(Socket socket)
@@ -391,12 +377,10 @@ public static bool IsErrorResumable(SocketError socketError)
#pragma warning restore IDE0010 // Add missing cases
}
-#if FEATURE_SOCKET_EAP
private static void ConnectCompleted(object sender, SocketAsyncEventArgs e)
{
var eventWaitHandle = (ManualResetEvent) e.UserToken;
_ = eventWaitHandle?.Set();
}
-#endif // FEATURE_SOCKET_EAP
}
}
diff --git a/src/Renci.SshNet/Connection/ConnectorBase.cs b/src/Renci.SshNet/Connection/ConnectorBase.cs
index 58b45960a..384091b18 100644
--- a/src/Renci.SshNet/Connection/ConnectorBase.cs
+++ b/src/Renci.SshNet/Connection/ConnectorBase.cs
@@ -38,7 +38,7 @@ protected ConnectorBase(ISocketFactory socketFactory)
/// An error occurred trying to establish the connection.
protected Socket SocketConnect(string host, int port, TimeSpan timeout)
{
- var ipAddress = DnsAbstraction.GetHostAddresses(host)[0];
+ var ipAddress = Dns.GetHostAddresses(host)[0];
var ep = new IPEndPoint(ipAddress, port);
DiagnosticAbstraction.Log(string.Format("Initiating connection to '{0}:{1}'.", host, port));
@@ -73,7 +73,12 @@ protected async Task SocketConnectAsync(string host, int port, Cancellat
{
cancellationToken.ThrowIfCancellationRequested();
- var ipAddress = (await DnsAbstraction.GetHostAddressesAsync(host).ConfigureAwait(false))[0];
+#if NET6_0_OR_GREATER
+ var ipAddress = (await Dns.GetHostAddressesAsync(host, cancellationToken).ConfigureAwait(false))[0];
+#else
+ var ipAddress = (await Dns.GetHostAddressesAsync(host).ConfigureAwait(false))[0];
+#endif
+
var ep = new IPEndPoint(ipAddress, port);
DiagnosticAbstraction.Log(string.Format("Initiating connection to '{0}:{1}'.", host, port));
diff --git a/src/Renci.SshNet/Connection/Socks4Connector.cs b/src/Renci.SshNet/Connection/Socks4Connector.cs
index d679c17a3..e3e9800f0 100644
--- a/src/Renci.SshNet/Connection/Socks4Connector.cs
+++ b/src/Renci.SshNet/Connection/Socks4Connector.cs
@@ -1,4 +1,5 @@
using System;
+using System.Net;
using System.Net.Sockets;
using System.Text;
@@ -108,7 +109,7 @@ private static byte[] CreateSocks4ConnectionRequest(string hostname, ushort port
private static byte[] GetSocks4DestinationAddress(string hostname)
{
- var addresses = DnsAbstraction.GetHostAddresses(hostname);
+ var addresses = Dns.GetHostAddresses(hostname);
for (var i = 0; i < addresses.Length; i++)
{
diff --git a/src/Renci.SshNet/Connection/Socks5Connector.cs b/src/Renci.SshNet/Connection/Socks5Connector.cs
index a1ed5f751..ecd286e00 100644
--- a/src/Renci.SshNet/Connection/Socks5Connector.cs
+++ b/src/Renci.SshNet/Connection/Socks5Connector.cs
@@ -1,4 +1,5 @@
using System;
+using System.Net;
using System.Net.Sockets;
using Renci.SshNet.Abstractions;
@@ -243,7 +244,7 @@ private static byte[] CreateSocks5ConnectionRequest(string hostname, ushort port
private static byte[] GetSocks5DestinationAddress(string hostname, out byte addressType)
{
- var ip = DnsAbstraction.GetHostAddresses(hostname)[0];
+ var ip = Dns.GetHostAddresses(hostname)[0];
byte[] address;
diff --git a/src/Renci.SshNet/ForwardedPortDynamic.cs b/src/Renci.SshNet/ForwardedPortDynamic.cs
index 21ab59a20..0c6e417a8 100644
--- a/src/Renci.SshNet/ForwardedPortDynamic.cs
+++ b/src/Renci.SshNet/ForwardedPortDynamic.cs
@@ -159,7 +159,7 @@ private void InternalStart()
var ip = IPAddress.Any;
if (!string.IsNullOrEmpty(BoundHost))
{
- ip = DnsAbstraction.GetHostAddresses(BoundHost)[0];
+ ip = Dns.GetHostAddresses(BoundHost)[0];
}
var ep = new IPEndPoint(ip, (int) BoundPort);
diff --git a/src/Renci.SshNet/ForwardedPortLocal.cs b/src/Renci.SshNet/ForwardedPortLocal.cs
index 72bf08dc7..fce8f7fd7 100644
--- a/src/Renci.SshNet/ForwardedPortLocal.cs
+++ b/src/Renci.SshNet/ForwardedPortLocal.cs
@@ -198,7 +198,7 @@ protected override void Dispose(bool disposing)
private void InternalStart()
{
- var addr = DnsAbstraction.GetHostAddresses(BoundHost)[0];
+ var addr = Dns.GetHostAddresses(BoundHost)[0];
var ep = new IPEndPoint(addr, (int) BoundPort);
_listener = new Socket(ep.AddressFamily, SocketType.Stream, ProtocolType.Tcp) { NoDelay = true };
diff --git a/src/Renci.SshNet/ForwardedPortRemote.cs b/src/Renci.SshNet/ForwardedPortRemote.cs
index 1b4a74eb4..10430abc3 100644
--- a/src/Renci.SshNet/ForwardedPortRemote.cs
+++ b/src/Renci.SshNet/ForwardedPortRemote.cs
@@ -125,9 +125,9 @@ public ForwardedPortRemote(uint boundPort, string host, uint port)
/// The host.
/// The port.
public ForwardedPortRemote(string boundHost, uint boundPort, string host, uint port)
- : this(DnsAbstraction.GetHostAddresses(boundHost)[0],
+ : this(Dns.GetHostAddresses(boundHost)[0],
boundPort,
- DnsAbstraction.GetHostAddresses(host)[0],
+ Dns.GetHostAddresses(host)[0],
port)
{
}
diff --git a/src/Renci.SshNet/Renci.SshNet.csproj b/src/Renci.SshNet/Renci.SshNet.csproj
index 334df5083..adda89ad9 100644
--- a/src/Renci.SshNet/Renci.SshNet.csproj
+++ b/src/Renci.SshNet/Renci.SshNet.csproj
@@ -6,7 +6,7 @@
- $(DefineConstants);FEATURE_BINARY_SERIALIZATION;FEATURE_SOCKET_EAP;FEATURE_SOCKET_APM;FEATURE_DNS_SYNC;FEATURE_HASH_RIPEMD160_CREATE;FEATURE_HMAC_RIPEMD160
+ $(DefineConstants);FEATURE_BINARY_SERIALIZATION;FEATURE_HASH_RIPEMD160_CREATE;FEATURE_HMAC_RIPEMD160
@@ -16,8 +16,4 @@
-
-
- $(DefineConstants);FEATURE_SOCKET_TAP;FEATURE_SOCKET_APM;FEATURE_SOCKET_EAP;FEATURE_DNS_SYNC;FEATURE_DNS_APM;FEATURE_DNS_TAP
-