mirror of
https://github.com/nmap/nmap.git
synced 2025-12-07 05:01:29 +00:00
Consolidate raw socket acquisition.
This commit is contained in:
@@ -949,39 +949,15 @@ void UltraScanInfo::Init(std::vector<Target *> &Targets, const struct scan_lists
|
||||
aren't doing a TCP connect scan, or if we're doing a ping scan that
|
||||
requires it. */
|
||||
if (isRawScan()) {
|
||||
const char *device = Targets[0]->deviceName();
|
||||
if (ping_scan_arp || (ping_scan_nd && o.sendpref != PACKET_SEND_IP_STRONG) || (o.sendpref & PACKET_SEND_ETH)) {
|
||||
/* We'll send ethernet packets with dnet */
|
||||
ethsd = eth_open_cached(device);
|
||||
if (ethsd == NULL) {
|
||||
error("dnet: Failed to open device %s", device);
|
||||
}
|
||||
else if (!netutil_eth_can_send(ethsd)) {
|
||||
ethsd = NULL;
|
||||
}
|
||||
/* If eth failed, we can fall back to raw socket. The only exception is
|
||||
* ARP ping, which needs Ethernet link. */
|
||||
if (ping_scan_arp && (ethsd == NULL || netutil_eth_datalink(ethsd) != DLT_EN10MB)) {
|
||||
fatal("ARP ping not supported on %s", device);
|
||||
}
|
||||
/* If eth failed, we can fall back to raw socket. The only exception is
|
||||
* ARP ping, which needs Ethernet link. */
|
||||
int sendpref = o.sendpref;
|
||||
if (ping_scan_arp) {
|
||||
assert(!(sendpref & PACKET_SEND_IP_STRONG));
|
||||
sendpref = PACKET_SEND_ETH;
|
||||
}
|
||||
if (ethsd == NULL) {
|
||||
#ifdef WIN32
|
||||
win32_fatal_raw_sockets(Targets[0]->deviceName());
|
||||
#endif
|
||||
rawsd = nmap_raw_socket();
|
||||
if (rawsd < 0)
|
||||
pfatal("Couldn't open a raw socket. "
|
||||
#if defined(sun) && defined(__SVR4)
|
||||
"In Solaris shared-IP non-global zones, this requires the PRIV_NET_RAWACCESS privilege. "
|
||||
#endif
|
||||
"Error"
|
||||
);
|
||||
/* We do not want to unblock the socket since we want to wait
|
||||
if kernel send buffers fill up rather than get ENOBUF, and
|
||||
we won't be receiving on the socket anyway
|
||||
unblock_socket(rawsd);*/
|
||||
ethsd = NULL;
|
||||
if (!raw_socket_or_eth(sendpref, Targets[0]->deviceName(), &rawsd, ðsd)) {
|
||||
fatal("Couldn't open a raw socket or eth handle.");
|
||||
}
|
||||
/* Raw scan types also need to know the source IP. */
|
||||
Targets[0]->SourceSockAddr(&sourceSockAddr, NULL);
|
||||
|
||||
Reference in New Issue
Block a user