diff options
author | Omar Polo <op@omarpolo.com> | 2024-08-03 14:02:00 +0000 |
---|---|---|
committer | Omar Polo <op@omarpolo.com> | 2024-08-03 14:02:00 +0000 |
commit | 1b098239eb59917add4aa53e902172813f7de5c4 (patch) | |
tree | 7c5b541e3bad2fe35ba2c43b741ee027ef1196fa | |
parent | 4e35f66545eb76348b9322b18f0b8cbc31274717 (diff) |
gg: support IPv6 addresses in -P
-rw-r--r-- | gg.1 | 1 | ||||
-rw-r--r-- | gg.c | 23 |
2 files changed, 15 insertions, 9 deletions
@@ -82,6 +82,7 @@ and to do the request instead of the ones extracted by the IRI. .Ar port is by default 1965. +IPv6 addresses have to be wrapped in braces, for e.g. [::1]. .It Fl q Don't print server error messages to standard error. .It Fl T Ar seconds @@ -362,22 +362,27 @@ parse_debug(const char *arg) } static void -parse_proxy(const char *arg) +parse_proxy(char *arg) { char *at; - if ((proxy_host = strdup(arg)) == NULL) - err(1, "strdup"); - + proxy_host = arg; proxy_port = "1965"; - if ((at = strchr(proxy_host, ':')) == NULL) + if (*proxy_host == '[') { + if ((at = strchr(proxy_host, ']')) == NULL) + errx(1, "invalid host: %s", proxy_host); + proxy_host++; + *at++ = '\0'; + if (*at == '\0') + return; + if (*at != ':') + errx(1, "invalid port specification: %s", at); + } else if ((at = strchr(proxy_host, ':')) == NULL) return; - *at = '\0'; - proxy_port = ++at; - if (strchr(proxy_port, ':') != NULL) - errx(1, "invalid port %s", proxy_port); + *at++ = '\0'; + proxy_port = at; } int |