From 62bef0d54598af1c9f0ed77ecd72d419d4d126e6 Mon Sep 17 00:00:00 2001 From: Shuanglei Tao Date: Sun, 9 Dec 2018 09:13:14 +0800 Subject: [PATCH] server: add option to toggle IPv6 support --- README.md | 1 + man/ttyd.1 | 4 ++++ man/ttyd.man.md | 3 +++ src/server.c | 9 +++++++-- 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3122e2a..3058863 100644 --- a/README.md +++ b/README.md @@ -85,6 +85,7 @@ OPTIONS: -o, --once Accept only one client and exit on disconnection -B, --browser Open terminal with the default system browser -I, --index Custom index.html path + -6, --ipv6 Enable IPv6 support -S, --ssl Enable SSL -C, --ssl-cert SSL certificate file path -K, --ssl-key SSL key file path diff --git a/man/ttyd.1 b/man/ttyd.1 index 46e4efb..a5197cd 100644 --- a/man/ttyd.1 +++ b/man/ttyd.1 @@ -90,6 +90,10 @@ Cross platform: macOS, Linux, FreeBSD/OpenBSD, OpenWrt/LEDE, Windows \-I, \-\-index Custom index.html path +.PP +\-6, \-\-ipv6 + Enable IPv6 support + .PP \-S, \-\-ssl Enable SSL diff --git a/man/ttyd.man.md b/man/ttyd.man.md index 41d48a1..47ef981 100644 --- a/man/ttyd.man.md +++ b/man/ttyd.man.md @@ -64,6 +64,9 @@ ttyd 1 "September 2016" ttyd "User Manual" -I, --index Custom index.html path + -6, --ipv6 + Enable IPv6 support + -S, --ssl Enable SSL diff --git a/src/server.c b/src/server.c index 96680d4..2f6be83 100644 --- a/src/server.c +++ b/src/server.c @@ -47,6 +47,7 @@ static const struct option options[] = { {"signal-list", no_argument, NULL, 1}, {"reconnect", required_argument, NULL, 'r'}, {"index", required_argument, NULL, 'I'}, + {"ipv6", no_argument, NULL, '6'}, {"ssl", no_argument, NULL, 'S'}, {"ssl-cert", required_argument, NULL, 'C'}, {"ssl-key", required_argument, NULL, 'K'}, @@ -61,7 +62,7 @@ static const struct option options[] = { {"help", no_argument, NULL, 'h'}, {NULL, 0, 0, 0} }; -static const char *opt_string = "p:i:c:u:g:s:r:I:aSC:K:A:Rt:T:Om:oBd:vh"; +static const char *opt_string = "p:i:c:u:g:s:r:I:6aSC:K:A:Rt:T:Om:oBd:vh"; void print_help() { fprintf(stderr, "ttyd is a tool for sharing terminal over the web\n\n" @@ -85,6 +86,7 @@ void print_help() { " -o, --once Accept only one client and exit on disconnection\n" " -B, --browser Open terminal with the default system browser\n" " -I, --index Custom index.html path\n" + " -6, --ipv6 Enable IPv6 support\n" " -S, --ssl Enable SSL\n" " -C, --ssl-cert SSL certificate file path\n" " -K, --ssl-key SSL key file path\n" @@ -236,7 +238,7 @@ main(int argc, char **argv) { info.gid = -1; info.uid = -1; info.max_http_header_pool = 16; - info.options = LWS_SERVER_OPTION_VALIDATE_UTF8; + info.options = LWS_SERVER_OPTION_VALIDATE_UTF8 | LWS_SERVER_OPTION_DISABLE_IPV6; info.extensions = extensions; int debug_level = LLL_ERR | LLL_WARN | LLL_NOTICE; @@ -337,6 +339,9 @@ main(int argc, char **argv) { return -1; } break; + case '6': + info.options &= ~(LWS_SERVER_OPTION_DISABLE_IPV6); + break; case 'S': ssl = true; break; -- 2.43.4