diff --git a/NmapOps.cc b/NmapOps.cc index 5fa73fafd..5d5e59135 100644 --- a/NmapOps.cc +++ b/NmapOps.cc @@ -297,15 +297,15 @@ void NmapOps::Initialize() { min_packet_send_rate = 0.0; /* Unset. */ max_packet_send_rate = 0.0; /* Unset. */ stats_interval = 0.0; /* Unset. */ - randomize_hosts = 0; - randomize_ports = 1; + randomize_hosts = false; + randomize_ports = true; sendpref = PACKET_SEND_NOPREF; - spoofsource = 0; - fastscan = 0; + spoofsource = false; + fastscan = false; device[0] = '\0'; ping_group_sz = PING_GROUP_SZ; - nogcc = 0; - generate_random_ips = 0; + nogcc = false; + generate_random_ips = false; reference_FPs = NULL; magic_port = 33000 + (get_random_uint() % 31000); magic_port_set = false; @@ -328,28 +328,28 @@ void NmapOps::Initialize() { scan_delay = 0; open_only = false; scanflags = -1; - defeat_rst_ratelimit = 0; - defeat_icmp_ratelimit = 0; + defeat_rst_ratelimit = false; + defeat_icmp_ratelimit = false; resume_ip.s_addr = 0; - osscan_limit = 0; - osscan_guess = 0; + osscan_limit = false; + osscan_guess = false; numdecoys = 0; decoyturn = -1; - osscan = 0; - servicescan = 0; - override_excludeports = 0; + osscan = false; + servicescan = false; + override_excludeports = false; version_intensity = 7; pingtype = PINGTYPE_UNKNOWN; - listscan = allowall = ackscan = bouncescan = connectscan = 0; + listscan = ackscan = bouncescan = connectscan = 0; nullscan = xmasscan = fragscan = synscan = windowscan = 0; maimonscan = idlescan = finscan = udpscan = ipprotscan = 0; - noportscan = noresolve = 0; + noportscan = noresolve = false; sctpinitscan = 0; sctpcookieechoscan = 0; - append_output = 0; + append_output = false; memset(logfd, 0, sizeof(FILE *) * LOG_NUM_FILES); ttl = -1; - badsum = 0; + badsum = false; nmap_stdout = stdout; gettimeofday(&start_time, NULL); pTrace = vTrace = false; @@ -379,11 +379,11 @@ void NmapOps::Initialize() { release_memory = false; topportlevel = -1; #ifndef NOLUA - script = 0; + script = false; scriptargs = NULL; - scriptversion = 0; - scripttrace = 0; - scriptupdatedb = 0; + scriptversion = false; + scripttrace = false; + scriptupdatedb = false; scripthelp = false; scripttimeout = 0; chosenScripts.clear(); @@ -546,16 +546,16 @@ administrator privileges."; if (osscan && ipprotscan) { error("WARNING: Disabling OS Scan (-O) as it is incompatible with the IPProto Scan (-sO)"); - osscan = 0; + osscan = false; } if (servicescan && ipprotscan) { error("WARNING: Disabling Service Scan (-sV) as it is incompatible with the IPProto Scan (-sO)"); - servicescan = 0; + servicescan = false; } if (servicescan && noportscan) - servicescan = 0; + servicescan = false; if (defeat_rst_ratelimit && !synscan && !openOnly()) { fatal("Option --defeat-rst-ratelimit works only with a SYN scan (-sS)"); @@ -580,7 +580,7 @@ administrator privileges."; fatal("--min-rate=%g must be less than or equal to --max-rate=%g", min_packet_send_rate, max_packet_send_rate); } - if (af() == AF_INET6 && (generate_random_ips|bouncescan|fragscan)) { + if (af() == AF_INET6 && (generate_random_ips||bouncescan||fragscan)) { fatal("Random targets, FTP bounce scan, and fragmentation are not supported with IPv6."); } diff --git a/NmapOps.h b/NmapOps.h index 34f93a7eb..22873a1be 100644 --- a/NmapOps.h +++ b/NmapOps.h @@ -228,14 +228,14 @@ class NmapOps { float max_packet_send_rate; /* The requested auto stats printing interval, or 0.0 if unset. */ float stats_interval; - int randomize_hosts; - int randomize_ports; - int spoofsource; /* -S used */ - int fastscan; + bool randomize_hosts; + bool randomize_ports; + bool spoofsource; /* -S used */ + bool fastscan; char device[64]; int ping_group_sz; - int nogcc; /* Turn off group congestion control with --nogcc */ - int generate_random_ips; /* -iR option */ + bool nogcc; /* Turn off group congestion control with --nogcc */ + bool generate_random_ips; /* -iR option */ FingerPrintDB *reference_FPs; /* Used in the new OS scan system. */ std::vector os_labels_ipv6; u16 magic_port; /* The source port set by -g or --source-port. */ @@ -308,11 +308,11 @@ class NmapOps { FIN scan into a PSH scan. Sort of a hack, but can be very useful sometimes. */ - int defeat_rst_ratelimit; /* Solaris 9 rate-limits RSTs so scanning is very + bool defeat_rst_ratelimit; /* Solaris 9 rate-limits RSTs so scanning is very slow against it. If we don't distinguish between closed and filtered ports, we can get the list of open ports very fast */ - int defeat_icmp_ratelimit; /* If a host rate-limits ICMP responses, then scanning + bool defeat_icmp_ratelimit; /* If a host rate-limits ICMP responses, then scanning is very slow against it. This option prevents Nmap to adjust timing when it changes the port's state because of ICMP response, as the latter might be rate-limited. Doing so we can get scan results faster. */ @@ -324,19 +324,18 @@ class NmapOps { to 0. */ // Version Detection Options - int override_excludeports; + bool override_excludeports; int version_intensity; struct sockaddr_storage decoys[MAX_DECOYS]; - int osscan_limit; /* Skip OS Scan if no open or no closed TCP ports */ - int osscan_guess; /* Be more aggressive in guessing OS type */ + bool osscan_limit; /* Skip OS Scan if no open or no closed TCP ports */ + bool osscan_guess; /* Be more aggressive in guessing OS type */ int numdecoys; int decoyturn; - int osscan; - int servicescan; + bool osscan; + bool servicescan; int pingtype; int listscan; - int allowall; int fragscan; /* 0 or MTU (without IPv4 header size) */ int ackscan; int bouncescan; @@ -353,13 +352,13 @@ class NmapOps { int sctpcookieechoscan; int windowscan; int xmasscan; - int noresolve; - int noportscan; - int append_output; /* Append to any output files rather than overwrite */ + bool noresolve; + bool noportscan; + bool append_output; /* Append to any output files rather than overwrite */ FILE *logfd[LOG_NUM_FILES]; FILE *nmap_stdout; /* Nmap standard output */ int ttl; // Time to live - int badsum; + bool badsum; char *datadir; /* A map from abstract data file names like "nmap-services" and "nmap-os-db" to paths which have been requested by the user. nmap_fetchfile will return @@ -398,12 +397,12 @@ class NmapOps { nsock_proxychain proxy_chain; #ifndef NOLUA - int script; + bool script; char *scriptargs; char *scriptargsfile; - int scriptversion; - int scripttrace; - int scriptupdatedb; + bool scriptversion; + bool scripttrace; + bool scriptupdatedb; bool scripthelp; double scripttimeout; void chooseScripts(char* argument); diff --git a/nmap.cc b/nmap.cc index 9a0b2b2c3..d0c1e1b45 100644 --- a/nmap.cc +++ b/nmap.cc @@ -735,16 +735,16 @@ void parse_options(int argc, char **argv) { case 0: #ifndef NOLUA if (strcmp(long_options[option_index].name, "script") == 0) { - o.script = 1; + o.script = true; o.chooseScripts(optarg); } else if (optcmp(long_options[option_index].name, "script-args") == 0) { o.scriptargs = strdup(optarg); } else if (optcmp(long_options[option_index].name, "script-args-file") == 0) { o.scriptargsfile = strdup(optarg); } else if (optcmp(long_options[option_index].name, "script-trace") == 0) { - o.scripttrace = 1; + o.scripttrace = true; } else if (optcmp(long_options[option_index].name, "script-updatedb") == 0) { - o.scriptupdatedb = 1; + o.scriptupdatedb = true; } else if (optcmp(long_options[option_index].name, "script-help") == 0) { o.scripthelp = true; o.chooseScripts(optarg); @@ -796,7 +796,7 @@ void parse_options(int argc, char **argv) { } else if (strcmp(long_options[option_index].name, "open") == 0) { o.setOpenOnly(true); // If they only want open, don't spend extra time (potentially) distinguishing closed from filtered. - o.defeat_rst_ratelimit = 1; + o.defeat_rst_ratelimit = true; } else if (strcmp(long_options[option_index].name, "scanflags") == 0) { o.scanflags = parse_scanflags(optarg); if (o.scanflags < 0) { @@ -805,7 +805,7 @@ void parse_options(int argc, char **argv) { } else if (strcmp(long_options[option_index].name, "iflist") == 0) { delayed_options.iflist = true; } else if (strcmp(long_options[option_index].name, "nogcc") == 0) { - o.nogcc = 1; + o.nogcc = true; } else if (optcmp(long_options[option_index].name, "release-memory") == 0) { o.release_memory = true; } else if (optcmp(long_options[option_index].name, "min-parallelism") == 0) { @@ -831,11 +831,11 @@ void parse_options(int argc, char **argv) { o.datadir = strdup(optarg); } else if (strcmp(long_options[option_index].name, "servicedb") == 0) { o.requested_data_files["nmap-services"] = optarg; - o.fastscan++; + o.fastscan = true; } else if (strcmp(long_options[option_index].name, "versiondb") == 0) { o.requested_data_files["nmap-service-probes"] = optarg; } else if (optcmp(long_options[option_index].name, "append-output") == 0) { - o.append_output = 1; + o.append_output = true; } else if (strcmp(long_options[option_index].name, "noninteractive") == 0) { o.noninteractive = true; } else if (optcmp(long_options[option_index].name, "spoof-mac") == 0) { @@ -843,7 +843,7 @@ void parse_options(int argc, char **argv) { files set up, --datadir, etc. */ delayed_options.spoofmac = optarg; } else if (strcmp(long_options[option_index].name, "allports") == 0) { - o.override_excludeports = 1; + o.override_excludeports = true; } else if (optcmp(long_options[option_index].name, "version-intensity") == 0) { o.version_intensity = atoi(optarg); if (o.version_intensity < 0 || o.version_intensity > 9) @@ -860,9 +860,9 @@ void parse_options(int argc, char **argv) { fatal("Since April 2010, the default unit for --scan-delay is seconds, so your time of \"%s\" is %.1f minutes. Use \"%sms\" for %g milliseconds.", optarg, l / 1000.0 / 60, optarg, l / 1000.0); delayed_options.pre_scan_delay = l; } else if (optcmp(long_options[option_index].name, "defeat-rst-ratelimit") == 0) { - o.defeat_rst_ratelimit = 1; + o.defeat_rst_ratelimit = true; } else if (optcmp(long_options[option_index].name, "defeat-icmp-ratelimit") == 0) { - o.defeat_icmp_ratelimit = 1; + o.defeat_icmp_ratelimit = true; } else if (optcmp(long_options[option_index].name, "max-scan-delay") == 0) { l = tval2msecs(optarg); if (l < 0) @@ -876,7 +876,7 @@ void parse_options(int argc, char **argv) { fatal("max-retries must be positive"); } else if (optcmp(long_options[option_index].name, "randomize-hosts") == 0 || strcmp(long_options[option_index].name, "rH") == 0) { - o.randomize_hosts = 1; + o.randomize_hosts = true; o.ping_group_sz = PING_GROUP_SZ * 4; } else if (optcmp(long_options[option_index].name, "nsock-engine") == 0) { if (nsock_set_default_engine(optarg) < 0) @@ -885,14 +885,14 @@ void parse_options(int argc, char **argv) { if (nsock_proxychain_new(optarg, &o.proxy_chain, NULL) < 0) fatal("Invalid proxy chain specification"); } else if (optcmp(long_options[option_index].name, "osscan-limit") == 0) { - o.osscan_limit = 1; + o.osscan_limit = true; } else if (optcmp(long_options[option_index].name, "osscan-guess") == 0 || strcmp(long_options[option_index].name, "fuzzy") == 0) { - o.osscan_guess = 1; + o.osscan_guess = true; } else if (optcmp(long_options[option_index].name, "packet-trace") == 0) { o.setPacketTrace(true); #ifndef NOLUA - o.scripttrace = 1; + o.scripttrace = true; #endif } else if (optcmp(long_options[option_index].name, "version-trace") == 0) { o.setVersionTrace(true); @@ -982,7 +982,7 @@ void parse_options(int argc, char **argv) { log_write(LOG_STDOUT, "!!Greets to Van Hauser, Plasmoid, Skyper and the rest of THC!!\n"); exit(0); } else if (strcmp(long_options[option_index].name, "badsum") == 0) { - o.badsum = 1; + o.badsum = true; } else if (strcmp(long_options[option_index].name, "iL") == 0) { if (o.inputfd) { fatal("Only one input filename allowed"); @@ -996,7 +996,7 @@ void parse_options(int argc, char **argv) { } } } else if (strcmp(long_options[option_index].name, "iR") == 0) { - o.generate_random_ips = 1; + o.generate_random_ips = true; o.max_ips_to_scan = strtoul(optarg, &endptr, 10); if (*endptr != '\0') { fatal("ERROR: -iR argument must be the maximum number of random IPs you wish to scan (use 0 for unlimited)"); @@ -1121,7 +1121,7 @@ void parse_options(int argc, char **argv) { Strncpy(o.device, optarg, sizeof(o.device)); break; case 'F': - o.fastscan++; + o.fastscan = true; break; case 'f': o.fragscan += 8; @@ -1171,11 +1171,11 @@ void parse_options(int argc, char **argv) { delayed_options.machinefilename = logfilename(optarg, local_time); break; case 'n': - o.noresolve++; + o.noresolve = true; break; case 'O': if (!optarg || *optarg == '2') - o.osscan++; + o.osscan = true; else if (*optarg == '1') fatal("First-generation OS detection (-O1) is no longer supported. Use -O instead."); else @@ -1290,13 +1290,13 @@ void parse_options(int argc, char **argv) { o.always_resolve = true; break; case 'r': - o.randomize_ports = 0; + o.randomize_ports = false; break; case 'S': if (o.spoofsource) fatal("You can only use the source option once! Use -D -D etc. for decoys\n"); delayed_options.spoofSource = strdup(optarg); - o.spoofsource = 1; + o.spoofsource = true; break; case 's': if (!*optarg) { @@ -1310,25 +1310,25 @@ void parse_options(int argc, char **argv) { case 'P': delayed_options.warn_deprecated("sP", "sn"); case 'n': - o.noportscan = 1; + o.noportscan = true; break; case 'A': - o.ackscan = 1; + o.ackscan = true; break; case 'B': fatal("No scan type 'B', did you mean bounce scan (-b)?"); break; #ifndef NOLUA case 'C': - o.script = 1; + o.script = true; break; #endif case 'F': o.finscan = 1; break; case 'L': - o.listscan = 1; - o.noportscan = 1; + o.listscan = true; + o.noportscan = true; o.pingtype |= PINGTYPE_NONE; break; case 'M': @@ -1342,7 +1342,7 @@ void parse_options(int argc, char **argv) { break; /* Alias for -sV since March 2011. */ case 'R': - o.servicescan = 1; + o.servicescan = true; delayed_options.warn_deprecated("sR", "sV"); error("WARNING: -sR is now an alias for -sV and activates version detection as well as RPC scan."); break; @@ -1356,7 +1356,7 @@ void parse_options(int argc, char **argv) { o.udpscan++; break; case 'V': - o.servicescan = 1; + o.servicescan = true; break; case 'W': o.windowscan = 1; @@ -1469,10 +1469,10 @@ void apply_delayed_options() { if (delayed_options.advanced) { o.servicescan = true; #ifndef NOLUA - o.script = 1; + o.script = true; #endif if (o.isr00t) { - o.osscan++; + o.osscan = true; o.traceroute = true; } } @@ -2033,7 +2033,7 @@ int nmap_main(int argc, char *argv[]) { o.max_ips_to_scan = o.numhosts_scanned; // disable warnings? } if (o.servicescan) - o.scriptversion = 1; + o.scriptversion = true; if (o.scriptversion || o.script || o.scriptupdatedb) open_nse(); diff --git a/nse_main.cc b/nse_main.cc index a3b5f0118..b49e95c6c 100644 --- a/nse_main.cc +++ b/nse_main.cc @@ -378,9 +378,9 @@ static void open_cnse (lua_State *L) luaL_newlib(L, nse); /* Add some other fields */ - nseU_setbfield(L, -1, "default", o.script == 1); - nseU_setbfield(L, -1, "scriptversion", o.scriptversion == 1); - nseU_setbfield(L, -1, "scriptupdatedb", o.scriptupdatedb == 1); + nseU_setbfield(L, -1, "default", o.script); + nseU_setbfield(L, -1, "scriptversion", o.scriptversion); + nseU_setbfield(L, -1, "scriptupdatedb", o.scriptupdatedb); nseU_setbfield(L, -1, "scripthelp", o.scripthelp); nseU_setsfield(L, -1, "script_dbpath", SCRIPT_ENGINE_DATABASE); nseU_setsfield(L, -1, "scriptargs", o.scriptargs); diff --git a/output.cc b/output.cc index df380827e..531176218 100644 --- a/output.cc +++ b/output.cc @@ -1112,9 +1112,9 @@ void log_flush_all() { } /* Open a log descriptor of the type given to the filename given. If - append is nonzero, the file will be appended instead of clobbered if + append is true, the file will be appended instead of clobbered if it already exists. If the file does not exist, it will be created */ -int log_open(int logt, int append, char *filename) { +int log_open(int logt, bool append, char *filename) { int i = 0; if (logt <= 0 || logt > LOG_FILE_MASK) return -1; @@ -2534,7 +2534,7 @@ void printfinaloutput() { if (o.numhosts_scanned == 0 #ifndef NOLUA - && o.scriptupdatedb == 0 + && !o.scriptupdatedb #endif ) error("WARNING: No targets were specified, so 0 hosts scanned."); diff --git a/output.h b/output.h index 04f41c8f2..9d97d01d8 100644 --- a/output.h +++ b/output.h @@ -228,7 +228,7 @@ void log_flush_all(); /* Open a log descriptor of the type given to the filename given. If append is nonzero, the file will be appended instead of clobbered if it already exists. If the file does not exist, it will be created */ -int log_open(int logt, int append, char *filename); +int log_open(int logt, bool append, char *filename); /* Output the list of ports scanned to the top of machine parseable logs (in a comment, unfortunately). The items in ports should be