summaryrefslogtreecommitdiff
path: root/lib/urlapi.c
diff options
context:
space:
mode:
authorBrad Spencer <bspencer@blackberry.com>2023-02-17 16:01:05 -0400
committerDaniel Stenberg <daniel@haxx.se>2023-03-03 10:05:08 +0100
commitad4997e5b289c97724fdcbaeb3c8c50222a757c4 (patch)
treea8c2f4097c794d47ec4b3e19d5559136e122c49c /lib/urlapi.c
parent73e9e6d767296c5759972d07f2441c8993ccbb9d (diff)
downloadcurl-ad4997e5b289c97724fdcbaeb3c8c50222a757c4.tar.gz
urlapi: parse IPv6 literals without ENABLE_IPV6
This makes the URL parser API stable and working the same way independently of libcurl supporting IPv6 transfers or not. Closes #10660
Diffstat (limited to 'lib/urlapi.c')
-rw-r--r--lib/urlapi.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/lib/urlapi.c b/lib/urlapi.c
index 29927b3d9..d078a49fc 100644
--- a/lib/urlapi.c
+++ b/lib/urlapi.c
@@ -57,6 +57,15 @@
/* scheme is not URL encoded, the longest libcurl supported ones are... */
#define MAX_SCHEME_LEN 40
+/*
+ * If ENABLE_IPV6 is disabled, we still want to parse IPv6 addresses, so make
+ * sure we have _some_ value for AF_INET6 without polluting our fake value
+ * everywhere.
+ */
+#if !defined(ENABLE_IPV6) && !defined(AF_INET6)
+#define AF_INET6 (AF_INET + 1)
+#endif
+
/* Internal representation of CURLU. Point to URL-encoded strings. */
struct Curl_URL {
char *scheme;
@@ -599,7 +608,8 @@ static CURLUcode hostname_check(struct Curl_URL *u, char *hostname,
return CURLUE_BAD_IPV6;
/* hostname is fine */
}
-#ifdef ENABLE_IPV6
+
+ /* Check the IPv6 address. */
{
char dest[16]; /* fits a binary IPv6 address */
char norm[MAX_IPADR_LEN];
@@ -616,7 +626,6 @@ static CURLUcode hostname_check(struct Curl_URL *u, char *hostname,
}
hostname[hlen] = ']'; /* restore ending bracket */
}
-#endif
}
else {
/* letters from the second string are not ok */