From b4e536f371a53dd8b25d2d454d029fecf8c955de Mon Sep 17 00:00:00 2001 From: dmiller Date: Wed, 3 Sep 2025 17:04:48 +0000 Subject: [PATCH] Only use eth handle for Ethernet on non-Windows systems. --- libnetutil/netutil.cc | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/libnetutil/netutil.cc b/libnetutil/netutil.cc index 166582568..e7d0783d7 100644 --- a/libnetutil/netutil.cc +++ b/libnetutil/netutil.cc @@ -1019,7 +1019,20 @@ netutil_eth_t *netutil_eth_open(const char *device) { } while (0); #else eth_handle(e) = eth_open(device); - e->datalink = DLT_EN10MB; + if (eth_handle(e)) { + eth_addr_t ea; + /* No guarantees this is Ethernet. Dnet doesn't offer a way to check the L2 + * protocol, so we'll try to get the Ethernet address to confirm. + */ + if (0 == eth_get(eth_handle(e), &ea) && 0 != memcmp(&ea, "\0\0\0\0\0\0", 6)) { + e->datalink = DLT_EN10MB; + } + else { + // Not a data link we know about. + eth_handle_close(eth_handle(e)); + eth_handle(e) = NULL; + } + } #endif if (eth_handle(e) == NULL) {