chapter 10 ipv4 and ipv6 interoperability. contents introduction ipv4 client, ipv6 server ipv6...

13
Chapter 10 IPv4 and IPv6 Interoperability

Upload: tiffany-hold

Post on 14-Dec-2015

231 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Chapter 10 IPv4 and IPv6 Interoperability. contents Introduction IPv4 Client, IPv6 Server IPv6 Client, IPv4 Server IPv6 Address Testing Macros IPV6_ADDRFORM

Chapter 10IPv4 and IPv6 Interoperability

Page 2: Chapter 10 IPv4 and IPv6 Interoperability. contents Introduction IPv4 Client, IPv6 Server IPv6 Client, IPv4 Server IPv6 Address Testing Macros IPV6_ADDRFORM

contents

• Introduction

• IPv4 Client, IPv6 Server

• IPv6 Client, IPv4 Server

• IPv6 Address Testing Macros

• IPV6_ADDRFORM Socket Option

• Source Code Portability

Page 3: Chapter 10 IPv4 and IPv6 Interoperability. contents Introduction IPv4 Client, IPv6 Server IPv6 Client, IPv4 Server IPv6 Address Testing Macros IPV6_ADDRFORM

Introduction

• Server and client combination– IPv4 <=> IPv4(most server and client)

– IPv4 <=> IPv6

– IPv6 <=> IPv4

– IPv6 <=> 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

Page 4: Chapter 10 IPv4 and IPv6 Interoperability. contents Introduction IPv4 Client, IPv6 Server IPv6 Client, IPv4 Server IPv6 Address Testing Macros IPV6_ADDRFORM

IPv4 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

Page 5: Chapter 10 IPv4 and IPv6 Interoperability. contents Introduction IPv4 Client, IPv6 Server IPv6 Client, IPv4 Server IPv6 Address Testing Macros IPV6_ADDRFORM

IPv6client

IPv6server

TCP

IPv6

Data link

Data link

IPv4

TCP

IPv4client

TCP

IPv4 IPv6

Data link

Enethdr

IPv4hdr

TCPhdr

TCPdata

Enethdr

IPv4hdr

TCPhdr

TCPdata

Type0800

Type0800 Dport 8888

Dport 8888

206.62.226.42

IPv4 mapped IPv6 address

IPv6 listening socket,

bound to 0::0, port 8888

IPv6 address

5flb:df00:ce3e:e200:20:800:2b37:6426

Page 6: Chapter 10 IPv4 and IPv6 Interoperability. contents Introduction IPv4 Client, IPv6 Server IPv6 Client, IPv4 Server IPv6 Address Testing Macros IPV6_ADDRFORM

IPv4 datagram IPv6 datagram

AF_INETSOCK_STREAMsockaddr_in

AF_INETSOCK_DGRAMsockaddr_in

AF_INET6SOCK_DGRAMsockaddr_in6

AF_INET6SOCK_DGRAMsockaddr_in6

TCP

IPv4 IPv6

UDP

IPv4 sockets

IPv6sockets

Addressreturned by accept or recvfrom

IPv6 IPv4 IPv4 mapped

Page 7: Chapter 10 IPv4 and IPv6 Interoperability. contents Introduction IPv4 Client, IPv6 Server IPv6 Client, IPv4 Server IPv6 Address Testing Macros IPV6_ADDRFORM

IPv6 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

Page 8: Chapter 10 IPv4 and IPv6 Interoperability. contents Introduction IPv4 Client, IPv6 Server IPv6 Client, IPv4 Server IPv6 Address Testing Macros IPV6_ADDRFORM

IPv4 datagram IPv6 datagram

AF_INETSOCK_STREAMsockaddr_in

AF_INETSOCK_DGRAMsockaddr_in

AF_INET6SOCK_DGRAMsockaddr_in6

AF_INET6SOCK_DGRAMsockaddr_in6

TCP

IPv4 IPv6

UDP

IPv4 sockets

IPv6sockets

Addressfor connect or sendto

IPv6 IPv4 IPv4 mapped IPv6

Page 9: Chapter 10 IPv4 and IPv6 Interoperability. contents Introduction IPv4 Client, IPv6 Server IPv6 Client, IPv4 Server IPv6 Address Testing Macros IPV6_ADDRFORM

IPv6 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 peer’s address is an IPv4-mapped IPv6 address.

• Twelve macro defined( 참조 page 267)

Page 10: Chapter 10 IPv4 and IPv6 Interoperability. contents Introduction IPv4 Client, IPv6 Server IPv6 Client, IPv4 Server IPv6 Address Testing Macros IPV6_ADDRFORM

IPV6_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.

Page 11: Chapter 10 IPv4 and IPv6 Interoperability. contents Introduction IPv4 Client, IPv6 Server IPv6 Client, IPv4 Server IPv6 Address Testing Macros IPV6_ADDRFORM

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_addr, 16, AF_INET);

Converting an IPv4 to IPv6

Page 12: Chapter 10 IPv4 and IPv6 Interoperability. contents Introduction IPv4 Client, IPv6 Server IPv6 Client, IPv4 Server IPv6 Address Testing Macros IPV6_ADDRFORM

• setsockopt => change the Address format of socket from IPv4 to IPv6.– Return value is AF_INET or AF_INET6

• getpeername =>return an IPv4-mapped IPv6 address

Page 13: Chapter 10 IPv4 and IPv6 Interoperability. contents Introduction IPv4 Client, IPv6 Server IPv6 Client, IPv4 Server IPv6 Address Testing Macros IPV6_ADDRFORM

Source Code Portability

• #ifdefs => hard to maintain, littered …

• use getaddrinfo and getnameinfo