summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Makefile1
-rwxr-xr-xsrc/configure31
-rw-r--r--src/options.c10
-rw-r--r--src/uanytun.c8
4 files changed, 48 insertions, 2 deletions
diff --git a/src/Makefile b/src/Makefile
index 4124575..7ad7921 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -89,6 +89,7 @@ distclean: cleanall
find . -name *.o -exec rm -f {} \;
find . -name "*.\~*" -exec rm -rf {} \;
rm -f include.mk
+ rm -f version.h
rm -f tun.c
clean:
diff --git a/src/configure b/src/configure
index ac2dc03..a791738 100755
--- a/src/configure
+++ b/src/configure
@@ -139,7 +139,7 @@ if [ -n "$ERRORS" ] && [ $EBUILD_COMPAT -ne 1 ]; then
exit 1
fi
-
+rm -f version.h
rm -f include.mk
case $TARGET in
Linux)
@@ -238,4 +238,33 @@ else
echo "not installing example files"
fi
+VERSION=`cat ../version`
+if which svn >/dev/null; then
+ SVN_REV=`svn info | grep "^Revision: " | awk '{print($2)}'`
+ if [ -n "$SVN_REV" ]; then
+ VERSION="$VERSION (svn$SVN_REV)"
+ fi
+fi
+HOSTNAME=`hostname`
+DATE=`date +"%d.%m.%Y %H:%M:%S %Z"`
+
+cat >> version.h <<EOF
+/*
+ * uanytun version info
+ *
+ * this file was created automatically
+ * do not edit this file directly
+ * use ./configure instead
+ */
+
+#ifndef UANYTUN_version_h_INCLUDED
+#define UANYTUN_version_h_INCLUDED
+
+#define VERSION_STRING_0 "uanytun version $VERSION"
+#define VERSION_STRING_1 "built on $HOSTNAME, $DATE"
+
+#endif
+
+EOF
+
exit 0
diff --git a/src/options.c b/src/options.c
index f5010bf..906e43e 100644
--- a/src/options.c
+++ b/src/options.c
@@ -34,6 +34,7 @@
*/
#include "datatypes.h"
+#include "version.h"
#include "options.h"
@@ -233,6 +234,8 @@ int options_parse(options_t* opt, int argc, char* argv[])
if(!strcmp(str,"-h") || !strcmp(str,"--help"))
return -1;
+ else if(!strcmp(str,"-v") || !strcmp(str,"--version"))
+ return -5;
PARSE_INVERSE_BOOL_PARAM("-D","--nodaemonize", opt->daemonize_)
PARSE_STRING_PARAM("-u","--username", opt->username_)
PARSE_STRING_PARAM("-g","--groupname", opt->groupname_)
@@ -420,6 +423,7 @@ void options_print_usage()
{
printf("USAGE:\n");
printf("uanytun [-h|--help] prints this...\n");
+ printf(" [-v|--version] print version info and exit\n");
printf(" [-D|--nodaemonize] don't run in background\n");
printf(" [-u|--username] <username> change to this user\n");
printf(" [-g|--groupname] <groupname> change to this group\n");
@@ -456,6 +460,12 @@ void options_print_usage()
#endif
}
+void options_print_version()
+{
+ printf("%s\n", VERSION_STRING_0);
+ printf("%s\n", VERSION_STRING_1);
+}
+
void options_print(options_t* opt)
{
if(!opt)
diff --git a/src/uanytun.c b/src/uanytun.c
index 0e36781..ba64bc7 100644
--- a/src/uanytun.c
+++ b/src/uanytun.c
@@ -336,10 +336,16 @@ int main(int argc, char* argv[])
if(ret == -4) {
fprintf(stderr, "syntax error: unknown role name\n\n");
}
+ if(ret == -5) {
+ options_print_version();
+ }
- if(ret != -2)
+ if(ret != -2 && ret != -5)
options_print_usage();
+ if(ret == -1 || ret == -5)
+ ret = 0;
+
options_clear(&opt);
log_close();
exit(ret);