From 010b252f5dfcccbcdf60ea3c1cbfcccc3ad4b40f Mon Sep 17 00:00:00 2001 From: robertdavidgraham Date: Fri, 31 Jan 2014 19:12:40 -0500 Subject: [PATCH] #80 added git hash to version --- Makefile | 12 ++++++ src/main-conf.c | 91 ++++++++++++++++++++++++++++++++++++++++++- src/masscan-version.h | 2 +- 3 files changed, 102 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index cdecc348..57d22005 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,11 @@ PREFIX ?= /usr BINDIR ?= $(PREFIX)/bin SYS := $(shell gcc -dumpmachine) +GITVER := $(shell git describe --tags) + +ifeq ($(GITVER),) +GITVER = "unknown" +endif # LINUX # The automated regression tests run on Linux, so this is the one @@ -67,6 +72,11 @@ CFLAGS = -g -ggdb $(FLAGS2) $(INCLUDES) $(DEFINES) -Wall -O3 all: bin/masscan + +tmp/main-conf.o: src/main-conf.c src/*.h + $(CC) $(CFLAGS) -c $< -o $@ -DGIT=\"$(GITVER)\" + + # just compile everything in the 'src' directory. Using this technique # means that include file dependencies are broken, so sometimes when # the program crashes unexpectedly, 'make clean' then 'make' fixes the @@ -74,9 +84,11 @@ all: bin/masscan tmp/%.o: src/%.c src/*.h $(CC) $(CFLAGS) -c $< -o $@ + SRC = $(wildcard src/*.c) OBJ = $(addprefix tmp/, $(notdir $(addsuffix .o, $(basename $(SRC))))) + bin/masscan: $(OBJ) $(CC) $(CFLAGS) -o $@ $(OBJ) $(LDFLAGS) $(LIBS) diff --git a/src/main-conf.c b/src/main-conf.c index 6bff56bb..c040d915 100644 --- a/src/main-conf.c +++ b/src/main-conf.c @@ -12,6 +12,7 @@ */ #include "masscan.h" +#include "masscan-version.h" #include "ranges.h" #include "string_s.h" #include "logger.h" @@ -55,6 +56,88 @@ masscan_usage(void) exit(1); } +/*************************************************************************** + ***************************************************************************/ +static void +print_version() +{ + const char *cpu = "unknown"; + const char *compiler = "unknown"; + const char *compiler_version = "unknown"; + const char *os = "unknown"; + printf("\n"); + printf("Masscan version %s ( %s )\n", + MASSCAN_VERSION, + "https://github.com/robertdavidgraham/masscan" + ); + printf("Compiled on: %s %s\n", __DATE__, __TIME__); + +#if defined(_MSC_VER) + #if defined(_M_AMD64) || defined(_M_X64) + cpu = "x86"; + #elif defined(_M_IX86) + cpu = "x86"; + #elif defined (_M_ARM_FP) + cpu = "arm"; + #endif + + { + int msc_ver = _MSC_VER; + + compiler = "VisualStudio"; + + if (msc_ver < 1500) + compiler_version = "pre2008"; + else if (msc_ver == 1500) + compiler_version = "2008"; + else if (msc_ver == 1600) + compiler_version = "2010"; + else if (msc_ver == 1700) + compiler_version = "2012"; + else if (msc_ver == 1800) + compiler_version = "2013"; + else + compiler_version = "post-2013"; + } + + +#elif defined(__GNUC__) + compiler = "gcc"; + compiler_version = __VERSION__; + +#if defined(i386) || defined(__i386) || defined(__i386__) + cpu = "x86"; +#endif + +#if defined(__corei7) || defined(__corei7__) + cpu = "x86-Corei7"; +#endif + +#endif + +#if defined(WIN32) + os = "Windows"; +#elif defined(__linux__) + os = "Linux"; +#elif defined(__APPLE__) + os = "Apple"; +#elif defined(__MACH__) + os = "MACH"; +#elif defined(__FreeBSD__) + os = "FreeBSD"; +#elif defined(unix) || defined(__unix) || defined(__unix__) + os = "Unix"; +#endif + + printf("Compiler: %s %s\n", compiler, compiler_version); + printf("OS: %s\n", os); + printf("CPU: %s (%u bits)\n", cpu, (unsigned)(sizeof(void*))*8); + +#if defined(GIT) + printf("GIT version: %s\n", GIT); +#endif +} + /*************************************************************************** ***************************************************************************/ static void @@ -1452,6 +1535,9 @@ masscan_set_parameter(struct Masscan *masscan, } else { masscan->nmap.ttl = x; } + } else if (EQUALS("version", name)) { + print_version(); + exit(1); } else if (EQUALS("version-intensity", name)) { fprintf(stderr, "nmap(%s): unsupported\n", name); exit(1); @@ -1485,7 +1571,8 @@ is_singleton(const char *name) { static const char *singletons[] = { "echo", "selftest", "self-test", "regress", - "system-dns", "traceroute", "version-light", + "system-dns", "traceroute", "version", + "version-light", "version-all", "version-trace", "osscan-limit", "osscan-guess", "badsum", "reason", "open", "open-only", @@ -1856,7 +1943,7 @@ masscan_command_line(struct Masscan *masscan, int argc, char *argv[]) } break; case 'V': /* print version and exit */ - exit(1); + masscan_set_parameter(masscan, "version", ""); break; case 'W': masscan->op = Operation_List_Adapters; diff --git a/src/masscan-version.h b/src/masscan-version.h index 4ce61f7a..cb7353c8 100644 --- a/src/masscan-version.h +++ b/src/masscan-version.h @@ -1,5 +1,5 @@ #ifndef MASSCAN_VERSION -#define MASSCAN_VERSION "1.0.2" +#define MASSCAN_VERSION "1.0.3" #endif