[ Team LiB ] |
12.4 IPv6 Address-Testing MacrosThere is a small class of IPv6 applications that must know whether they are talking to an IPv4 peer. These applications need to know if the peer's address is an IPv4-mapped IPv6 address. The following 12 macros are defined to test an IPv6 address for certain properties.
The first seven macros test the basic type of IPv6 address. We show these various address types in Section A.5. The final five macros test the scope of an IPv6 multicast address (Section 21.2).
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. As an example of an application that needs this macro, consider FTP and its PORT command. If we start an FTP client, log in to an FTP server, and issue an FTP dir command, the FTP client sends a PORT command to the FTP server across the control connection. This tells the server the client's IP address and port, to which the server then creates a data connection. (Chapter 27 of TCPv1 contains all the details of the FTP application protocol.) But, 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. Exercise 12.1 gives an example of IPv4 and IPv6 FTP protocol behavior. |
[ Team LiB ] |