HPlogo HP-UX IPv6 Porting Guide: HP-UX 11i v2 September 2004 > Chapter 5 Overview of IPv4 and IPv6 Call Set-up

Using AF_INET6 Socket to Send IPv4 UDP Communications

» 

Technical documentation

Complete book in PDF

 » Table of Contents

You can use the AF_INET6 socket for both IPv6 and IPv4 communications; IPv6 uses the POSIX function call getaddrinfo() rather than the IPv4 gethostbyname() function call. For IPv4 communications, create an AF_INET6 socket and pass it a sockaddr_in6 structure that contains an IPv4-mapped IPv6 address (for example, ::FFFF:1.2.3.4). The figure below shows the sequence of events for an application that uses an AF_INET6 socket to send IPv4 packets.

Figure 5-2 Title not available (Using AF_INET6 Socket to Send IPv4 UDP Communications)

  1. Application calls getaddrinfo() and passes:

    • the host name (host2).

    • the AF_INET6 address family hint, which asks the Name Service for an IPv6 address corresponding to the host name.

    • The AI_V4MAPPED flag hint, which tells the function that if the Name Service finds no IPv6 address but finds an IPv4 address for host2, return the IPv4 address within an IPv4-mapped IPv6 address. See getaddrinfo(3N) later in this document for a description of hints and flags values.

  2. The search finds the IPv4 address 1.2.3.4 for host2 in the Name Service database.

  3. Because getaddrinfo() had the AI_V4MAPPED flag set, the function returns the IPv4 -mapped address ::FFFF:1.2.3.4.

  4. The application calls the socket() function to open an IPv6 AF_INET6 socket.

  5. The application calls the sendto() function toward the ::FFFF:1.2.3.4 address.

  6. The socket layer passes the sendto request, socket information and IPv4-mapped IPv6 address to the UDP/IP module.

  7. The UDP/IP module:

    1. identifies the IPv4-mapped IPv6 address.

    2. puts the 1.2.3.4 address into an IPv4 packet header.

    3. passes the packet to the IPv4 module for transmission.

© 2004 Hewlett-Packard Development Company, L.P.