summaryrefslogtreecommitdiff
path: root/lib/hostip.c
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2021-05-29 23:57:58 +0200
committerDaniel Stenberg <daniel@haxx.se>2021-05-30 19:49:40 +0200
commit1c1d9f1affbd3367bcb24062e261d0ea5d185e3a (patch)
treecebd58fc62fe33c97b6f22d0f03b3d87a65e04ae /lib/hostip.c
parent9097843e8fe42aa237c3c2087cfde781fbb5b331 (diff)
downloadcurl-1c1d9f1affbd3367bcb24062e261d0ea5d185e3a.tar.gz
hsts: ignore numberical IP address hosts
Also, use a single function library-wide for detecting if a given hostname is a numerical IP address. Reported-by: Harry Sintonen Fixes #7146 Closes #7149
Diffstat (limited to 'lib/hostip.c')
-rw-r--r--lib/hostip.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/hostip.c b/lib/hostip.c
index e0e3cfc2c..b0d2db0b4 100644
--- a/lib/hostip.c
+++ b/lib/hostip.c
@@ -461,6 +461,25 @@ Curl_cache_addr(struct Curl_easy *data,
}
/*
+ * Curl_host_is_ipnum() returns TRUE if the given string is a numerical IPv4
+ * (or IPv6 if supported) address.
+ */
+bool Curl_host_is_ipnum(const char *hostname)
+{
+ struct in_addr in;
+#ifdef ENABLE_IPV6
+ struct in6_addr in6;
+#endif
+ if(Curl_inet_pton(AF_INET, hostname, &in) > 0
+#ifdef ENABLE_IPV6
+ || Curl_inet_pton(AF_INET6, hostname, &in6) > 0
+#endif
+ )
+ return TRUE;
+ return FALSE;
+}
+
+/*
* Curl_resolv() is the main name resolve function within libcurl. It resolves
* a name and returns a pointer to the entry in the 'entry' argument (if one
* is provided). This function might return immediately if we're using asynch