1
0
mirror of https://github.com/nmap/nmap.git synced 2026-02-14 01:16:33 +00:00

Consolidate and improve error checks for missing source MAC. See #2711

This commit is contained in:
dmiller
2026-01-28 21:36:15 +00:00
parent a5b332ccd2
commit c1d16550dc
8 changed files with 61 additions and 49 deletions

View File

@@ -497,6 +497,46 @@ const u8 *Target::NextHopMACAddress() const {
return (NextHopMACaddress_set)? NextHopMACaddress : NULL;
}
eth_nfo *Target::FillEthNfo(eth_nfo *eth, netutil_eth_t *ethsd) const {
assert(eth != NULL);
const char *devname = this->deviceName();
if (devname == NULL) {
return NULL;
}
if (ethsd == NULL) {
ethsd = eth_open_cached(devname);
}
else {
eth->ethsd = ethsd;
}
if (ethsd == NULL) {
error("%s: Failed to open device (%s)", __func__, devname);
return NULL;
}
if (!netutil_eth_can_send(ethsd)) {
error("%s: Cannot send on device (%s)", __func__, devname);
return NULL;
}
if (netutil_eth_datalink(ethsd) == DLT_EN10MB){
const u8 *src_mac = this->SrcMACAddress();
if (src_mac == NULL) {
error("%s: Cannot determine source MAC for %s", __func__, this->targetipstr());
return NULL;
}
const u8 *dst_mac = this->NextHopMACAddress();
if (dst_mac == NULL) {
error("%s: Cannot determine next hop MAC for %s", __func__, this->targetipstr());
return NULL;
}
assert(eth->srcmac != NULL && eth->dstmac != NULL);
memcpy(eth->srcmac, src_mac, 6);
memcpy(eth->dstmac, dst_mac, 6);
}
Strncpy(eth->devname, devname, sizeof(eth->devname));
return eth;
}
int Target::osscanPerformed(void) const {
return osscan_flag;
}