Skip to content

Commit 010b252

Browse files
#80 added git hash to version
1 parent 0d779d0 commit 010b252

File tree

3 files changed

+102
-3
lines changed

3 files changed

+102
-3
lines changed

Makefile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
PREFIX ?= /usr
22
BINDIR ?= $(PREFIX)/bin
33
SYS := $(shell gcc -dumpmachine)
4+
GITVER := $(shell git describe --tags)
5+
6+
ifeq ($(GITVER),)
7+
GITVER = "unknown"
8+
endif
49

510
# LINUX
611
# The automated regression tests run on Linux, so this is the one
@@ -67,16 +72,23 @@ CFLAGS = -g -ggdb $(FLAGS2) $(INCLUDES) $(DEFINES) -Wall -O3
6772

6873
all: bin/masscan
6974

75+
76+
tmp/main-conf.o: src/main-conf.c src/*.h
77+
$(CC) $(CFLAGS) -c $< -o $@ -DGIT=\"$(GITVER)\"
78+
79+
7080
# just compile everything in the 'src' directory. Using this technique
7181
# means that include file dependencies are broken, so sometimes when
7282
# the program crashes unexpectedly, 'make clean' then 'make' fixes the
7383
# problem that a .h file was out of date
7484
tmp/%.o: src/%.c src/*.h
7585
$(CC) $(CFLAGS) -c $< -o $@
7686

87+
7788
SRC = $(wildcard src/*.c)
7889
OBJ = $(addprefix tmp/, $(notdir $(addsuffix .o, $(basename $(SRC)))))
7990

91+
8092
bin/masscan: $(OBJ)
8193
$(CC) $(CFLAGS) -o $@ $(OBJ) $(LDFLAGS) $(LIBS)
8294

src/main-conf.c

Lines changed: 89 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
1313
*/
1414
#include "masscan.h"
15+
#include "masscan-version.h"
1516
#include "ranges.h"
1617
#include "string_s.h"
1718
#include "logger.h"
@@ -55,6 +56,88 @@ masscan_usage(void)
5556
exit(1);
5657
}
5758

59+
/***************************************************************************
60+
***************************************************************************/
61+
static void
62+
print_version()
63+
{
64+
const char *cpu = "unknown";
65+
const char *compiler = "unknown";
66+
const char *compiler_version = "unknown";
67+
const char *os = "unknown";
68+
printf("\n");
69+
printf("Masscan version %s ( %s )\n",
70+
MASSCAN_VERSION,
71+
"https://github.com/robertdavidgraham/masscan"
72+
);
73+
printf("Compiled on: %s %s\n", __DATE__, __TIME__);
74+
75+
#if defined(_MSC_VER)
76+
#if defined(_M_AMD64) || defined(_M_X64)
77+
cpu = "x86";
78+
#elif defined(_M_IX86)
79+
cpu = "x86";
80+
#elif defined (_M_ARM_FP)
81+
cpu = "arm";
82+
#endif
83+
84+
{
85+
int msc_ver = _MSC_VER;
86+
87+
compiler = "VisualStudio";
88+
89+
if (msc_ver < 1500)
90+
compiler_version = "pre2008";
91+
else if (msc_ver == 1500)
92+
compiler_version = "2008";
93+
else if (msc_ver == 1600)
94+
compiler_version = "2010";
95+
else if (msc_ver == 1700)
96+
compiler_version = "2012";
97+
else if (msc_ver == 1800)
98+
compiler_version = "2013";
99+
else
100+
compiler_version = "post-2013";
101+
}
102+
103+
104+
#elif defined(__GNUC__)
105+
compiler = "gcc";
106+
compiler_version = __VERSION__;
107+
108+
#if defined(i386) || defined(__i386) || defined(__i386__)
109+
cpu = "x86";
110+
#endif
111+
112+
#if defined(__corei7) || defined(__corei7__)
113+
cpu = "x86-Corei7";
114+
#endif
115+
116+
#endif
117+
118+
#if defined(WIN32)
119+
os = "Windows";
120+
#elif defined(__linux__)
121+
os = "Linux";
122+
#elif defined(__APPLE__)
123+
os = "Apple";
124+
#elif defined(__MACH__)
125+
os = "MACH";
126+
#elif defined(__FreeBSD__)
127+
os = "FreeBSD";
128+
#elif defined(unix) || defined(__unix) || defined(__unix__)
129+
os = "Unix";
130+
#endif
131+
132+
printf("Compiler: %s %s\n", compiler, compiler_version);
133+
printf("OS: %s\n", os);
134+
printf("CPU: %s (%u bits)\n", cpu, (unsigned)(sizeof(void*))*8);
135+
136+
#if defined(GIT)
137+
printf("GIT version: %s\n", GIT);
138+
#endif
139+
}
140+
58141
/***************************************************************************
59142
***************************************************************************/
60143
static void
@@ -1452,6 +1535,9 @@ masscan_set_parameter(struct Masscan *masscan,
14521535
} else {
14531536
masscan->nmap.ttl = x;
14541537
}
1538+
} else if (EQUALS("version", name)) {
1539+
print_version();
1540+
exit(1);
14551541
} else if (EQUALS("version-intensity", name)) {
14561542
fprintf(stderr, "nmap(%s): unsupported\n", name);
14571543
exit(1);
@@ -1485,7 +1571,8 @@ is_singleton(const char *name)
14851571
{
14861572
static const char *singletons[] = {
14871573
"echo", "selftest", "self-test", "regress",
1488-
"system-dns", "traceroute", "version-light",
1574+
"system-dns", "traceroute", "version",
1575+
"version-light",
14891576
"version-all", "version-trace",
14901577
"osscan-limit", "osscan-guess",
14911578
"badsum", "reason", "open", "open-only",
@@ -1856,7 +1943,7 @@ masscan_command_line(struct Masscan *masscan, int argc, char *argv[])
18561943
}
18571944
break;
18581945
case 'V': /* print version and exit */
1859-
exit(1);
1946+
masscan_set_parameter(masscan, "version", "");
18601947
break;
18611948
case 'W':
18621949
masscan->op = Operation_List_Adapters;

src/masscan-version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#ifndef MASSCAN_VERSION
22

3-
#define MASSCAN_VERSION "1.0.2"
3+
#define MASSCAN_VERSION "1.0.3"
44

55
#endif

0 commit comments

Comments
 (0)