diff --git a/lib/blacklist.h b/lib/blacklist.h index 5604171..80a44fc 100644 --- a/lib/blacklist.h +++ b/lib/blacklist.h @@ -1,7 +1,7 @@ #include -#ifndef _BLACKLIST_H -#define _BLACKLIST_H +#ifndef BLACKLIST_H +#define BLACKLIST_H int blacklist_is_allowed(uint32_t s_addr); void blacklist_prefix(char *ip, int prefix_len); diff --git a/lib/constraint.h b/lib/constraint.h index 3e914a3..2170f8f 100644 --- a/lib/constraint.h +++ b/lib/constraint.h @@ -1,5 +1,5 @@ -#ifndef _CONSTRAINT_H -#define _CONSTRAINT_H +#ifndef CONSTRAINT_H +#define CONSTRAINT_H typedef struct _constraint constraint_t; typedef int value_t; diff --git a/lib/logger.h b/lib/logger.h index 8cf2a9f..a961ac3 100644 --- a/lib/logger.h +++ b/lib/logger.h @@ -1,8 +1,8 @@ #include #include -#ifndef _LOGGER_H -#define _LOGGER_H +#ifndef LOGGER_H +#define LOGGER_H enum LogLevel { LOG_FATAL, LOG_ERROR, LOG_WARN, LOG_INFO, LOG_DEBUG, LOG_TRACE, NUM_LOGLEVELS }; diff --git a/lib/random.h b/lib/random.h index d83b14d..b05a5d6 100644 --- a/lib/random.h +++ b/lib/random.h @@ -1,8 +1,8 @@ #include #include -#ifndef _RANDOM_H -#define _RANDOM_H +#ifndef RANDOM_H +#define RANDOM_H int random_bytes(void *dst, size_t n); diff --git a/lib/redis.h b/lib/redis.h index 51a1a7f..229136c 100644 --- a/lib/redis.h +++ b/lib/redis.h @@ -2,8 +2,8 @@ #include #include -#ifndef _REDIS_ZHELPERS_H -#define _REDIS_ZHELPERS_H +#ifndef REDIS_ZHELPERS_H +#define REDIS_ZHELPERS_H int redis_init(void); diff --git a/lib/rijndael-alg-fst.h b/lib/rijndael-alg-fst.h index 2c3396e..4a8bd5a 100644 --- a/lib/rijndael-alg-fst.h +++ b/lib/rijndael-alg-fst.h @@ -23,8 +23,8 @@ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef __RIJNDAEL_ALG_FST_H -#define __RIJNDAEL_ALG_FST_H +#ifndef RIJNDAEL_ALG_FST_H +#define RIJNDAEL_ALG_FST_H #define MAXKC (256/32) #define MAXKB (256/8) @@ -44,4 +44,4 @@ void rijndaelEncryptRound(const u32 rk[/*4*(Nr + 1)*/], int Nr, u8 block[16], in void rijndaelDecryptRound(const u32 rk[/*4*(Nr + 1)*/], int Nr, u8 block[16], int rounds); #endif /* INTERMEDIATE_VALUE_KAT */ -#endif /* __RIJNDAEL_ALG_FST_H */ +#endif /* RIJNDAEL_ALG_FST_H */ diff --git a/src/Makefile b/src/Makefile index 1ae5e35..6f9f98f 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,44 +1,43 @@ -CFLAGS+=-Wall -pedantic -Wextra -std=gnu99 -I../lib -I./ -Ioutput_modules -O2 -g -LDFLAGS+=-g -pthread -LDLIBS+= -lpcap -lgmp -lm +INCLUDE+=-I../lib -I./ -Ioutput_modules +LDFLAGS+=-pthread +LDLIBS+=-lpcap -lgmp -lm TARGETS=zmap VPATH=../lib:output_modules:probe_modules PREFIX=/usr/local INSTALL=install INSTALLDATA=install -m 644 -mandir=/usr/share/man/man1/ +mandir=$(PREFIX)/man/man1/ bindir=$(PREFIX)/sbin # Hardening and warnings for building with gcc -#M aybe add -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -#-Wold-style-definition -Wswitch-enum -GCCWARNINGS = -Wall -fno-strict-aliasing -W -Wfloat-equal -Wundef \ --Wpointer-arith \ --Wwrite-strings -Wredundant-decls -Wchar-subscripts -Wcomment \ --Wformat=2 -Wwrite-strings -Wredundant-decls -Wno-unused-but-set-variable \ +# Maybe add -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations +GCCWARNINGS = -Wall -Wformat=2 -Wno-format-nonliteral\ +-pedantic -fno-strict-aliasing \ +-Wextra \ +-Wfloat-equal -Wundef -Wwrite-strings -Wredundant-decls \ -Wnested-externs -Wbad-function-cast -Winit-self \ --Wmissing-field-initializers \ --Waddress -Wmissing-noreturn -Wnormalized=id \ --Woverride-init -Wstrict-overflow=1 -Wextra -Warray-bounds \ --Wstack-protector -Wformat -Wformat-security -Wpointer-sign -Wno-format-nonliteral -Wno-format-y2k -GCCHARDENING=-D_FORTIFY_SOURCE=2 -fstack-protector-all -fwrapv -fPIC --param ssp-buffer-size=1 +-Wmissing-noreturn -Wnormalized=id \ +-Wstack-protector + +GCCHARDENING=-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fstack-protector-all -fwrapv -fPIC --param ssp-buffer-size=1 LDHARDENING=-z relro -z now -EXTRACFLAGS=-g -O2 $(EXTRA_CFLAGS) $(GCCHARDENING) $(GCCWARNINGS) -Werror +EXTRACFLAGS=-std=gnu99 -g -O2 $(GCCHARDENING) $(GCCWARNINGS) $(EXTRA_CFLAGS) -Werror EXTRALDFLAGS= $(LDHARDENING) -CFLAGS+=-Wall $(INCLUDE) $(EXTRACFLAGS) +CFLAGS+=$(INCLUDE) $(EXTRACFLAGS) LDFLAGS+=$(EXTRALDFLAGS) probemodules=module_tcp_synscan.o module_icmp_echo.o #module_udp.o #ADD YOUR PROBE MODULE HERE -outputmodules= module_csv.o #module_simple_file.o module_extended_file.o module_csv.o #ADD YOUR OUTPUT MODULE HERE +outputmodules= module_csv.o #ADD YOUR OUTPUT MODULE HERE -objects=constraint.o blacklist.o cyclic.o logger.o send.o recv.o state.o monitor.o zopt.o zmap.o random.o output_modules.o packet.o probe_modules.o ${probemodules} ${outputmodules} validate.o rijndael-alg-fst.o get_gateway.o aesrand.o fieldset.o +objects=constraint.o blacklist.o cyclic.o logger.o send.o recv.o state.o monitor.o zopt_compat.o zmap.o random.o output_modules.o packet.o probe_modules.o ${probemodules} ${outputmodules} validate.o rijndael-alg-fst.o get_gateway.o aesrand.o fieldset.o +redis_objects=module_redis.o redis.o ifeq ($(REDIS), true) LDLIBS+=-lhiredis - objects+=module_redis.o redis.o + objects+=$(redis_objects) CFLAGS+=-DREDIS endif @@ -49,17 +48,20 @@ $(TARGETS): zmap: $(objects) +zopt_compat.o: zopt.c + zopt.c zopt.h: zopt.ggo gengetopt -C --no-help --no-version -i $^ -F $* install: zmap $(INSTALL) zmap $(bindir)/zmap test -d /etc/zmap || (mkdir /etc/zmap && $(INSTALLDATA) ../conf/* /etc/zmap/) + test -d $(mandir) || mkdir -p $(mandir) $(INSTALLDATA) ./zmap.1 $(mandir) - echo "\n\n\n\n**************\nSuccess! ZMap is installed. Try running (as root):\nzmap -p 80 -N 10 -B 1M -o -\n**************" + @echo "\n**************\nSuccess! ZMap is installed. Try running (as root):\nzmap -p 80 -N 10 -B 1M -o -\n**************" clean: - -rm -f $(objects) $(TARGETS) + -rm -f $(objects) $(redis_objects) $(TARGETS) .PHONY: install clean diff --git a/src/aesrand.h b/src/aesrand.h index 2d3dedb..352c14a 100644 --- a/src/aesrand.h +++ b/src/aesrand.h @@ -8,8 +8,8 @@ #include -#ifndef _AESRAND_H -#define _AESRAND_H +#ifndef AESRAND_H +#define AESRAND_H void aesrand_init(uint32_t seed); diff --git a/src/cyclic.h b/src/cyclic.h index f7bb7a2..f7f7387 100644 --- a/src/cyclic.h +++ b/src/cyclic.h @@ -8,8 +8,8 @@ #include -#ifndef _CYCLIC_H -#define _CYCLIC_H +#ifndef CYCLIC_H +#define CYCLIC_H int cyclic_init(uint32_t, uint32_t); diff --git a/src/get_gateway.h b/src/get_gateway.h index 398e3e1..ba5098b 100644 --- a/src/get_gateway.h +++ b/src/get_gateway.h @@ -6,8 +6,8 @@ * of the License at http://www.apache.org/licenses/LICENSE-2.0 */ -#ifndef _GET_GATEWAY_H -#define _GET_GATEWAY_H +#ifndef GET_GATEWAY_H +#define GET_GATEWAY_H #include diff --git a/src/monitor.h b/src/monitor.h index c8bd9fb..9dcc673 100644 --- a/src/monitor.h +++ b/src/monitor.h @@ -6,8 +6,8 @@ * of the License at http://www.apache.org/licenses/LICENSE-2.0 */ -#ifndef _MONITOR_H -#define _MONITOR_H +#ifndef MONITOR_H +#define MONITOR_H void monitor_run(); diff --git a/src/output_modules/output_modules.h b/src/output_modules/output_modules.h index 85a83ae..8da6399 100644 --- a/src/output_modules/output_modules.h +++ b/src/output_modules/output_modules.h @@ -6,8 +6,8 @@ * of the License at http://www.apache.org/licenses/LICENSE-2.0 */ -#ifndef HEADER_OUTPUT_MODULES_H -#define HEADER_OUTPUT_MODULES_H +#ifndef OUTPUT_MODULES_H +#define OUTPUT_MODULES_H #include "../state.h" #include "../fieldset.h" diff --git a/src/probe_modules/packet.h b/src/probe_modules/packet.h index 91fa0b6..1db5d6d 100644 --- a/src/probe_modules/packet.h +++ b/src/probe_modules/packet.h @@ -6,8 +6,8 @@ #include #include -#ifndef HEADER_ZMAP_PACKET_H -#define HEADER_ZMAP_PACKET_H +#ifndef PACKET_H +#define PACKET_H #define MAX_PACKET_SIZE 4096 diff --git a/src/recv.h b/src/recv.h index 8befea5..3c6f055 100644 --- a/src/recv.h +++ b/src/recv.h @@ -6,8 +6,8 @@ * of the License at http://www.apache.org/licenses/LICENSE-2.0 */ -#ifndef _RECV_H -#define _RECV_H +#ifndef RECV_H +#define RECV_H int recv_update_pcap_stats(void); int recv_run(pthread_mutex_t *recv_ready_mutex); diff --git a/src/send.h b/src/send.h index 5116e45..1b96120 100644 --- a/src/send.h +++ b/src/send.h @@ -6,8 +6,8 @@ * of the License at http://www.apache.org/licenses/LICENSE-2.0 */ -#ifndef _SEND_H -#define _SEND_H +#ifndef SEND_H +#define SEND_H int send_init(void); int send_run(void); diff --git a/src/state.h b/src/state.h index 8846008..a9f8f22 100644 --- a/src/state.h +++ b/src/state.h @@ -16,8 +16,8 @@ #include "types.h" #include "fieldset.h" -#ifndef _STATE_H -#define _STATE_H +#ifndef STATE_H +#define STATE_H #define MAX_PACKET_SIZE 4096 diff --git a/src/validate.h b/src/validate.h index e1b0230..4eb6362 100644 --- a/src/validate.h +++ b/src/validate.h @@ -6,8 +6,8 @@ * of the License at http://www.apache.org/licenses/LICENSE-2.0 */ -#ifndef _VALIDATE_H -#define _VALIDATE_H +#ifndef VALIDATE_H +#define VALIDATE_H #define VALIDATE_BYTES 16 diff --git a/src/zopt_compat.c b/src/zopt_compat.c new file mode 100644 index 0000000..3dfda9d --- /dev/null +++ b/src/zopt_compat.c @@ -0,0 +1,7 @@ +#if __GNUC__ < 4 +#error "gcc version >= 4 is required" +#elif __GNUC_MINOR__ >= 6 +#pragma GCC diagnostic ignored "-Wunused-but-set-variable" +#endif + +#include "zopt.c"