Title: Chapter 10 IPv4 and IPv6 Interoperability
1Chapter 10IPv4 and IPv6 Interoperability
2contents
- Introduction
- IPv4 Client, IPv6 Server
- IPv6 Client, IPv4 Server
- IPv6 Address Testing Macros
- IPV6_ADDRFORM Socket Option
- Source Code Portability
3Introduction
- Server and client combination
- IPv4 ltgt IPv4(most server and client)
- IPv4 ltgt IPv6
- IPv6 ltgt IPv4
- IPv6 ltgt IPv6
- How IPv4 application and IPv6 application can
communicate with each other. - Host are running dual stacks, both an IPv4
protocol stack and IPv6 protocol stack
4IPv4 Client , IPv6 Server
- IPv6 dual stack server can handle both IPv4 and
IPv6 clients. - This is done using IPv4-mapped IPv6 address
- server create an IPv6 listening socket that is
bound to the IPv6 wildcard address
5IPv6 server
IPv6 client
IPv4 client
IPv6 listening socket, bound to 00, port 8888
TCP
TCP
TCP
IPv6 address
IPv4 mapped IPv6 address
IPv6
IPv4
IPv4
IPv6
206.62.226.42
5flbdf00ce3ee200208002b376426
Data link
Data link
Data link
Enet hdr
IPv4 hdr
TCP hdr
TCP data
Type0800
Dport 8888
TCP hdr
TCP data
Enet hdr
IPv4 hdr
Type0800
Dport 8888
6AF_INET SOCK_DGRAM sockaddr_in
AF_INET SOCK_STREAM sockaddr_in
IPv4 sockets
AF_INET6 SOCK_DGRAM sockaddr_in6
AF_INET6 SOCK_DGRAM sockaddr_in6
IPv6 sockets
UDP
TCP
IPv4 mapped
IPv4
IPv6
Address returned by accept or recvfrom
IPv4
IPv6
IPv4 datagram
IPv6 datagram
7IPv6 client, IPv4 server
- IPv4 server start on an IPv4 only host and create
an IPv4 listening socket - IPv6 client start, call gethostbyname. IPv4
mapped IPv6 address is returned. - Using IPv4 datagram
8AF_INET SOCK_DGRAM sockaddr_in
AF_INET SOCK_STREAM sockaddr_in
IPv4 sockets
AF_INET6 SOCK_DGRAM sockaddr_in6
AF_INET6 SOCK_DGRAM sockaddr_in6
IPv6 sockets
UDP
TCP
IPv6
IPv4 mapped
IPv4
IPv6
Address for connect or sendto
IPv4
IPv6
IPv4 datagram
IPv6 datagram
9IPv6 Address Testing Macros
- There are small class of IPv6 application that
must know whether they are talking to an IPv4
peer. - These application need to know if the peers
address is an IPv4-mapped IPv6 address. - Twelve macro defined(?? page 267)
10IPV6_ADDRFORM Socket Option
- Can change a socket from one type to another,
following restriction. - An IPv4 socket can always be changed to an
IPv6. Any IPv4 address already associated with
the socket are converted to IPv4- mapped IPv6
address. - An IPv6 socket can changed to an IPv4 socket only
if any address already associated with the socket
are IPv4-mapped IPv6 address.
11Converting an IPv4 to IPv6
Int af socklen_t clilen struct
sockaddr_int6 cli / IPv6 struct / struct
hostent ptr af AF_INT6 Setsockopt(STDIN_
FILENO, IPPROTO_IPV6, IPV6_ADDRFORM, af,
sizeof(af)) clilen sizeof(cli) Getpeername(0,
cli, clilen) ptr gethostbyaddr(cli.sin6_add
r, 16, AF_INET)
12- setsockopt gt change the Address format of socket
from IPv4 to IPv6. - Return value is AF_INET or AF_INET6
- getpeername gtreturn an IPv4-mapped IPv6 address
13Source Code Portability
- ifdefs gt hard to maintain, littered
- use getaddrinfo and getnameinfo