ofalk / libdnet

libdnet provides a simplified, portable interface to several low-level networking routines.
Other
153 stars 60 forks source link

arp_loop() returns invalid entries #35

Closed gvanem closed 7 months ago

gvanem commented 9 years ago

In ./src/arp-win32.c, arp_loop() will add invalid ARP-entries (because of incomplete ARP requests etc.). Was this intentional? It seems strange to do that (comparing to the arp -a command on Win8.1). The ARP-table now:

dnet.exe arp show
10.0.0.1 at 1c:bd:b9:c0:63:c6   << 
10.0.0.20 at 68:63:59:4e:98:f0
10.0.0.255 at ff:ff:ff:ff:ff:ff
224.0.0.22 at 01:00:5e:00:00:16
224.0.0.252 at 01:00:5e:00:00:fc
239.255.255.250 at 01:00:5e:7f:ff:fa
10.0.0.1 at 00:00:00:00:00:00    << duplicated illegal entry
224.0.0.22 at 01:00:5e:00:00:16

But after my little patch below, it seems better:

10.0.0.1 at 1c:bd:b9:c0:63:c6
10.0.0.20 at 68:63:59:4e:98:f0
10.0.0.255 at ff:ff:ff:ff:ff:ff
224.0.0.22 at 01:00:5e:00:00:16
224.0.0.252 at 01:00:5e:00:00:fc
239.255.255.250 at 01:00:5e:7f:ff:fa
224.0.0.22 at 01:00:5e:00:00:16

No duplicate. Patch:

--- a/src/arp-win32.c 2015-06-25 21:02:17
+++ b/src/arp-win32.c 2015-06-26 14:22:20
@@ -119,6 +119,9 @@
        for (i = 0; i < (int)arp->iptable->dwNumEntries; i++) {
                if (arp->iptable->table[i].dwPhysAddrLen != ETH_ADDR_LEN)
                        continue;
+               if (arp->iptable->table[i].dwType == MIB_IPNET_TYPE_INVALID)
+                       continue;
+
                entry.arp_pa.addr_ip = arp->iptable->table[i].dwAddr;
                memcpy(&entry.arp_ha.addr_eth,
                    arp->iptable->table[i].bPhysAddr, ETH_ADDR_LEN);
gvanem commented 8 months ago

added a commit that referenced this issue on Nov 6, 2023

I do not see any such change was committed for this file. This code:

+    if (arp->iptable->table[i].dwType == MIB_IPNET_TYPE_INVALID)
+                       continue;

is not in master !? So still Dnet is still broken on Windows. Not only this, e.g. a dnet ip src 10.0.0.10 dst 10.0.0.1 proto 17 fails due to a missing WSAStartup().

ofalk commented 7 months ago

There must have been a patch that reverted this change. I'm going to reapply it. Apologies for this, but thanks a lot for spotting and reporting it @gvanem !

ofalk commented 7 months ago

Oh. I know what happened. I've only applied this in the devel branch, but that actually reminded me to start working on merging devel back to the default branch and create a new release with the latest fixes.

ofalk commented 7 months ago

This is going to be fixed in the next release via https://github.com/ofalk/libdnet/pull/96

ofalk commented 7 months ago

Considering this closed with https://github.com/ofalk/libdnet/pull/96/