Fixes bug when trying to use local ip address as host name. (#133)

This commit is contained in:
Kieran Devlin 2022-05-27 09:20:07 +01:00 committed by GitHub
parent 5c4b88c759
commit f8baa1b101
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 6 deletions

View file

@ -60,12 +60,12 @@ namespace SMBLibrary.Client
public bool Connect(string serverName, SMBTransportType transport) public bool Connect(string serverName, SMBTransportType transport)
{ {
IPHostEntry hostEntry = Dns.GetHostEntry(serverName); IPAddress[] hostAddresses = Dns.GetHostAddresses(serverName);
if (hostEntry.AddressList.Length == 0) if (hostAddresses.Length == 0)
{ {
throw new Exception(String.Format("Cannot resolve host name {0} to an IP address", serverName)); throw new Exception(String.Format("Cannot resolve host name {0} to an IP address", serverName));
} }
IPAddress serverAddress = hostEntry.AddressList[0]; IPAddress serverAddress = hostAddresses[0];
return Connect(serverAddress, transport); return Connect(serverAddress, transport);
} }

View file

@ -66,12 +66,12 @@ namespace SMBLibrary.Client
public bool Connect(string serverName, SMBTransportType transport) public bool Connect(string serverName, SMBTransportType transport)
{ {
m_serverName = serverName; m_serverName = serverName;
IPHostEntry hostEntry = Dns.GetHostEntry(serverName); IPAddress[] hostAddresses = Dns.GetHostAddresses(serverName);
if (hostEntry.AddressList.Length == 0) if (hostAddresses.Length == 0)
{ {
throw new Exception(String.Format("Cannot resolve host name {0} to an IP address", serverName)); throw new Exception(String.Format("Cannot resolve host name {0} to an IP address", serverName));
} }
IPAddress serverAddress = hostEntry.AddressList[0]; IPAddress serverAddress = hostAddresses[0];
return Connect(serverAddress, transport); return Connect(serverAddress, transport);
} }