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

自古美人都是妖i 提交于 2019-12-28 16:30:28

问题


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


回答1:


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!




回答2:


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

Forwards-compatibility?




回答3:


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.



来源:https://stackoverflow.com/questions/5861107/when-is-the-hybrid-ip-notation-ffff192-168-1-4-appropriate

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!