From 80c3b259d04b729740ea2f4442fe1549e3f7d51f Mon Sep 17 00:00:00 2001 From: "mingang.he" Date: Sun, 6 Dec 2020 22:11:48 +0800 Subject: [PATCH] Add graftcp version info --- Makefile | 6 ++++++ main.c | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/Makefile b/Makefile index 2078ff0..b42ccac 100644 --- a/Makefile +++ b/Makefile @@ -19,6 +19,8 @@ ifneq ($(KERNEL), Linux) $(error only support Linux now.) endif +VERSION = $(shell git describe --tags) + debug = 0 PREFIX = /usr/local @@ -33,6 +35,10 @@ else CFLAGS += -O2 -DNDEBUG endif +ifeq ($(shell echo $(VERSION) | head -c 1), v) + CFLAGS += -DVERSION=$(VERSION) +endif + SRC := $(wildcard *.c) GRAFTCP_LOCAL_BIN = graftcp-local/graftcp-local diff --git a/main.c b/main.c index c09c78c..2561e14 100644 --- a/main.c +++ b/main.c @@ -18,6 +18,10 @@ #include "graftcp.h" #include "string-set.h" +#ifndef VERSION +#define VERSION "v0.3" +#endif + struct sockaddr_in PROXY_SA; struct sockaddr_in6 PROXY_SA6; char *LOCAL_ADDR = "127.0.0.1"; @@ -367,6 +371,8 @@ static void usage(char **argv) " -n --not-ignore-local\n" " Connecting to local is not changed by default, this\n" " option will redirect it to SOCKS5\n" + " -V --version\n" + " Show version\n" " -h --help\n" " Display this help and exit\n" "\n", argv[0]); @@ -378,6 +384,7 @@ int main(int argc, char **argv) bool ignore_local = true; struct option long_opts[] = { {"help", no_argument, 0, 'h'}, + {"version", no_argument, 0, 'V'}, {"local-addr", required_argument, 0, 'a'}, {"local-port", required_argument, 0, 'p'}, {"local-fifo", required_argument, 0, 'f'}, @@ -408,6 +415,9 @@ int main(int argc, char **argv) case 'n': ignore_local = false; break; + case 'V': + fprintf(stderr, "graftcp %s\n", VERSION); + exit(0); case 0: case 'h': default: