2.2 2.2 (Freelance web design) ? 15 APIs such as

2.2 2.2 ? 15 APIs such as gethostbyname2(3) do not provide support for scoped IPv6 addresses. Program 2.1 presents a program that hardcodes IPv4 assumptions. Bold portions depend on IPv4 or on IPv4 API assumptions. Other reading material may recommend to just replace AF_INET into AF_INET6 and sockaddr_in into sockaddr_in6, as in Program 2.2. However, the approach has multiple drawbacks. First, with gethostbyname2(3), you can only connect to IPv6 destinations, not IPv4 destinations. In an IPv4/v6 dual stack environment, FQDN can be resolved into multiple IPv4 addresses as well as multiple IPv6 addresses. Clients should try to contact all of them, not just the IPv6 ones. Second, IPv6 supports scoped IPv6 addresses, as discussed earlier. With the use of gethostbyname2(3), we cannot handle scoped IPv6 addresses, since gethostbyname2( 3) does not return scope identification. Third, by hardcoding AF_INET6 the code will work only on IPv6-enabled kernels, since a kernel without IPv6 support does not usually have AF_INET6 socket support. If you want to ship a single binary that works correctly on IPv4-only, IPv6only, and IPv4/v6 dual stack kernel without recompilation, address-family independence is needed. Fourth, the code is not future-proven. In the future, when a new protocol comes up, we would like to avoid rewriting exising applications. IPv6 transition is costly, so we would like to solve other problems together with the IPv6 transition; therefore, let us make sure we won t need to upgrade our networking code ever again. Finally, from our experience, by writing applications in an address-family independent manner, you can maintain higher portability and stability of your applications. Therefore, this book does not recommend hardcoding AF_INET6. Program 2.1 Original program, which is IPv4-only. /* * original code */ struct sockaddr_in sin; socklen_t salen; struct hostent *hp; /* open the socket */ s= socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (s < 0) { perror( socket ); Chapter
If you are looking quality, fast, secure and reliable web hosting with PHP service at an affordable price, check php5 hosting services.

Leave a Reply