From 9c36367eea586bf43c4069546a19617d829e0a3c Mon Sep 17 00:00:00 2001 From: dmiller Date: Tue, 26 Nov 2013 20:55:29 +0000 Subject: [PATCH] header file cleanup see http://seclists.org/nmap-dev/2013/q4/168 Move some includes out of nmap.h: nmap.h gets included lots of places, and unconditionally included math.h, ctype.h, errno.h, stdio.h, sys/stat.h, fcntl.h, sys/types.h, and stdarg.h. This commit moves those includes into the .cc files where they are necessary and out of nmap.h Remove redundant include global_structures.h, included from nmap.h Removed redundant code included from nmap.h Removing #include nbase.h when nmap.h is included (redundant) Remove duplicate #include lines Add ifndef guards to a few .h files --- FPEngine.cc | 1 + FingerPrintResults.h | 1 - NmapOps.cc | 1 - NmapOps.h | 6 ++- idle_scan.h | 2 - nmap.cc | 6 ++- nmap.h | 12 ----- nmap_dns.cc | 1 - nmap_dns.h | 3 ++ nmap_error.cc | 1 + nmap_tty.cc | 4 -- nmap_tty.h | 5 +- nse_main.cc | 2 +- nse_main.h | 1 - nse_ssl_cert.h | 3 ++ nsock/examples/nsock_telnet.c | 2 - nsock/examples/nsock_test_timers.c | 1 - osscan.h | 1 - osscan2.cc | 1 + osscan2.h | 2 - output.cc | 2 - output.h | 1 - payload.cc | 1 - protocols.h | 2 - scan_engine.h | 1 - service_scan.h | 1 - services.h | 8 --- targets.h | 22 -------- tcpip.h | 80 ++---------------------------- timing.cc | 1 + timing.h | 1 - traceroute.h | 3 ++ utils.cc | 1 + utils.h | 28 +---------- 34 files changed, 31 insertions(+), 177 deletions(-) diff --git a/FPEngine.cc b/FPEngine.cc index 483c2bb7f..31c36cbe8 100644 --- a/FPEngine.cc +++ b/FPEngine.cc @@ -132,6 +132,7 @@ #include "osscan.h" #include "libnetutil/npacket.h" #include "linear.h" +#include extern NmapOps o; diff --git a/FingerPrintResults.h b/FingerPrintResults.h index 81fee1400..fedba1341 100644 --- a/FingerPrintResults.h +++ b/FingerPrintResults.h @@ -130,7 +130,6 @@ class FingerPrintResults; #include "nmap.h" -#include "global_structures.h" #include "FPEngine.h" /* Maximum number of results allowed in one of these things ... */ diff --git a/NmapOps.cc b/NmapOps.cc index 9837d8d6c..a4c2f7108 100644 --- a/NmapOps.cc +++ b/NmapOps.cc @@ -124,7 +124,6 @@ /* $Id$ */ #include "nmap.h" -#include "nbase.h" #include "NmapOps.h" #include "services.h" #include "utils.h" diff --git a/NmapOps.h b/NmapOps.h index ad9003113..d47bad93f 100644 --- a/NmapOps.h +++ b/NmapOps.h @@ -124,8 +124,10 @@ /* $Id$ */ +#ifndef NMAPOPS_H +#define NMAPOPS_H + #include "nmap.h" -#include "global_structures.h" #include "output.h" #include #include @@ -424,4 +426,4 @@ class NmapOps { u8 spoof_mac[6]; bool spoof_mac_set; }; - +#endif /* NMAPOPS_H */ diff --git a/idle_scan.h b/idle_scan.h index bb1709cee..7434c16f5 100644 --- a/idle_scan.h +++ b/idle_scan.h @@ -132,8 +132,6 @@ #define IDLE_SCAN_H #include "nmap.h" -#include "global_structures.h" -#include class Target; diff --git a/nmap.cc b/nmap.cc index a5a7913ea..d663e1d68 100644 --- a/nmap.cc +++ b/nmap.cc @@ -129,12 +129,10 @@ #include "osscan2.h" #include "scan_engine.h" #include "idle_scan.h" -#include "timing.h" #include "NmapOps.h" #include "MACLookup.h" #include "traceroute.h" #include "nmap_tty.h" -#include "nmap_dns.h" #include "services.h" #include "protocols.h" #include "targets.h" @@ -145,6 +143,10 @@ #include "utils.h" #include "xml.h" +#include +#include +#include + #ifndef NOLUA #include "nse_main.h" #endif diff --git a/nmap.h b/nmap.h index b0185e169..2d1cc4bd6 100644 --- a/nmap.h +++ b/nmap.h @@ -173,9 +173,6 @@ void *realloc(); #include #endif -#include -#include - #ifndef WIN32 /* from nmapNT -- seems to work */ #include #endif /* !WIN32 */ @@ -184,8 +181,6 @@ void *realloc(); #include /* Defines MAXHOSTNAMELEN on BSD*/ #endif -#include - #if HAVE_RPC_TYPES_H #include #endif @@ -194,14 +189,10 @@ void *realloc(); #include #endif -#include - #if HAVE_NETINET_IN_H #include #endif -#include - #if HAVE_NETDB_H #include #endif @@ -217,8 +208,6 @@ void *realloc(); # endif #endif -#include -#include #ifdef HAVE_PWD_H #include @@ -236,7 +225,6 @@ void *realloc(); /* Keep assert() defined for security reasons */ #undef NDEBUG -#include #include #if HAVE_SYS_RESOURCE_H diff --git a/nmap_dns.cc b/nmap_dns.cc index 7665a09e9..5857f657f 100644 --- a/nmap_dns.cc +++ b/nmap_dns.cc @@ -194,7 +194,6 @@ #include #include #include -#include #include extern NmapOps o; diff --git a/nmap_dns.h b/nmap_dns.h index fc86ba0d2..97ffc8ffa 100644 --- a/nmap_dns.h +++ b/nmap_dns.h @@ -120,6 +120,8 @@ * * ***************************************************************************/ +#ifndef NMAP_DNS_H +#define NMAP_DNS_H class Target; #include "nbase.h" @@ -131,3 +133,4 @@ void nmap_mass_rdns(Target ** targets, int num_targets); const char *lookup_cached_host(u32 ip); std::list get_dns_servers(); +#endif /* NMAP_DNS_H */ diff --git a/nmap_error.cc b/nmap_error.cc index 237de7211..9917127f5 100644 --- a/nmap_error.cc +++ b/nmap_error.cc @@ -127,6 +127,7 @@ #include "output.h" #include "NmapOps.h" #include "xml.h" +#include extern NmapOps o; diff --git a/nmap_tty.cc b/nmap_tty.cc index 7491103de..ea12cdeed 100644 --- a/nmap_tty.cc +++ b/nmap_tty.cc @@ -121,10 +121,6 @@ * * ***************************************************************************/ -#ifndef WIN32 -#include "nmap_config.h" -#endif - #include "nmap.h" #include diff --git a/nmap_tty.h b/nmap_tty.h index 944d9166b..69f606361 100644 --- a/nmap_tty.h +++ b/nmap_tty.h @@ -121,6 +121,9 @@ * * ***************************************************************************/ +#ifndef NMAP_TTY_H +#define NMAP_TTY_H + /* * Initializes the terminal for unbuffered non-blocking input. Also * registers tty_done() via atexit(). You need to call this before @@ -133,4 +136,4 @@ void tty_init(); being returned means a nonstandard key has been pressed and the calling method should print a status message */ bool keyWasPressed(); - +#endif /* NMAP_TTY_H */ diff --git a/nse_main.cc b/nse_main.cc index 362d1675d..0ee525436 100644 --- a/nse_main.cc +++ b/nse_main.cc @@ -1,5 +1,4 @@ #include "nmap.h" -#include "nbase.h" #include "nmap_error.h" #include "portlist.h" #include "nsock.h" @@ -8,6 +7,7 @@ #include "Target.h" #include "nmap_tty.h" #include "xml.h" +#include #include "nse_main.h" #include "nse_utility.h" diff --git a/nse_main.h b/nse_main.h index c264d7631..a21d5d789 100644 --- a/nse_main.h +++ b/nse_main.h @@ -14,7 +14,6 @@ extern "C" { } #include "nmap.h" -#include "global_structures.h" class ScriptResult { diff --git a/nse_ssl_cert.h b/nse_ssl_cert.h index c8ef4bcaa..f49afcdfb 100644 --- a/nse_ssl_cert.h +++ b/nse_ssl_cert.h @@ -122,6 +122,9 @@ ***************************************************************************/ /* $Id:$ */ +#ifndef NSE_SSL_CERT_H +#define NSE_SSL_CERT_H int l_get_ssl_certificate(lua_State *L); void nse_nsock_init_ssl_cert(lua_State *L); +#endif /* NSE_SSL_CERT_H */ diff --git a/nsock/examples/nsock_telnet.c b/nsock/examples/nsock_telnet.c index 8f81c50e2..20ba126fd 100644 --- a/nsock/examples/nsock_telnet.c +++ b/nsock/examples/nsock_telnet.c @@ -64,9 +64,7 @@ #include #include #include -#include #include -#include #include #include diff --git a/nsock/examples/nsock_test_timers.c b/nsock/examples/nsock_test_timers.c index f317f3d38..7a9781242 100644 --- a/nsock/examples/nsock_test_timers.c +++ b/nsock/examples/nsock_test_timers.c @@ -64,7 +64,6 @@ #include #include #include -#include #include #include diff --git a/osscan.h b/osscan.h index 5437d6b3a..d5ce5cd4e 100644 --- a/osscan.h +++ b/osscan.h @@ -128,7 +128,6 @@ #define OSSCAN_H #include "nmap.h" -#include "global_structures.h" #include "FingerPrintResults.h" #include "Target.h" diff --git a/osscan2.cc b/osscan2.cc index eed70db70..1db961731 100644 --- a/osscan2.cc +++ b/osscan2.cc @@ -137,6 +137,7 @@ #include "struct_ip.h" #include +#include extern NmapOps o; diff --git a/osscan2.h b/osscan2.h index e5a273192..e6c799490 100644 --- a/osscan2.h +++ b/osscan2.h @@ -129,8 +129,6 @@ #define OSSCAN2_H #include "nmap.h" -#include "global_structures.h" -#include "nbase.h" #include #include #include "Target.h" diff --git a/output.cc b/output.cc index 90b9025eb..a658f39a2 100644 --- a/output.cc +++ b/output.cc @@ -139,12 +139,10 @@ #include "Target.h" #include "utils.h" #include "xml.h" -#include "nbase.h" #include "libnetutil/netutil.h" #include -#include #include #include #include diff --git a/output.h b/output.h index 52bab7c73..b82668174 100644 --- a/output.h +++ b/output.h @@ -165,7 +165,6 @@ #include "portlist.h" #include "nmap.h" -#include "global_structures.h" #include #include diff --git a/payload.cc b/payload.cc index 3710cdb47..330bf2534 100644 --- a/payload.cc +++ b/payload.cc @@ -134,7 +134,6 @@ #include #include "NmapOps.h" -#include "nbase.h" #include "payload.h" #include "utils.h" diff --git a/protocols.h b/protocols.h index 3fb7aa4c4..1d6f1bc13 100644 --- a/protocols.h +++ b/protocols.h @@ -132,8 +132,6 @@ #endif #include "nmap.h" -#include "global_structures.h" -#include "nbase.h" #define PROTOCOL_TABLE_SIZE 256 diff --git a/scan_engine.h b/scan_engine.h index c1988ac8c..7172346fd 100644 --- a/scan_engine.h +++ b/scan_engine.h @@ -129,7 +129,6 @@ #define SCAN_ENGINE_H #include "nmap.h" -#include "global_structures.h" #include struct probespec_tcpdata { diff --git a/service_scan.h b/service_scan.h index 2ee692b69..53b2323ab 100644 --- a/service_scan.h +++ b/service_scan.h @@ -129,7 +129,6 @@ #define SERVICE_SCAN_H #include "nmap.h" -#include "global_structures.h" #include "portlist.h" #include diff --git a/services.h b/services.h index 49d43019b..78ff26503 100644 --- a/services.h +++ b/services.h @@ -128,15 +128,7 @@ #ifndef SERVICES_H #define SERVICES_H -#ifdef WIN32 -#include "mswin32\winclude.h" -#else -#include -#endif #include "nmap.h" -#include "global_structures.h" - -#include "nbase.h" #define SERVICE_TABLE_SIZE 1024 diff --git a/targets.h b/targets.h index aa5aa5e73..5f74b4387 100644 --- a/targets.h +++ b/targets.h @@ -127,29 +127,7 @@ #ifndef TARGETS_H #define TARGETS_H -#ifdef HAVE_CONFIG_H -#include "nmap_config.h" -#else -#ifdef WIN32 -#include "nmap_winconfig.h" -#endif /* WIN32 */ -#endif /* HAVE_CONFIG_H */ - -/* This contains pretty much everything we need ... */ -#if HAVE_SYS_TIME_H -#include -#endif - -#if HAVE_UNISTD_H -#include -#endif - -#ifdef HAVE_SYS_PARAM_H -#include /* Defines MAXHOSTNAMELEN on BSD*/ -#endif - #include "nmap.h" -#include "global_structures.h" #include "TargetGroup.h" class TargetGroup { diff --git a/tcpip.h b/tcpip.h index a2b40d306..a434d702e 100644 --- a/tcpip.h +++ b/tcpip.h @@ -129,78 +129,7 @@ #ifndef TCPIP_H #define TCPIP_H -#ifdef HAVE_CONFIG_H -#include "nmap_config.h" -#endif - -#include "nbase.h" - -#ifdef WIN32 -#include "mswin32\winclude.h" -#else - -#ifdef STDC_HEADERS -#include -#else -void *malloc(); -void *realloc(); -#endif - -#if STDC_HEADERS || HAVE_STRING_H -#include -#if !STDC_HEADERS && HAVE_MEMORY_H -#include -#endif -#endif -#if HAVE_STRINGS_H -#include -#endif - -#ifdef HAVE_BSTRING_H -#include -#endif - -#include -#include - -#ifdef HAVE_SYS_PARAM_H -#include /* Defines MAXHOSTNAMELEN on BSD*/ -#endif - -#include - -#if HAVE_NETINET_IN_H -#include -#endif - -#ifdef HAVE_RPC_TYPES_H -#include -#endif - -#ifdef HAVE_NETDB_H -#include -#endif - -#if HAVE_SYS_SOCKET_H -#include -#endif - -#include -#if HAVE_UNISTD_H -#include -#endif -#include - -#if TIME_WITH_SYS_TIME -# include -# include -#else -# if HAVE_SYS_TIME_H -# include -# else -# include -# endif -#endif +#include "nmap.h" #include @@ -215,17 +144,14 @@ extern "C" { #if HAVE_SYS_SOCKIO_H #include /* SIOCGIFCONF for Solaris */ #endif -#endif /* WIN32 */ #include #include #include #include - - -#include "nmap.h" -#include "global_structures.h" +/* from Target.h */ +class Target; #ifndef INET_ADDRSTRLEN #define INET_ADDRSTRLEN 16 diff --git a/timing.cc b/timing.cc index 12e9a6e25..c0e9aaaf8 100644 --- a/timing.cc +++ b/timing.cc @@ -130,6 +130,7 @@ #include "NmapOps.h" #include "utils.h" #include "xml.h" +#include extern NmapOps o; diff --git a/timing.h b/timing.h index d60a67ded..9a9af61d1 100644 --- a/timing.h +++ b/timing.h @@ -130,7 +130,6 @@ #define NMAP_TIMING_H #include "nmap.h" -#include "global_structures.h" /* Call this function on a newly allocated struct timeout_info to initialize the values appropriately */ diff --git a/traceroute.h b/traceroute.h index c603f378b..fbe1e601e 100644 --- a/traceroute.h +++ b/traceroute.h @@ -123,6 +123,8 @@ /* $Id: nmap.h 6676 2008-01-12 22:39:34Z fyodor $ */ +#ifndef NMAP_TRACEROUTE_H +#define NMAP_TRACEROUTE_H #include "Target.h" #include @@ -130,3 +132,4 @@ int traceroute(std::vector &Targets); void traceroute_hop_cache_clear(); +#endif /* NMAP_TRACEROUTE_H */ diff --git a/utils.cc b/utils.cc index 4283fc50c..917ff3508 100644 --- a/utils.cc +++ b/utils.cc @@ -126,6 +126,7 @@ #include "nmap.h" #include "utils.h" #include "NmapOps.h" +#include extern NmapOps o; diff --git a/utils.h b/utils.h index 1506fb963..1026833e3 100644 --- a/utils.h +++ b/utils.h @@ -133,38 +133,12 @@ #include #include #include "nmap.h" -#ifdef WIN32 -#include "mswin32\winclude.h" -#else -#include - -#if HAVE_NETINET_IN_H -#include -#endif +#ifndef WIN32 #include -#include "nmap_config.h" #endif -#if HAVE_UNISTD_H -#include -#endif - -#if TIME_WITH_SYS_TIME -# include -# include -#else -# if HAVE_SYS_TIME_H -# include -# else -# include -# endif -#endif - -#include "nbase.h" - #include "nmap_error.h" -#include "global_structures.h" /* Arithmatic difference modulo 2^32 */ #ifndef MOD_DIFF