Skip to content

Commit ddc7f37

Browse files
committed
The call to Dns.GetHostEntry() may fail on MacOS
... only ever seen there.
1 parent 55a4ec0 commit ddc7f37

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/devices/Nmea0183/NmeaUdpServer.cs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -255,14 +255,22 @@ public override int Read(byte[] buffer, int offset, int count)
255255
}
256256

257257
// Check whether the given address is ours (new IPs can be added at runtime, if interfaces go up)
258-
var host = Dns.GetHostEntry(Dns.GetHostName());
259-
if (host.AddressList.Contains(pt.Address))
258+
try
260259
{
261-
_knownSenders.Add(pt.Address, true);
260+
var host = Dns.GetHostEntry(Dns.GetHostName());
261+
if (host.AddressList.Contains(pt.Address))
262+
{
263+
_knownSenders.Add(pt.Address, true);
264+
}
265+
else
266+
{
267+
_knownSenders.Add(pt.Address, false);
268+
}
262269
}
263-
else
270+
catch (SocketException x)
264271
{
265-
_knownSenders.Add(pt.Address, false);
272+
// Dns.GetHostEntry() sometimes throws a SocketException, but only on MacOS.
273+
_parent.FireOnParserError($"Unable to get DNS entry for Host, possibly disconnected?. Error: {x.Message}", NmeaError.None);
266274
}
267275
}
268276

0 commit comments

Comments
 (0)