mirror of
https://github.com/nmap/nmap.git
synced 2025-12-06 04:31:29 +00:00
Consolidate raw socket acquisition.
This commit is contained in:
31
FPEngine.cc
31
FPEngine.cc
@@ -118,7 +118,7 @@ FPNetworkControl::~FPNetworkControl() {
|
||||
|
||||
/* (Re)-Initialize object's state (default parameter setup and nsock
|
||||
* initialization). */
|
||||
void FPNetworkControl::init(const char *ifname, devtype iftype) {
|
||||
void FPNetworkControl::init(const char *ifname) {
|
||||
|
||||
/* Init congestion control parameters */
|
||||
this->cc_init();
|
||||
@@ -155,27 +155,14 @@ void FPNetworkControl::init(const char *ifname, devtype iftype) {
|
||||
/* Flag it as already initialized so we free this nsp next time */
|
||||
this->nsock_init = true;
|
||||
|
||||
/* We don't need to store the eth handle because FPProbes come with a
|
||||
* suitable one (FPProbes::getEthernet()), we just attempt to obtain one
|
||||
* to see if it fails. */
|
||||
netutil_eth_t *ethsd = NULL;
|
||||
|
||||
/* Obtain raw socket or check that we can obtain an eth descriptor. */
|
||||
if ((o.sendpref & PACKET_SEND_ETH) && (iftype == devt_ethernet
|
||||
#ifdef WIN32
|
||||
|| (o.have_pcap && iftype == devt_loopback)
|
||||
#endif
|
||||
) && ifname != NULL) {
|
||||
/* We don't need to store the eth handler because FPProbes come with a
|
||||
* suitable one (FPProbes::getEthernet()), we just attempt to obtain one
|
||||
* to see if it fails. */
|
||||
if (eth_open_cached(ifname) == NULL)
|
||||
fatal("dnet: failed to open device %s", ifname);
|
||||
this->rawsd = -1;
|
||||
} else {
|
||||
#ifdef WIN32
|
||||
win32_fatal_raw_sockets(ifname);
|
||||
#endif
|
||||
if (this->rawsd >= 0)
|
||||
close(this->rawsd);
|
||||
rawsd = nmap_raw_socket();
|
||||
if (rawsd < 0)
|
||||
pfatal("Couldn't obtain raw socket in %s", __func__);
|
||||
if (!raw_socket_or_eth(o.sendpref, ifname, &this->rawsd, ðsd)) {
|
||||
fatal("Couldn't obtain raw socket or eth handle in %s", __func__);
|
||||
}
|
||||
|
||||
/* De-register existing callers */
|
||||
@@ -1135,7 +1122,7 @@ int FPEngine6::os_scan(std::vector<Target *> &Targets) {
|
||||
|
||||
/* Initialize variables, timers, etc. */
|
||||
gettimeofday(&begin_time, NULL);
|
||||
global_netctl.init(Targets[0]->deviceName(), Targets[0]->ifType());
|
||||
global_netctl.init(Targets[0]->deviceName());
|
||||
for (size_t i = 0; i < Targets.size(); i++) {
|
||||
if (o.debugging > 3) {
|
||||
log_write(LOG_PLAIN, "[FPEngine] Allocating FPHost6 for %s %s\n",
|
||||
|
||||
Reference in New Issue
Block a user