开发者

When is the hybrid IP notation ::ffff:192.168.1.4 appropriate?

开发者 https://www.devze.com 2023-03-01 23:05 出处:网络
Put another way, if an address is IPv4, why bother to ex开发者_如何学运维press it as IPv6 at all?It’s IPv4 expressed through IPv6 so that the application only needs to support one IP stack.

Put another way, if an address is IPv4, why bother to ex开发者_如何学运维press it as IPv6 at all?


It’s IPv4 expressed through IPv6 so that the application only needs to support one IP stack.

Being able to reference IPv4 addresses through IPv6 notation means I can work on getting IPv6 support really solid in my application, and not have to worry about duplicating effort.

These days some distributions disable IPv4 compatibility by default (e.g. Debian), and also Windows does this by default. To accommodate this as a programmer you should bind two sockets: one IPv4 socket, and one IPv6 socket with the IPV6_V6ONLY flag (which forces it to bind IPv6–only with no IPv4 compatibility, no matter the state of /proc/sys/net/ipv6/bindv6only).

In the comments below, Mike linked me to this great site with info on how you should use sockaddr_storage for AF_–independent programming (which has great relevance whether you decide to go AF_INET6, or decide to use AF_INET and AF_INET6 side by side). Also I like Beej's Guide to Network Programming, which has some similar information too. Recommended reading. Thanks, Mike!


if an address is IPv4, why bother to express it as IPv6 at all?

Forwards-compatibility?


It's appropriate to use that form with V4MAPPED addresses.

The V4MAPPED addresses aren't supposed to appear in actual IPv6 headers transmitted in the network. They're only supposed to be used by applications that use dual-stack IPv4/IPv6 host implementations where a single transport endpoint can communicate using both IPv4 and IPv6 concurrently.

If you open a TCP connection using the IPv6 protocol family without requiring the endpoint to be IPv6-only [which may be the default on your system] and you specify the destination address in V4MAPPED form, then the operating system will connect over IPv4, and when you call the moral equivalent of getsockname on your system, you will get back a V4MAPPED address.

0

精彩评论

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

关注公众号