Skip to content

Commit

Permalink
main: Add --timestamp option
Browse files Browse the repository at this point in the history
This is useful for debugging connection timeouts and DPD/Keepalive
problems.

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
  • Loading branch information
cernekee committed Jan 15, 2014
1 parent d51ab4d commit 765f0de
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
16 changes: 16 additions & 0 deletions main.c
Expand Up @@ -53,6 +53,7 @@
#include LIBPROXY_HDR
#endif
#include <getopt.h>
#include <time.h>

#include "openconnect-internal.h"

Expand All @@ -77,6 +78,7 @@ static void init_token(struct openconnect_info *vpninfo,
#undef openconnect_version_str

int verbose = PRG_INFO;
int timestamp;
int background;
int do_passphrase_from_fsid;
int nocertcheck;
Expand Down Expand Up @@ -122,6 +124,7 @@ enum {
OPT_TOKEN_MODE,
OPT_TOKEN_SECRET,
OPT_OS,
OPT_TIMESTAMP,
};

#ifdef __sun__
Expand Down Expand Up @@ -152,6 +155,7 @@ static struct option long_options[] = {
OPTION("script", 1, 's'),
OPTION("script-tun", 0, 'S'),
OPTION("syslog", 0, 'l'),
OPTION("timestamp", 0, OPT_TIMESTAMP),
OPTION("key-password", 1, 'p'),
OPTION("proxy", 1, 'P'),
OPTION("user", 1, 'u'),
Expand Down Expand Up @@ -263,6 +267,7 @@ static void usage(void)
printf(" -h, --help %s\n", _("Display help text"));
printf(" -i, --interface=IFNAME %s\n", _("Use IFNAME for tunnel interface"));
printf(" -l, --syslog %s\n", _("Use syslog for progress messages"));
printf(" --timestamp %s\n", _("Prepend timestamp to progress messages"));
printf(" -U, --setuid=USER %s\n", _("Drop privileges after connecting"));
printf(" --csd-user=USER %s\n", _("Drop privileges during CSD execution"));
printf(" --csd-wrapper=SCRIPT %s\n", _("Run SCRIPT instead of CSD binary"));
Expand Down Expand Up @@ -799,6 +804,9 @@ int main(int argc, char **argv)
xstrdup("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"));
}
break;
case OPT_TIMESTAMP:
timestamp = 1;
break;
default:
usage();
}
Expand Down Expand Up @@ -1042,6 +1050,14 @@ void write_progress(void *_vpninfo, int level, const char *fmt, ...)
outf = stderr;

if (verbose >= level) {
if (timestamp) {
char ts[64];
time_t t = time(NULL);
struct tm *tm = localtime(&t);

strftime(ts, 64, "[%Y-%m-%d %H:%M:%S] ", tm);
fprintf(outf, "%s", ts);
}
va_start(args, fmt);
vfprintf(outf, fmt, args);
va_end(args);
Expand Down
4 changes: 4 additions & 0 deletions openconnect.8.in
Expand Up @@ -18,6 +18,7 @@ openconnect \- Connect to Cisco AnyConnect VPN
.OP \-h,\-\-help
.OP \-i,\-\-interface ifname
.OP \-l,\-\-syslog
.OP \-\-timestamp
.OP \-U,\-\-setuid user
.OP \-\-csd\-user user
.OP \-m,\-\-mtu mtu
Expand Down Expand Up @@ -154,6 +155,9 @@ for tunnel interface
.B \-l,\-\-syslog
Use syslog for progress messages
.TP
.B \-\-timestamp
Prepend a timestamp to each progress message
.TP
.B \-U,\-\-setuid=USER
Drop privileges after connecting, to become user
.I USER
Expand Down

0 comments on commit 765f0de

Please sign in to comment.