Skip to content

Commit

Permalink
#80 added git hash to version
Browse files Browse the repository at this point in the history
  • Loading branch information
robertdavidgraham committed Feb 1, 2014
1 parent 0d779d0 commit 010b252
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 3 deletions.
12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -67,16 +72,23 @@ 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
# problem that a .h file was out of date
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)

Expand Down
91 changes: 89 additions & 2 deletions src/main-conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/
#include "masscan.h"
#include "masscan-version.h"
#include "ranges.h"
#include "string_s.h"
#include "logger.h"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/masscan-version.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef MASSCAN_VERSION

#define MASSCAN_VERSION "1.0.2"
#define MASSCAN_VERSION "1.0.3"

#endif

0 comments on commit 010b252

Please sign in to comment.