SlideShare una empresa de Scribd logo
1 de 16
IPv6 Programming
    Eric 2012/06/29
outline

echo client

echo server

DNS conversions

refine our app to support ipv6 and ipv4

special case
ipv4 echo client
int sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
struct sockaddr_in serv_addr;
memset((unsigned char *)&serv_addr, 0x00, sizeof(serv_addr));
serv_addr.sin_family = AF_INET;
serv_addr.sin_port = htons(9999);
inet_pton(AF_INET, "127.0.0.1", &serv_addr.sin_addr);

connect(sock, (struct sockaddr *)&serv_addr,
sizeof(serv_addr));
ipv6 echo client
int sock = socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP);
struct sockaddr_in6 serv_addr;
memset((unsigned char *)&serv_addr, 0x00, sizeof(serv_addr));
serv_addr.sin6_family = AF_INET6;
serv_addr.sin6_port = htons(9999);
inet_pton(AF_INET6, "::1", &serv_addr.sin6_addr);

connect(sock, (struct sockaddr *)&serv_addr,
sizeof(serv_addr));
comparison
ipv4 echo server
int sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
struct sockaddr_in serv_addr;
memset((unsigned char *)&serv_addr, 0x00, sizeof(serv_addr));
serv_addr.sin_family = AF_INET;
serv_addr.sin_port = htons(9999);
serv_addr.sin_addr.s_addr = INADDR_ANY;
struct sockaddr_in client_addr;

bind(sock, (struct sockaddr *)&serv_addr, sizeof(serv_addr));
listen(sock, 20);
socklen_t len = sizeof(client_addr);
int conn = accept(sock, (struct sockaddr *)&client_addr,
&len);
ipv6 echo server
int sock = socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP);
struct sockaddr_in6 serv_addr;
memset((unsigned char *)&serv_addr, 0x00, sizeof(serv_addr));
serv_addr.sin6_family = AF_INET6;
serv_addr.sin6_port = htons(9999);
serv_addr.sin6_addr = in6addr_any;
const int on = 1;
setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof(on));
struct sockaddr_in6 client_addr;

bind(sock, (struct sockaddr *)&serv_addr, sizeof(serv_addr));
listen(sock, 20);
socklen_t len = sizeof(client_addr);
int conn = accept(sock, (struct sockaddr *)&client_addr,
&len);
ipv4 & ipv6 echo server


 let’s see echoServer2.c

   set up 2 socket for ipv4 and ipv6
   independently.

   select is key point.
DNS conversions
please notice following functions:

  gethostbyname

  gethostbyaddr

  gethostbyname2

  inet_aton, inet_ntoa

let’s see hostent.c
hostent structure
addrinfo structure
refine our app to
support ipv6 and ipv4
grep -re “gethostby” *

grep -re “inet_ntoa” *

grep -re “inet_aton” *

grep -re “AF_INET” *

grep -re “sockaddr_in” *
special case

if our environment support ipv4 and ipv6, so

  server is simple

     ipv4 -> ipv4 socket

     ipv6 -> ipv6 socket
        const int on = 1;
        setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY,
        &on, sizeof(on));
special case


if our environment support ipv4 and ipv6, so

  client must consider priority of DNS
  conversions and retry connection.
special case

but......

   if our environment is ipv4 only, we should
   use hints.ai_family = AF_INET on
   getaddrinfo.

   relatively, env is ipv6 only, please enable
   hints.ai_family = AF_INET6 on getaddrinfo.
Thanks a lot.

Más contenido relacionado

La actualidad más candente

La actualidad más candente (8)

Rop and it's friends
Rop and it's friendsRop and it's friends
Rop and it's friends
 
Remote Command Execution
Remote Command ExecutionRemote Command Execution
Remote Command Execution
 
MUST CS101 Lab11
MUST CS101 Lab11 MUST CS101 Lab11
MUST CS101 Lab11
 
Quick Start Guide using Virtuozzo 7 (β) on AWS EC2
Quick Start Guide using Virtuozzo 7 (β) on AWS EC2Quick Start Guide using Virtuozzo 7 (β) on AWS EC2
Quick Start Guide using Virtuozzo 7 (β) on AWS EC2
 
