Gracefully handle arp_open failure

This commit is contained in:
dmiller 2026-03-10 18:32:50 +00:00
parent 7f2764927b
commit 5b78ef236e
2 changed files with 21 additions and 14 deletions

View file

@ -769,16 +769,21 @@ bool NpingTarget::determineNextHopMACAddress() {
/* Maybe the system ARP cache will be more helpful */
nping_print(DBG_3," > Checking system's ARP cache...");
a = arp_open();
addr_ston((sockaddr *)&targetss, &ae.arp_pa);
if (arp_get(a, &ae) == 0) {
mac_cache_set(&targetss, ae.arp_ha.addr_eth.data);
this->setNextHopMACAddress(ae.arp_ha.addr_eth.data);
if (a) {
addr_ston((sockaddr *)&targetss, &ae.arp_pa);
if (arp_get(a, &ae) == 0) {
mac_cache_set(&targetss, ae.arp_ha.addr_eth.data);
this->setNextHopMACAddress(ae.arp_ha.addr_eth.data);
arp_close(a);
nping_print(DBG_3," > Success: Entry found [%s]", this->getNextHopMACStr() );
return true;
}
arp_close(a);
nping_print(DBG_3," > Success: Entry found [%s]", this->getNextHopMACStr() );
return true;
nping_print(DBG_3," > No relevant entries found in system's ARP cache.");
}
else {
nping_print(DBG_3," > Failed to open system's ARP cache.");
}
arp_close(a);
nping_print(DBG_3," > No relevant entries found in system's ARP cache.");
/* OK, the last choice is to send our own damn ARP request (and

View file

@ -1663,14 +1663,16 @@ bool getNextHopMAC(const char *iface, const u8 *srcmac, const struct sockaddr_st
/* Maybe the system ARP cache will be more helpful */
a = arp_open();
addr_ston((sockaddr *) dstss, &ae.arp_pa);
if (arp_get(a, &ae) == 0) {
mac_cache_set(dstss, ae.arp_ha.addr_eth.data);
memcpy(dstmac, ae.arp_ha.addr_eth.data, 6);
if (a) {
addr_ston((sockaddr *) dstss, &ae.arp_pa);
if (arp_get(a, &ae) == 0) {
mac_cache_set(dstss, ae.arp_ha.addr_eth.data);
memcpy(dstmac, ae.arp_ha.addr_eth.data, 6);
arp_close(a);
return true;
}
arp_close(a);
return true;
}
arp_close(a);
/* OK, the last choice is to send our own damn ARP request (and
retransmissions if necessary) to determine the MAC */