diff options
author | YX Hao <lifenjoiner@163.com> | 2023-04-15 23:08:40 +0800 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2023-04-26 23:39:57 +0200 |
commit | ca3f6decb927a4c3eb4c10fba09848b626a526d6 (patch) | |
tree | 0e8c3dfae8ae651e6619867f8c2b9f226f5afe33 | |
parent | 65f03e507f7eece690a0e6a05ab6f0408dbcbcb2 (diff) | |
download | curl-ca3f6decb927a4c3eb4c10fba09848b626a526d6.tar.gz |
cf-socket: turn off IPV6_V6ONLY on Windows if it is supported
IPV6_V6ONLY refs:
https://en.wikipedia.org/wiki/IPv6#IPv4-mapped_IPv6_addresses
https://github.com/golang/go/blob/master/src/net/ipsock_posix.go
https://en.wikipedia.org/wiki/Unix-like
https://learn.microsoft.com/en-us/windows/win32/winsock/ipproto-ipv6-socket-options
default value refs:
https://datatracker.ietf.org/doc/html/rfc3493#section-5.3
https://www.kernel.org/doc/html/latest/networking/ip-sysctl.html#proc-sys-net-ipv6-variables
Closes #10975
-rw-r--r-- | lib/cf-socket.c | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/lib/cf-socket.c b/lib/cf-socket.c index dc6a40e90..331d2c9c9 100644 --- a/lib/cf-socket.c +++ b/lib/cf-socket.c @@ -80,6 +80,22 @@ #include "memdebug.h" +#if defined(ENABLE_IPV6) && defined(IPV6_V6ONLY) && defined(WIN32) +/* It makes support for IPv4-mapped IPv6 addresses. + * Linux kernel, NetBSD, FreeBSD and Darwin: default is off; + * Windows Vista and later: default is on; + * DragonFly BSD: acts like off, and dummy setting; + * OpenBSD and earlier Windows: unsupported. + * Linux: controlled by /proc/sys/net/ipv6/bindv6only. + */ +static void set_ipv6_v6only(curl_socket_t sockfd, int on) +{ + (void)setsockopt(sockfd, IPPROTO_IPV6, IPV6_V6ONLY, (void *)&on, sizeof(on)); +} +#else +#define set_ipv6_v6only(x,y) +#endif + static void tcpnodelay(struct Curl_easy *data, curl_socket_t sockfd) { #if defined(TCP_NODELAY) @@ -944,8 +960,10 @@ static CURLcode cf_socket_open(struct Curl_cfilter *cf, goto out; #ifdef ENABLE_IPV6 - if(ctx->addr.family == AF_INET6) + if(ctx->addr.family == AF_INET6) { + set_ipv6_v6only(ctx->sock, 0); ipmsg = " Trying [%s]:%d..."; + } else #endif ipmsg = " Trying %s:%d..."; |