Research Institute of Network Technology (RINT)
In this article, I would like to briefly introduce you to some concepts and the overall flow of IPv6 network programming.
Although I called it IPv6 network programming, itêó actually not much different from writing a network program that is address family independent.
The use of dual stack
During the transition from IPv4 to IPv6, nodes will be running IPv4/IPv6 dual stack. In other words, nodes should be supporting both IPv4 and IPv6. This brings up a question. When you start communicating, how do you know if your communication partner supports IPv6, or it only supports IPv4?
DNS, which I assume most readers are familiar with, plays an important role here. Lets consider a case where we try to access a node with a name of www.example.org.
Normally, when you want to access a certain node, you use FQDN (Fully Qualified Domain Name: a name for identifying a host on the Internet) and query DNS servers to resolve the address. Dual stack uses this system in a clever way.
Generally, a node that only supports IPv4 has an A record that describes its IPv4 address on the DNS server. If a node is running dual stack, it will have an AAAA record (*1) that describes its IPv6 address, in addition to an A record.
Example
www.example.org. IN A 192.168.0.1
IN AAAA 2001:0db8:ffff::80
|
A program that only supports IPv4 will only request A record from the DNS server. However, a program that supports IPv4/IPv6 will request both AAAA and A records. The procedures for establishing a connection may differ slightly depending on the implementation, but are generally done in the following way.
- Try accessing the IPv6 address written in the AAAA record.
- If an attempt to connect using IPv6 fails, try accessing the IPv4 address written in the A record.
(*1) AAAA (usually read quad A)
Address family independent network programming
In the past, name resolution was performed using a familiar gethostbyname() function. Perhaps some readers are also familiar with the gethostbyname2(). These functions are address family dependent (it directly handles AF_INET or AF_INET6). Because of this dependency, if IPv7 or IPv8 were to be developed in the future, programs that use these functions must be rewritten. (If I may add, gethostbyname() cant even handle AF_INET6)
However, if you write programs using address family independent functions, you can save your programs from such problems.
What then, is such an address family independent function? The answer is getaddrinfo().
The actual name resolution process
Its probably easier to understand the process if you just take a look at the actual program. Following is a sample of the program.
|
|
The flow shown above is almost a standard, so looking at this program should also help you read programs written by other people. I hope you were able to grasp the overall flow of the IPv6 network programming. It is often said that the best way to improve your programming skills is to read programs written by others. IPv6 programming is no exception. I recommend you to try to upgrade existing program to an IPv6 version. |
この記事のトラックバックURL
http://www.ipv6style.jp/trackback/601


