Skip to content

Commit

Permalink
SOCK4: search all host addresses for the first IPv4 address.
Browse files Browse the repository at this point in the history
  • Loading branch information
drieseng committed Jul 30, 2018
1 parent cfd4125 commit 07e142c
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/Renci.SshNet/Session.cs
Original file line number Diff line number Diff line change
Expand Up @@ -954,7 +954,7 @@ internal void SendMessage(Message message)
hash = _clientMac.ComputeHash(packetData);
}

// Encrypt packet data
// Encrypt packet data
if (_clientCipher != null)
{
packetData = _clientCipher.Encrypt(packetData, packetDataOffset, (packetData.Length - packetDataOffset));
Expand Down Expand Up @@ -1952,9 +1952,9 @@ private void MessageListener()
break;
}
#elif FEATURE_SOCKET_POLL
// when Socket.Select(IList, IList, IList, Int32) is not available or is buggy, we use
// Socket.Poll(Int, SelectMode) to block until either data is available or the socket
// is closed
// when Socket.Select(IList, IList, IList, Int32) is not available or is buggy, we use
// Socket.Poll(Int, SelectMode) to block until either data is available or the socket
// is closed
_socket.Poll(-1, SelectMode.SelectRead);

if (!_socket.IsConnected())
Expand Down Expand Up @@ -2271,14 +2271,16 @@ private static byte[] CreateSocks5ConnectionRequest(string hostname, ushort port

private static byte[] GetSocks4DestinationAddress(string hostname)
{
var ip = DnsAbstraction.GetHostAddresses(hostname)[0];
var addresses = DnsAbstraction.GetHostAddresses(hostname);

if (ip.AddressFamily != AddressFamily.InterNetwork)
for (var i = 0; i < addresses.Length; i++)
{
throw new ProxyException("SOCKS4 only supports IPv4.");
var address = addresses[i];
if (address.AddressFamily == AddressFamily.InterNetwork)
return address.GetAddressBytes();
}

return ip.GetAddressBytes();
throw new ProxyException(string.Format("SOCKS4 only supports IPv4. No such address found for '{0}'.", hostname));
}

private static byte[] GetSocks5DestinationAddress(string hostname, out byte addressType)
Expand Down Expand Up @@ -2442,7 +2444,7 @@ private void Reset()
private static SshConnectionException CreateConnectionAbortedByServerException()
{
return new SshConnectionException("An established connection was aborted by the server.",
DisconnectReason.ConnectionLost);
DisconnectReason.ConnectionLost);
}

#region IDisposable implementation
Expand Down

0 comments on commit 07e142c

Please sign in to comment.