开发者

IPv6 socket creation

开发者 https://www.devze.com 2023-03-12 15:02 出处:网络
I am implementing dual stack mode to support IPv4 and IPv6. If I am creating a IPv6 socket and listenin开发者_开发问答g on it, will it accept the connection from IPv4 socket also ??Yes, unless the ope

I am implementing dual stack mode to support IPv4 and IPv6. If I am creating a IPv6 socket and listenin开发者_开发问答g on it, will it accept the connection from IPv4 socket also ??


Yes, unless the operating system is configured otherwise, e.g. net.ipv6.bindv6only=1 in Linux, or you set the IPV6_V6ONLY socket option.


Only if the system has a dual-stack implementation. Most modern systems do, but old versions of Windows and OpenBSD do not. You shouldn't rely on this though. Get the value of the IPV6_V6ONLY socket option and if it's zero you will need to open a second socket for IPv4.

When using a dual-stack socket IPv4 addresses are represented as ::ffff:[IPv4 address]; for example ::ffff:127.0.0.1 (this corresponds to ::ffff:7f00:1; it's just typically printed in dot-decimal notation for the sake of readability).


According to Microsoft, the default even in dual stack mode is to have IPV6_V6ONLY set to false - but you can enable it through the setsockopt(2) call. FWIW, "Old versions" of Windows (single-stack) include the still-widely-used Windows XP (anything older than Vista).

So, if you're on Windows you should try and disable IPV6_V6ONLY and see if it succeeds. I don't know if that's a good answer for other single-stack implementations or not.

0

精彩评论

暂无评论...
验证码 换一张
取 消