Skip to content

Commit

Permalink
Remove Dns.GetHostentry, it might not return the original IP address (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Arkatufus committed Aug 8, 2022
1 parent d044865 commit 0836f2b
Showing 1 changed file with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using System.Threading;
using System.Threading.Tasks;
using Akka.Actor;
using Akka.Configuration;
using Akka.Discovery.Azure.Model;
using Akka.Event;
using Akka.Util.Internal;
Expand Down Expand Up @@ -123,14 +124,19 @@ private bool Initializing(object message)
case Start _:
try
{
var entry = Dns.GetHostEntry(_settings.HostName);
_host = entry.HostName;
_address = entry.AddressList
.First(i =>
!Equals(i, IPAddress.Any) &&
!Equals(i, IPAddress.Loopback) &&
!Equals(i, IPAddress.IPv6Any) &&
!Equals(i, IPAddress.IPv6Loopback));
if (IPAddress.TryParse(_settings.HostName, out _address))
{
if (_address.Equals(IPAddress.Any) || _address.Equals(IPAddress.IPv6Any))
throw new ConfigurationException($"IPAddress.Any or IPAddress.IPv6Any cannot be used as host address. Was: {_settings.HostName}");

_host = Dns.GetHostName();
}
else
{
_host = _settings.HostName;
_address = Dns.GetHostAddresses(_host)
.First(i => !Equals(i, IPAddress.Any) && !Equals(i, IPAddress.IPv6Any));
}
}
catch (Exception ex)
{
Expand Down

0 comments on commit 0836f2b

Please sign in to comment.