mirror of
https://github.com/nmap/nmap.git
synced 2025-12-06 04:31:29 +00:00
nse_dnet: try raw Ethernet sends if raw sockets don't work, e.g. Windows
This commit is contained in:
30
nse_dnet.cc
30
nse_dnet.cc
@@ -228,9 +228,18 @@ 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();
|
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)",
|
if (o.scriptTrace())
|
||||||
socket_strerror(socket_errno()), socket_errno());
|
{
|
||||||
|
log_write(LOG_STDOUT, "%s: failed to open raw socket: %s (errno %d)", SCRIPT_ENGINE,
|
||||||
|
socket_strerror(socket_errno()), socket_errno());
|
||||||
|
}
|
||||||
|
// If possible, we'll try to use Ethernet headers to send packets, but not
|
||||||
|
// if the user specified --send-ip
|
||||||
|
if (o.sendpref == PACKET_SEND_IP_STRONG) {
|
||||||
|
return luaL_error(L, "Unable to open raw IP socket.");
|
||||||
|
}
|
||||||
|
}
|
||||||
if (o.scriptTrace())
|
if (o.scriptTrace())
|
||||||
{
|
{
|
||||||
log_write(LOG_STDOUT, "%s: raw IP socket open\n", SCRIPT_ENGINE);
|
log_write(LOG_STDOUT, "%s: raw IP socket open\n", SCRIPT_ENGINE);
|
||||||
@@ -264,7 +273,9 @@ static int ip_send (lua_State *L)
|
|||||||
char dev[16];
|
char dev[16];
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (udata->sock == -1)
|
// If possible, we'll try to use Ethernet headers to send packets, but not
|
||||||
|
// if the user specified --send-ip
|
||||||
|
if (udata->sock == -1 && o.sendpref == PACKET_SEND_IP_STRONG)
|
||||||
return luaL_error(L, "raw socket not open to send");
|
return luaL_error(L, "raw socket not open to send");
|
||||||
|
|
||||||
packet = luaL_checklstring(L, 2, &packetlen);
|
packet = luaL_checklstring(L, 2, &packetlen);
|
||||||
@@ -349,11 +360,12 @@ static int ip_send (lua_State *L)
|
|||||||
ret = send_ip_packet(udata->sock, ð, &dst, (u8 *) packet, packetlen);
|
ret = send_ip_packet(udata->sock, ð, &dst, (u8 *) packet, packetlen);
|
||||||
} else {
|
} else {
|
||||||
usesock:
|
usesock:
|
||||||
#ifdef WIN32
|
if (udata->sock == -1) {
|
||||||
if (strlen(dev) > 0)
|
return luaL_error(L, "raw socket not open to send");
|
||||||
win32_fatal_raw_sockets(dev);
|
}
|
||||||
#endif
|
else {
|
||||||
ret = send_ip_packet(udata->sock, NULL, &dst, (u8 *) packet, packetlen);
|
ret = send_ip_packet(udata->sock, NULL, &dst, (u8 *) packet, packetlen);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (ret == -1)
|
if (ret == -1)
|
||||||
return nseU_safeerror(L, "error while sending: %s (errno %d)",
|
return nseU_safeerror(L, "error while sending: %s (errno %d)",
|
||||||
|
|||||||
Reference in New Issue
Block a user