mirror of
https://github.com/nmap/nmap.git
synced 2025-12-06 04:31:29 +00:00
Move win32_fatal_raw_sockets out of nmap_raw_socket.
For the same reason and with the same exception (nse_dnet.cc) as in r30159.
This commit is contained in:
@@ -184,9 +184,12 @@ void FPNetworkControl::init(const char *ifname, devtype iftype) {
|
|||||||
fatal("dnet: failed to open device %s", ifname);
|
fatal("dnet: failed to open device %s", ifname);
|
||||||
this->rawsd = -1;
|
this->rawsd = -1;
|
||||||
} else {
|
} else {
|
||||||
|
#ifdef WIN32
|
||||||
|
win32_fatal_raw_sockets(ifname);
|
||||||
|
#endif
|
||||||
if (this->rawsd >= 0)
|
if (this->rawsd >= 0)
|
||||||
close(this->rawsd);
|
close(this->rawsd);
|
||||||
rawsd = nmap_raw_socket(ifname);
|
rawsd = nmap_raw_socket();
|
||||||
if (rawsd < 0)
|
if (rawsd < 0)
|
||||||
pfatal("Couldn't obtain raw socket in %s", __func__);
|
pfatal("Couldn't obtain raw socket in %s", __func__);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -382,7 +382,10 @@ static void initialize_idleproxy(struct idle_proxy_info *proxy, char *proxyName,
|
|||||||
proxy->rawsd = -1;
|
proxy->rawsd = -1;
|
||||||
proxy->ethptr = &proxy->eth;
|
proxy->ethptr = &proxy->eth;
|
||||||
} else {
|
} else {
|
||||||
proxy->rawsd = nmap_raw_socket(proxy->host.deviceName());
|
#ifdef WIN32
|
||||||
|
win32_fatal_raw_sockets(proxy->host.deviceName());
|
||||||
|
#endif
|
||||||
|
proxy->rawsd = nmap_raw_socket();
|
||||||
if (proxy->rawsd < 0)
|
if (proxy->rawsd < 0)
|
||||||
pfatal("socket troubles in %s", __func__);
|
pfatal("socket troubles in %s", __func__);
|
||||||
unblock_socket(proxy->rawsd);
|
unblock_socket(proxy->rawsd);
|
||||||
|
|||||||
@@ -187,7 +187,7 @@ static int ethernet_send (lua_State *L)
|
|||||||
static int ip_open (lua_State *L)
|
static int ip_open (lua_State *L)
|
||||||
{
|
{
|
||||||
nse_dnet_udata *udata = (nse_dnet_udata *) nseU_checkudata(L, 1, DNET_METATABLE, "dnet");
|
nse_dnet_udata *udata = (nse_dnet_udata *) nseU_checkudata(L, 1, DNET_METATABLE, "dnet");
|
||||||
udata->sock = nmap_raw_socket(NULL);
|
udata->sock = nmap_raw_socket();
|
||||||
if (udata->sock == -1)
|
if (udata->sock == -1)
|
||||||
return luaL_error(L, "failed to open raw socket: %s (errno %d)",
|
return luaL_error(L, "failed to open raw socket: %s (errno %d)",
|
||||||
socket_strerror(socket_errno()), socket_errno());
|
socket_strerror(socket_errno()), socket_errno());
|
||||||
|
|||||||
@@ -1267,7 +1267,10 @@ HostOsScan::HostOsScan(Target *t) {
|
|||||||
fatal("%s: Failed to open ethernet device (%s)", __func__, t->deviceName());
|
fatal("%s: Failed to open ethernet device (%s)", __func__, t->deviceName());
|
||||||
rawsd = -1;
|
rawsd = -1;
|
||||||
} else {
|
} else {
|
||||||
rawsd = nmap_raw_socket(t->deviceName());
|
#ifdef WIN32
|
||||||
|
win32_fatal_raw_sockets(t->deviceName());
|
||||||
|
#endif
|
||||||
|
rawsd = nmap_raw_socket();
|
||||||
if (rawsd < 0)
|
if (rawsd < 0)
|
||||||
pfatal("socket troubles in %s", __func__);
|
pfatal("socket troubles in %s", __func__);
|
||||||
unblock_socket(rawsd);
|
unblock_socket(rawsd);
|
||||||
|
|||||||
@@ -1661,7 +1661,10 @@ void UltraScanInfo::Init(std::vector<Target *> &Targets, struct scan_lists *pts,
|
|||||||
fatal("dnet: Failed to open device %s", Targets[0]->deviceName());
|
fatal("dnet: Failed to open device %s", Targets[0]->deviceName());
|
||||||
rawsd = -1;
|
rawsd = -1;
|
||||||
} else {
|
} else {
|
||||||
rawsd = nmap_raw_socket(Targets[0]->deviceName());
|
#ifdef WIN32
|
||||||
|
win32_fatal_raw_sockets(Targets[0]->deviceName());
|
||||||
|
#endif
|
||||||
|
rawsd = nmap_raw_socket();
|
||||||
if (rawsd < 0)
|
if (rawsd < 0)
|
||||||
pfatal("socket troubles in %s", __func__);
|
pfatal("socket troubles in %s", __func__);
|
||||||
/* We do not wan't to unblock the socket since we want to wait
|
/* We do not wan't to unblock the socket since we want to wait
|
||||||
|
|||||||
12
tcpip.cc
12
tcpip.cc
@@ -139,22 +139,14 @@ static PacketCounter PktCt;
|
|||||||
|
|
||||||
|
|
||||||
/* Create a raw socket and do things that always apply to raw sockets:
|
/* Create a raw socket and do things that always apply to raw sockets:
|
||||||
* Emit a fatal error on Windows.
|
|
||||||
* Set SO_BROADCAST.
|
* Set SO_BROADCAST.
|
||||||
* Set IP_HDRINCL.
|
* Set IP_HDRINCL.
|
||||||
* Bind to an interface with SO_BINDTODEVICE (if o.device is set).
|
* Bind to an interface with SO_BINDTODEVICE (if o.device is set).
|
||||||
The socket is created with address family AF_INET, but may be usable for
|
The socket is created with address family AF_INET, but may be usable for
|
||||||
AF_INET6, depending on the operating system.
|
AF_INET6, depending on the operating system. */
|
||||||
|
int nmap_raw_socket() {
|
||||||
The argument warning_device_name is used *only* in the Windows fatal error
|
|
||||||
message, and does not affect any socket characteristics. The global o.device
|
|
||||||
controls which interface to bind to with SO_BINDTODEVICE. */
|
|
||||||
int nmap_raw_socket(const char *warning_device_name) {
|
|
||||||
int rawsd;
|
int rawsd;
|
||||||
|
|
||||||
#ifdef WIN32
|
|
||||||
win32_fatal_raw_sockets(warning_device_name);
|
|
||||||
#endif
|
|
||||||
rawsd = socket(AF_INET, SOCK_RAW, IPPROTO_RAW);
|
rawsd = socket(AF_INET, SOCK_RAW, IPPROTO_RAW);
|
||||||
if (rawsd < 0)
|
if (rawsd < 0)
|
||||||
return rawsd;
|
return rawsd;
|
||||||
|
|||||||
2
tcpip.h
2
tcpip.h
@@ -200,7 +200,7 @@ extern "C" {
|
|||||||
#define INET_ADDRSTRLEN 16
|
#define INET_ADDRSTRLEN 16
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int nmap_raw_socket(const char *warning_device_name);
|
int nmap_raw_socket();
|
||||||
|
|
||||||
/* Used for tracing all packets sent or received (eg the
|
/* Used for tracing all packets sent or received (eg the
|
||||||
--packet-trace option) */
|
--packet-trace option) */
|
||||||
|
|||||||
@@ -878,7 +878,10 @@ TracerouteState::TracerouteState(std::vector<Target *> &targets) {
|
|||||||
fatal("dnet: failed to open device %s", targets[0]->deviceName());
|
fatal("dnet: failed to open device %s", targets[0]->deviceName());
|
||||||
rawsd = -1;
|
rawsd = -1;
|
||||||
} else {
|
} else {
|
||||||
rawsd = nmap_raw_socket(targets[0]->deviceName());
|
#ifdef WIN32
|
||||||
|
win32_fatal_raw_sockets(targets[0]->deviceName());
|
||||||
|
#endif
|
||||||
|
rawsd = nmap_raw_socket();
|
||||||
if (rawsd < 0)
|
if (rawsd < 0)
|
||||||
pfatal("traceroute: socket troubles");
|
pfatal("traceroute: socket troubles");
|
||||||
ethsd = NULL;
|
ethsd = NULL;
|
||||||
|
|||||||
Reference in New Issue
Block a user