diff --git a/README.md b/README.md index df2378a..374712c 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,7 @@ Bind options: -b port number for binding Forward options: + -T port forwarding timeout in seconds -t
domain name or address to forward target -p port number to forward target (0: use public port) ``` diff --git a/src/hev-conf.c b/src/hev-conf.c index 9902470..462837d 100644 --- a/src/hev-conf.c +++ b/src/hev-conf.c @@ -20,6 +20,7 @@ static int mode = SOCK_STREAM; static int type = AF_UNSPEC; static int keep; static int dmon; +static int tmsec; static char mport[16]; static char sport[16] = "3478"; @@ -56,6 +57,7 @@ hev_conf_help (void) " -b port number for binding\n" "\n" "Forward options:\n" + " -T port forwarding timeout in seconds\n" " -t
domain name or address to forward target\n" " -p port number to forward target (0: use public port)\n"; @@ -67,7 +69,7 @@ hev_conf_init (int argc, char *argv[]) { int opt; - while ((opt = getopt (argc, argv, "46udk:s:h:e:b:t:p:i:")) != -1) { + while ((opt = getopt (argc, argv, "46udk:s:h:e:b:T:t:p:i:")) != -1) { switch (opt) { case '4': type = AF_INET; @@ -96,6 +98,9 @@ hev_conf_init (int argc, char *argv[]) case 'b': bport = optarg; break; + case 'T': + tmsec = strtoul (optarg, NULL, 10) * 1000; + break; case 't': taddr = optarg; break; @@ -133,6 +138,10 @@ hev_conf_init (int argc, char *argv[]) baddr = (type == AF_INET6) ? "::" : "0.0.0.0"; + if (tmsec <= 0) { + tmsec = 120000; + } + return 0; } @@ -196,6 +205,12 @@ hev_conf_tport (void) return tport; } +int +hev_conf_tmsec (void) +{ + return tmsec; +} + const char * hev_conf_mport (int port) { diff --git a/src/hev-conf.h b/src/hev-conf.h index 051c7ca..9ce41f3 100644 --- a/src/hev-conf.h +++ b/src/hev-conf.h @@ -120,6 +120,15 @@ const char *hev_conf_taddr (void); */ const char *hev_conf_tport (void); +/** + * hev_conf_tmsec: + * + * Get timeout millseconds for port forwarding. + * + * Returns: returns integer number. + */ +int hev_conf_tmsec (void); + /** * hev_conf_mport: * @port: port number diff --git a/src/hev-tfwd.c b/src/hev-tfwd.c index c64d706..80a8617 100644 --- a/src/hev-tfwd.c +++ b/src/hev-tfwd.c @@ -36,9 +36,9 @@ yielder (HevTaskYieldType type, void *data) static void client_task_entry (void *data) { - int timeout = 120000; const char *addr; const char *port; + int timeout; int mode; int sfd; int dfd; @@ -47,6 +47,7 @@ client_task_entry (void *data) mode = hev_conf_mode (); addr = hev_conf_taddr (); port = hev_conf_tport (); + timeout = hev_conf_tmsec (); if (strtoul (port, NULL, 10) == 0) port = hev_conf_mport (-1); diff --git a/src/hev-ufwd.c b/src/hev-ufwd.c index 4edf411..c3f0bc3 100644 --- a/src/hev-ufwd.c +++ b/src/hev-ufwd.c @@ -151,13 +151,14 @@ static void client_task_entry (void *data) { const int bufsize = 2048; - int timeout = 120000; struct sockaddr *pa; char buf[bufsize]; Session *s = data; + int timeout; pa = (struct sockaddr *)&s->addr; hev_task_add_fd (hev_task_self (), s->fd, POLLIN); + timeout = hev_conf_tmsec (); for (;;) { int len;