TCP/IP Programming Manual

Figure 4 Using AF_INET6 Socket for IPv4 Communications (Receive)
1. The application calls socket to create an AF_INET6 socket.
2. The application initializes a sockaddr_storage structure, and sets the family, address, and
port.
3. The application calls bind to assign in6addr_any to the socket.
4. The application calls accept to mark the socket to listen and wait for incoming connections.
5. An IPv4 packet arrives and passes through the IPv4 module.
6. The TCP layer strips off the packet header and passes the information and the IPv4-mapped
address (::ffff:1.2.3.4) to the socket layer.
7. The socket layer returns the information to the application. The information from the socket is
passed to the application in a sockaddr_storage structure. (Using sockaddr_storage instead
of sockaddr_in6 makes the application protocol-independent.)
8. The application calls getnameinfo and passes the ::ffff:1.2.3.4 address and the NI_NAMEREQD
flag. The flag tells the function to return the hostname for the address. See getnameinfo
(page 117) for a description of the flags bits and their meanings.
9. The search finds the hostname for the 1.2.3.4 address in the hosts database, and getnameinfo
returns the hostname.
Chapter 5 contains sample server program code that demonstrates these steps.
Address-Testing Macros
In some cases, an application that uses an AF_INET6 socket for communications needs to determine
the type of address that is returned in the structure. For this case, the API defines macros to test the
52 Porting and Developing IPv6 Applications (NonStop TCP/IPv6 and CIP Only)