1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-06 04:31:29 +00:00

Merge r5744 from /nmap-exp/david/nmap-massping-migration.

Add a handler for EACCES on initial connect.
This commit is contained in:
david
2007-08-31 05:02:25 +00:00
parent 8c87b5f34b
commit cde0b41cc0
3 changed files with 46 additions and 33 deletions

View File

@@ -115,7 +115,8 @@ class PortList;
/* Possible plural and singular reasons */ /* Possible plural and singular reasons */
char *reason_text[ER_MAX+1]={ char *reason_text[ER_MAX+1]={
"reset", "conn-refused", "syn-ack", "syn-ack", "udp-response", "reset", "conn-refused", "syn-ack", "syn-ack", "udp-response",
"proto-response","net-unreach", "host-unreach", "proto-unreach", "proto-response", "perm-denied",
"net-unreach", "host-unreach", "proto-unreach",
"port-unreach", "echo-reply", "unknown", "unknown", "dest-unreach", "port-unreach", "echo-reply", "unknown", "unknown", "dest-unreach",
"source-quench", "net-prohibited", "host-prohibited", "unknown", "source-quench", "net-prohibited", "host-prohibited", "unknown",
"unknown", "admin-prohibited", "unknown", "time-exceeded", "unknown", "unknown", "unknown", "admin-prohibited", "unknown", "time-exceeded", "unknown", "unknown",
@@ -126,7 +127,8 @@ char *reason_text[ER_MAX+1]={
char *reason_pl_text[ER_MAX+1]={ char *reason_pl_text[ER_MAX+1]={
"resets", "conn-refused", "syn-acks", "syn-acks", "udp-responses", "resets", "conn-refused", "syn-acks", "syn-acks", "udp-responses",
"proto-responses","net-unreaches", "host-unreaches", "proto-unreaches", "proto-responses", "perm-denieds",
"net-unreaches", "host-unreaches", "proto-unreaches",
"port-unreaches", "echo-replies", "unknowns", "unknowns", "dest-unreaches", "port-unreaches", "echo-replies", "unknowns", "unknowns", "dest-unreaches",
"source-quenches", "net-prohibiteds", "host-prohibiteds", "unknowns", "source-quenches", "net-prohibiteds", "host-prohibiteds", "unknowns",
"unknowns", "admin-prohibiteds", "unknowns", "time-exceededs", "unknowns", "unknowns", "admin-prohibiteds", "unknowns", "time-exceededs", "unknowns",

View File

@@ -135,17 +135,18 @@ typedef struct port_reason_summary {
/* portreasons.h:reason_codes and portreasons.cc:reason_str must stay in sync */ /* portreasons.h:reason_codes and portreasons.cc:reason_str must stay in sync */
enum reason_codes { enum reason_codes {
ER_RESETPEER=0, ER_CONREFUSED, ER_CONACCEPT, ER_RESETPEER=0, ER_CONREFUSED, ER_CONACCEPT,
ER_SYNACK, ER_UDPRESPONSE, ER_PROTORESPONSE, ER_SYNACK, ER_UDPRESPONSE, ER_PROTORESPONSE, ER_ACCES, /* 7 */
ER_NETUNREACH, ER_HOSTUNREACH, ER_PROTOUNREACH, ER_NETUNREACH, ER_HOSTUNREACH, ER_PROTOUNREACH,
ER_PORTUNREACH, ER_ECHOREPLY, /* 10 */ ER_PORTUNREACH, ER_ECHOREPLY, /* 11 */
ER_DESTUNREACH=13, ER_SOURCEQUENCH, ER_NETPROHIBITED, ER_DESTUNREACH=14, ER_SOURCEQUENCH, ER_NETPROHIBITED,
ER_HOSTPROHIBITED, ER_ADMINPROHIBITED=19, ER_HOSTPROHIBITED, ER_ADMINPROHIBITED=20,
ER_TIMEEXCCEDED=21, ER_TIMESTAMPREPLY=24, ER_TIMEEXCCEDED=22, ER_TIMESTAMPREPLY=25,
ER_ADDRESSMASKREPLY=28, ER_NOIPIDCHANGE, ER_IPIDCHANGE, ER_ADDRESSMASKREPLY=29, ER_NOIPIDCHANGE, ER_IPIDCHANGE,
ER_ARPRESPONSE, ER_TCPRESPONSE, ER_NORESPONSE, ER_ARPRESPONSE, ER_TCPRESPONSE, ER_NORESPONSE,
ER_LOCALHOST, ER_UNKNOWN, ER_MAX=ER_UNKNOWN /* 36 */ ER_LOCALHOST, ER_UNKNOWN, ER_MAX=ER_UNKNOWN /* 37 */
}; };
/* Be careful to update these values if any ICMP /* Be careful to update these values if any ICMP
@@ -153,8 +154,8 @@ enum reason_codes {
* *
* ICMP ER_* codes are calculated by adding the * ICMP ER_* codes are calculated by adding the
* offsets below to an ICMP packets code/type value */ * offsets below to an ICMP packets code/type value */
#define ER_ICMPCODE_MOD 6 #define ER_ICMPCODE_MOD 7
#define ER_ICMPTYPE_MOD 10 #define ER_ICMPTYPE_MOD 11
/* passed to the print_state_summary. /* passed to the print_state_summary.
* STATE_REASON_EMPTY will append to the current line, prefixed with " because of" * STATE_REASON_EMPTY will append to the current line, prefixed with " because of"

View File

@@ -2438,18 +2438,30 @@ static UltraProbe *sendConnectScanProbe(UltraScanInfo *USI, HostScanStats *hss,
else else
ultrascan_port_probe_update(USI, hss, probeI, PORT_OPEN, &USI->now); ultrascan_port_probe_update(USI, hss, probeI, PORT_OPEN, &USI->now);
probe = NULL; probe = NULL;
} else { } else if (connect_errno == EINPROGRESS || connect_errno == EAGAIN) {
switch(connect_errno) {
case EINPROGRESS:
case EAGAIN:
USI->gstats->CSI->watchSD(CP->sd); USI->gstats->CSI->watchSD(CP->sd);
} else {
int host_state = HOST_UNKNOWN, port_state = PORT_UNKNOWN;
switch(connect_errno) {
/* This can happen on localhost, successful/failing connection immediately
in non-blocking mode. */
case ECONNREFUSED:
host_state = HOST_UP;
port_state = PORT_CLOSED;
hss->target->reason.reason_id = ER_CONREFUSED;
break; break;
case ENETUNREACH: case ENETUNREACH:
if (o.debugging) if (o.debugging)
log_write(LOG_STDOUT, "Got ENETUNREACH from %s connect()\n", __func__); log_write(LOG_STDOUT, "Got ENETUNREACH from %s connect()\n", __func__);
ultrascan_host_probe_update(USI, hss, probeI, HOST_DOWN, &USI->now); host_state = HOST_DOWN;
hss->target->reason.reason_id = ER_NETUNREACH; hss->target->reason.reason_id = ER_NETUNREACH;
probe = NULL; break;
case EACCES:
if (o.debugging)
log_write(LOG_STDOUT, "Got EACCES from %s connect()\n", __func__);
host_state = HOST_DOWN;
hss->target->reason.reason_id = ER_ACCES;
break; break;
default: default:
if (!connecterror) { if (!connecterror) {
@@ -2457,23 +2469,21 @@ static UltraProbe *sendConnectScanProbe(UltraScanInfo *USI, HostScanStats *hss,
fprintf(stderr, "Strange error from connect (%d):", connect_errno); fprintf(stderr, "Strange error from connect (%d):", connect_errno);
fflush(stdout); fflush(stdout);
fflush(stderr); fflush(stderr);
perror(""); /*falling through intentionally*/ perror("");
}
host_state = HOST_DOWN;
hss->target->reason.reason_id = ER_UNKNOWN;
} }
case ECONNREFUSED:
/* This can happen on localhost, successful/failing connection immediately
in non-blocking mode. */
if (probe->isPing()) { if (probe->isPing()) {
ultrascan_ping_update(USI, hss, probeI, &USI->now); ultrascan_ping_update(USI, hss, probeI, &USI->now);
} else if (USI->ping_scan) { } else if (USI->ping_scan && host_state != HOST_UNKNOWN) {
ultrascan_host_probe_update(USI, hss, probeI, HOST_UP, &USI->now); ultrascan_host_probe_update(USI, hss, probeI, host_state, &USI->now);
/* If the host is up, we can forget our other probes. */ if (host_state == HOST_UP)
hss->destroyAllOutstandingProbes(); hss->destroyAllOutstandingProbes();
} else { } else if (!USI->ping_scan && port_state != PORT_UNKNOWN) {
ultrascan_port_probe_update(USI, hss, probeI, PORT_CLOSED, &USI->now); ultrascan_port_probe_update(USI, hss, probeI, port_state, &USI->now);
} }
probe = NULL; probe = NULL;
break;
}
} }
gettimeofday(&USI->now, NULL); gettimeofday(&USI->now, NULL);
return probe; return probe;