Add display version
This commit is contained in:
@@ -5,6 +5,9 @@ OBJS=smartdns.o fast_ping.o dns_client.o dns_server.o dns.o util.o tlog.o dns_co
|
||||
CFLAGS +=-O2 -g -Wall -Wstrict-prototypes -fno-omit-frame-pointer -Wstrict-aliasing
|
||||
CFLAGS +=-Iinclude
|
||||
CFLAGS += -DBASE_FILE_NAME=\"$(notdir $<)\"
|
||||
ifdef VER
|
||||
CFLAGS += -DSMARTDNS_VERION=\"$(VER)\"
|
||||
endif
|
||||
CXXFLAGS=-O2 -g -Wall -std=c++11
|
||||
CXXFLAGS +=-Iinclude
|
||||
ifeq ($(STATIC), yes)
|
||||
|
||||
@@ -59,7 +59,8 @@ static void _help(void)
|
||||
" -c [conf] config file.\n"
|
||||
" -p [pid] pid file path\n"
|
||||
" -S ignore segment fault signal.\n"
|
||||
" -v verbose screent.\n"
|
||||
" -x verbose screen.\n"
|
||||
" -v dispaly version.\n"
|
||||
" -h show this help message.\n"
|
||||
|
||||
"Online help: http://pymumu.github.io/smartdns\n"
|
||||
@@ -69,6 +70,21 @@ static void _help(void)
|
||||
printf("%s", help);
|
||||
}
|
||||
|
||||
static void _show_version(void)
|
||||
{
|
||||
char str_ver[256] = {0};
|
||||
#ifdef SMARTDNS_VERION
|
||||
const char *ver = SMARTDNS_VERION;
|
||||
snprintf(str_ver, sizeof(str_ver), "%s", ver);
|
||||
#else
|
||||
struct tm tm;
|
||||
get_compiled_time(&tm);
|
||||
snprintf(str_ver, sizeof(str_ver), "1.%.4d%.2d%.2d-%.2d%.2d", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour,
|
||||
tm.tm_min);
|
||||
#endif
|
||||
printf("smartdns %s\n", str_ver);
|
||||
}
|
||||
|
||||
static int _smartdns_load_from_resolv(void)
|
||||
{
|
||||
FILE *fp = NULL;
|
||||
@@ -362,7 +378,7 @@ int main(int argc, char *argv[])
|
||||
safe_strncpy(config_file, SMARTDNS_CONF_FILE, MAX_LINE_LEN);
|
||||
safe_strncpy(pid_file, SMARTDNS_PID_FILE, MAX_LINE_LEN);
|
||||
|
||||
while ((opt = getopt(argc, argv, "fhc:p:Sv")) != -1) {
|
||||
while ((opt = getopt(argc, argv, "fhc:p:Svx")) != -1) {
|
||||
switch (opt) {
|
||||
case 'f':
|
||||
is_forground = 1;
|
||||
@@ -376,9 +392,13 @@ int main(int argc, char *argv[])
|
||||
case 'S':
|
||||
signal_ignore = 1;
|
||||
break;
|
||||
case 'v':
|
||||
case 'x':
|
||||
verbose_screen = 1;
|
||||
break;
|
||||
case 'v':
|
||||
_show_version();
|
||||
return 0;
|
||||
break;
|
||||
case 'h':
|
||||
_help();
|
||||
return 1;
|
||||
|
||||
19
src/util.c
19
src/util.c
@@ -839,3 +839,22 @@ static int parse_server_name_extension(const char *data, size_t data_len, char *
|
||||
|
||||
return -2;
|
||||
}
|
||||
|
||||
void get_compiled_time(struct tm *tm)
|
||||
{
|
||||
char s_month[5];
|
||||
int month, day, year;
|
||||
int hour, min, sec;
|
||||
static const char *month_names = "JanFebMarAprMayJunJulAugSepOctNovDec";
|
||||
|
||||
sscanf(__DATE__, "%s %d %d", s_month, &day, &year);
|
||||
month = (strstr(month_names, s_month) - month_names) / 3;
|
||||
sscanf(__TIME__, "%d:%d:%d", &hour, &min, &sec);
|
||||
tm->tm_year = year - 1900;
|
||||
tm->tm_mon = month;
|
||||
tm->tm_mday = day;
|
||||
tm->tm_isdst = -1;
|
||||
tm->tm_hour = hour;
|
||||
tm->tm_min = min;
|
||||
tm->tm_sec = sec;
|
||||
}
|
||||
@@ -4,6 +4,7 @@
|
||||
#define SMART_DNS_UTIL_H
|
||||
|
||||
#include <netdb.h>
|
||||
#include <time.h>
|
||||
#include "stringutil.h"
|
||||
|
||||
#define PORT_NOT_DEFINED -1
|
||||
@@ -56,4 +57,6 @@ int create_pid_file(const char *pid_file);
|
||||
*/
|
||||
int parse_tls_header(const char *data, size_t data_len, char *hostname, const char **hostname_ptr);
|
||||
|
||||
void get_compiled_time(struct tm *tm);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user