Sockets intro
Sockets introSockets intro
Sockets intro
 
Tuga IT 2017 - Redis
Tuga IT 2017 - RedisTuga IT 2017 - Redis
Tuga IT 2017 - Redis
 
Npc14
Npc14Npc14
Npc14
 
Salesforce Integration using REST SOAP and HTTP callouts
Salesforce Integration using REST SOAP and HTTP calloutsSalesforce Integration using REST SOAP and HTTP callouts
Salesforce Integration using REST SOAP and HTTP callouts
 

Similar a ipv6 programming

IPV4_IPV6_INTEROPERABILITY_
IPV4_IPV6_INTEROPERABILITY_IPV4_IPV6_INTEROPERABILITY_
IPV4_IPV6_INTEROPERABILITY_
Rajesh Porwal
 
[Cisco Connect 2018 - Vietnam] Anh duc le reap the benefits of sdn with cisco...
[Cisco Connect 2018 - Vietnam] Anh duc le reap the benefits of sdn with cisco...[Cisco Connect 2018 - Vietnam] Anh duc le reap the benefits of sdn with cisco...
[Cisco Connect 2018 - Vietnam] Anh duc le reap the benefits of sdn with cisco...
Nur Shiqim Chok
 
Morethan200ccnaquesti 140420001832-phpapp02
Morethan200ccnaquesti 140420001832-phpapp02Morethan200ccnaquesti 140420001832-phpapp02
Morethan200ccnaquesti 140420001832-phpapp02
moutaz mahgoub
 

Similar a ipv6 programming (20)

IPV4_IPV6_INTEROPERABILITY_
IPV4_IPV6_INTEROPERABILITY_IPV4_IPV6_INTEROPERABILITY_
IPV4_IPV6_INTEROPERABILITY_
 
[Cisco Connect 2018 - Vietnam] Anh duc le reap the benefits of sdn with cisco...
[Cisco Connect 2018 - Vietnam] Anh duc le reap the benefits of sdn with cisco...[Cisco Connect 2018 - Vietnam] Anh duc le reap the benefits of sdn with cisco...
[Cisco Connect 2018 - Vietnam] Anh duc le reap the benefits of sdn with cisco...
 
Transitioning IPv4 to IPv6
Transitioning IPv4 to IPv6Transitioning IPv4 to IPv6
Transitioning IPv4 to IPv6
 
123
123123
123
 
Cisco CCNA EIGRP IPV6 Configuration
Cisco CCNA EIGRP IPV6 ConfigurationCisco CCNA EIGRP IPV6 Configuration
Cisco CCNA EIGRP IPV6 Configuration
 
A deep dive about VIP,HAIP, and SCAN
A deep dive about VIP,HAIP, and SCAN A deep dive about VIP,HAIP, and SCAN
A deep dive about VIP,HAIP, and SCAN
 
200 ccna questions
200 ccna questions200 ccna questions
200 ccna questions
 
Nat failover with dual isp on cisco router configuration explained with example
Nat failover with dual isp on cisco router configuration explained with exampleNat failover with dual isp on cisco router configuration explained with example
Nat failover with dual isp on cisco router configuration explained with example
 
Morethan200ccnaquesti 140420001832-phpapp02
Morethan200ccnaquesti 140420001832-phpapp02Morethan200ccnaquesti 140420001832-phpapp02
Morethan200ccnaquesti 140420001832-phpapp02
 
More than 200 CCNA Question Answer
More than 200 CCNA Question AnswerMore than 200 CCNA Question Answer
More than 200 CCNA Question Answer
 
Day 17.1 nat pat
Day 17.1 nat pat Day 17.1 nat pat
Day 17.1 nat pat
 
Ik
IkIk
Ik
 
Day 17.1 nat pat (2)
Day 17.1 nat pat  (2)Day 17.1 nat pat  (2)
Day 17.1 nat pat (2)
 
Nat 07
Nat 07Nat 07
Nat 07
 
Nat 03
Nat 03Nat 03
Nat 03
 
Nxll18 vpn (s2 s gre & dmvpn)
Nxll18 vpn (s2 s gre & dmvpn)Nxll18 vpn (s2 s gre & dmvpn)
Nxll18 vpn (s2 s gre & dmvpn)
 
