Skip to content

Commit

Permalink
Fix: Server endpoints are not returned if GetHostEntry fails. (#1639)
Browse files Browse the repository at this point in the history
Fix: Server endpoints are not returned if GetHostEntry fails.

* User had issues with DNS server which caused Dns.GetHostEntry to throw SocketExceptions.
* It caused that OPC UA servers couldn't return their endpoints to remote machines.
* fix catches the SocketExceptions on Dns.GetHostEntry.
  • Loading branch information
MD-V committed Dec 17, 2021
1 parent a147eb5 commit bcc573a
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions Stack/Opc.Ua.Core/Stack/Server/ServerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -888,13 +888,25 @@ protected string NormalizeHostname(string hostname)
}

// check for aliases.
System.Net.IPHostEntry entry = System.Net.Dns.GetHostEntry(computerName);
IPHostEntry entry = null;

for (int ii = 0; ii < entry.Aliases.Length; ii++)
try
{
entry = Dns.GetHostEntry(computerName);
}
catch (System.Net.Sockets.SocketException e)
{
Utils.LogError(e, "Unable to check aliases for hostname {0}.", computerName);
}

if (entry != null)
{
if (Utils.AreDomainsEqual(hostname, entry.Aliases[ii]))
for (int ii = 0; ii < entry.Aliases.Length; ii++)
{
return computerName.ToUpper();
if (Utils.AreDomainsEqual(hostname, entry.Aliases[ii]))
{
return computerName.ToUpper();
}
}
}

Expand Down

0 comments on commit bcc573a

Please sign in to comment.