Skip to content

Commit

Permalink
The call to Dns.GetHostEntry() may fail on MacOS
Browse files Browse the repository at this point in the history
... only ever seen there.
  • Loading branch information
pgrawehr committed Sep 18, 2022
1 parent 55a4ec0 commit ddc7f37
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/devices/Nmea0183/NmeaUdpServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -255,14 +255,22 @@ public override int Read(byte[] buffer, int offset, int count)
}

// Check whether the given address is ours (new IPs can be added at runtime, if interfaces go up)
var host = Dns.GetHostEntry(Dns.GetHostName());
if (host.AddressList.Contains(pt.Address))
try
{
_knownSenders.Add(pt.Address, true);
var host = Dns.GetHostEntry(Dns.GetHostName());
if (host.AddressList.Contains(pt.Address))
{
_knownSenders.Add(pt.Address, true);
}
else
{
_knownSenders.Add(pt.Address, false);
}
}
else
catch (SocketException x)
{
_knownSenders.Add(pt.Address, false);
// Dns.GetHostEntry() sometimes throws a SocketException, but only on MacOS.
_parent.FireOnParserError($"Unable to get DNS entry for Host, possibly disconnected?. Error: {x.Message}", NmeaError.None);
}
}

Expand Down

0 comments on commit ddc7f37

Please sign in to comment.