Cisco CCNA OSPF IPV6 Configuration
Cisco CCNA OSPF IPV6 ConfigurationCisco CCNA OSPF IPV6 Configuration
Cisco CCNA OSPF IPV6 Configuration
 
Capacitacion 2018
Capacitacion 2018Capacitacion 2018
Capacitacion 2018
 
OpenStack Havana over IPv6
OpenStack Havana over IPv6OpenStack Havana over IPv6
OpenStack Havana over IPv6
 
Internet Technology Practical (Mumbai University) -2017
Internet Technology Practical  (Mumbai University) -2017Internet Technology Practical  (Mumbai University) -2017
Internet Technology Practical (Mumbai University) -2017
 

Último

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
negromaestrong
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 

Último (20)

Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptx
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 

ipv6 programming

  • 1. IPv6 Programming Eric 2012/06/29
  • 2. outline echo client echo server DNS conversions refine our app to support ipv6 and ipv4 special case
  • 3. ipv4 echo client int sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); struct sockaddr_in serv_addr; memset((unsigned char *)&serv_addr, 0x00, sizeof(serv_addr)); serv_addr.sin_family = AF_INET; serv_addr.sin_port = htons(9999); inet_pton(AF_INET, "127.0.0.1", &serv_addr.sin_addr); connect(sock, (struct sockaddr *)&serv_addr, sizeof(serv_addr));
  • 4. ipv6 echo client int sock = socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP); struct sockaddr_in6 serv_addr; memset((unsigned char *)&serv_addr, 0x00, sizeof(serv_addr)); serv_addr.sin6_family = AF_INET6; serv_addr.sin6_port = htons(9999); inet_pton(AF_INET6, "::1", &serv_addr.sin6_addr); connect(sock, (struct sockaddr *)&serv_addr, sizeof(serv_addr));
  • 6. ipv4 echo server int sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); struct sockaddr_in serv_addr; memset((unsigned char *)&serv_addr, 0x00, sizeof(serv_addr)); serv_addr.sin_family = AF_INET; serv_addr.sin_port = htons(9999); serv_addr.sin_addr.s_addr = INADDR_ANY; struct sockaddr_in client_addr; bind(sock, (struct sockaddr *)&serv_addr, sizeof(serv_addr)); listen(sock, 20); socklen_t len = sizeof(client_addr); int conn = accept(sock, (struct sockaddr *)&client_addr, &len);
  • 7. ipv6 echo server int sock = socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP); struct sockaddr_in6 serv_addr; memset((unsigned char *)&serv_addr, 0x00, sizeof(serv_addr)); serv_addr.sin6_family = AF_INET6; serv_addr.sin6_port = htons(9999); serv_addr.sin6_addr = in6addr_any; const int on = 1; setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof(on)); struct sockaddr_in6 client_addr; bind(sock, (struct sockaddr *)&serv_addr, sizeof(serv_addr)); listen(sock, 20); socklen_t len = sizeof(client_addr); int conn = accept(sock, (struct sockaddr *)&client_addr, &len);
  • 8. ipv4 & ipv6 echo server let’s see echoServer2.c set up 2 socket for ipv4 and ipv6 independently. select is key point.
  • 9. DNS conversions please notice following functions: gethostbyname gethostbyaddr gethostbyname2 inet_aton, inet_ntoa let’s see hostent.c
  • 12. refine our app to support ipv6 and ipv4 grep -re “gethostby” * grep -re “inet_ntoa” * grep -re “inet_aton” * grep -re “AF_INET” * grep -re “sockaddr_in” *
  • 13. special case if our environment support ipv4 and ipv6, so server is simple ipv4 -> ipv4 socket ipv6 -> ipv6 socket const int on = 1; setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof(on));
  • 14. special case if our environment support ipv4 and ipv6, so client must consider priority of DNS conversions and retry connection.
  • 15. special case but...... if our environment is ipv4 only, we should use hints.ai_family = AF_INET on getaddrinfo. relatively, env is ipv6 only, please enable hints.ai_family = AF_INET6 on getaddrinfo.

Notas del editor

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n