您的位置:首页 > 理论基础 > 计算机网络

网络编程之IPv4和IPv6的互通性剩余小知识点(二)

2018-03-22 18:00 519 查看

1. IPv6 Address-Testing Macros

#include <netinet/in.h>
int IN6_IS_ADDR_UNSPECIFIED(const struct in6_addr *aptr);
int IN6_IS_ADDR_LOOPBACK(const struct in6_addr *aptr);
int IN6_IS_ADDR_MULTICAST(const struct in6_addr *aptr);
int IN6_IS_ADDR_LINKLOCAL(const struct in6_addr *aptr);
int IN6_IS_ADDR_SITELOCAL(const struct in6_addr *aptr);
int IN6_IS_ADDR_V4MAPPED(const struct in6_addr *aptr);
int IN6_IS_ADDR_V4COMPAT(const struct in6_addr *aptr);
int IN6_IS_ADDR_MC_NODELOCAL(const struct in6_addr *aptr);
int IN6_IS_ADDR_MC_LINKLOCAL(const struct in6_addr *aptr);
int IN6_IS_ADDR_MC_SITELOCAL(const struct in6_addr *aptr);
int IN6_IS_ADDR_MC_ORGLOCAL(const struct in6_addr *aptr);
int IN6_IS_ADDR_MC_GLOBAL(const struct in6_addr *aptr);
All return: nonzero if IPv6 address is of specified type, zero otherwise


The first seven macros test the basic type of IPv6 address.

An IPv6 client could call the IN6_IS_ADDR_V4MAPPED macro to test the IPv6 address returned by the resolver.

An IPv6 server could call this macro to test the IPv6 address returned by accept or recvfrom.

The final five macros test the scope of an IPv6 multicast address.

对于client来说,有时候必须知道server的IP协议的类型:


an IPv6 FTP client must know whether the server is an IPv4 server or an IPv6 server, because the former requires a command of the form PORT a1,a2,a3,a4,p1,p2 where the first four numbers (each between 0 and 255) form the 4-byte IPv4 address and the last two numbers form the 2-byte port number. An IPv6 server, however, requires an EPRT command (RFC 2428 [Allman, Ostermann, and Metz 1998]), containing an address family, text format address, and text format port.

2. 总结

An IPv6 server on a dual-stack host can service both IPv4 clients and IPv6 clients.

An IPv4 client still sends IPv4 datagrams to the server, but the server’s protocol stack converts the client’s address into an IPv4-mapped IPv6 address since the IPv6 server is dealing with IPv6 socket address structures.

Similarly, an IPv6 client on a dual-stack host can communicate with an IPv4 server. The client’s resolver will return IPv4-mapped IPv6 addresses for all the server’s A records, and calling connect for one of these addresses results in the dual stack sending an IPv4 SYN segment.

Only a few special clients and servers need to know the protocol being used by the peer (e.g., FTP) and the IN6_IS_ADDR_V4MAPPED macro can be used to see if the peer is using IPv4.

  在章节的编排上,笔者还是觉得前一篇要单独成篇,后面的尾巴再单独记录一篇。总体上还是对上一篇内容的复述。这种特性并不依赖于何种语言,只要是使用TCP/IP的网络应用程序都遵守这样的准则。

  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: