t* gopherproxy-c customized URI git clone git://git.codevoid.de/gopherproxy-c-sdk DIR Log DIR Files DIR Refs DIR README DIR LICENSE --- DIR commit 9612b7ed97d46f386db7334b7ef880038a92df8c DIR parent d0cd571a262cbbca3c7d12f08799e6835552bf13 URI Author: Hiltjo Posthuma <hiltjo@codemadness.org> Date: Fri, 17 Aug 2018 18:37:09 +0200 parseuri: support IPv6 address for host Diffstat: M gopherproxy.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) --- DIR diff --git a/gopherproxy.c b/gopherproxy.c t@@ -446,15 +446,26 @@ parseuri(const char *str, struct uri *u) memset(u, 0, sizeof(struct uri)); s = str; - e = &s[strcspn(s, ":/")]; - if (e - s + 1 >= sizeof(u->host)) - return 0; - memcpy(u->host, s, e - s); - u->host[e - s] = '\0'; - if (*e == ':') { - s = ++e; + /* IPv6 */ + if (*s == '[') { + s++; + e = strchr(s, ']'); + if (!e || e - s + 1 >= sizeof(u->host)) + return 0; + memcpy(u->host, s, e - s); + u->host[e - s] = '\0'; + e++; + } else { + e = &s[strcspn(s, ":/")]; + if (e - s + 1 >= sizeof(u->host)) + return 0; + memcpy(u->host, s, e - s); + u->host[e - s] = '\0'; + } + if (*e == ':') { + s = e + 1; e = &s[strcspn(s, "/")]; if (e - s + 1 >= sizeof(u->port))