IPv6 Programming    Eric 2012/06/29
outlineecho clientecho serverDNS conversionsrefine our app to support ipv6 and ipv4special case
ipv4 echo clientint sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);struct sockaddr_in serv_addr;memset((unsigned char *)...
ipv6 echo clientint sock = socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP);struct sockaddr_in6 serv_addr;memset((unsigned char ...
comparison
ipv4 echo serverint sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);struct sockaddr_in serv_addr;memset((unsigned char *)...
ipv6 echo serverint sock = socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP);struct sockaddr_in6 serv_addr;memset((unsigned char ...
ipv4 & ipv6 echo server let’s see echoServer2.c   set up 2 socket for ipv4 and ipv6   independently.   select is key point.
DNS conversionsplease notice following functions:  gethostbyname  gethostbyaddr  gethostbyname2  inet_aton, inet_ntoalet’s...
hostent structure
addrinfo structure
refine our app tosupport ipv6 and ipv4grep -re “gethostby” *grep -re “inet_ntoa” *grep -re “inet_aton” *grep -re “AF_INET” ...
special caseif our environment support ipv4 and ipv6, so  server is simple     ipv4 -> ipv4 socket     ipv6 -> ipv6 socket...
special caseif our environment support ipv4 and ipv6, so  client must consider priority of DNS  conversions and retry conn...
special casebut......   if our environment is ipv4 only, we should   use hints.ai_family = AF_INET on   getaddrinfo.   rel...
Thanks a lot.
Upcoming SlideShare
Loading in …5
×

ipv6 programming

1,135 views

Published on

Published in: Education, Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,135
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
69
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • ipv6 programming

    1. 1. IPv6 Programming Eric 2012/06/29
    2. 2. outlineecho clientecho serverDNS conversionsrefine our app to support ipv6 and ipv4special case
    3. 3. ipv4 echo clientint 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. 4. ipv6 echo clientint 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));
    5. 5. comparison
    6. 6. ipv4 echo serverint 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. 7. ipv6 echo serverint 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. 8. ipv4 & ipv6 echo server let’s see echoServer2.c set up 2 socket for ipv4 and ipv6 independently. select is key point.
    9. 9. DNS conversionsplease notice following functions: gethostbyname gethostbyaddr gethostbyname2 inet_aton, inet_ntoalet’s see hostent.c
    10. 10. hostent structure
    11. 11. addrinfo structure
    12. 12. refine our app tosupport ipv6 and ipv4grep -re “gethostby” *grep -re “inet_ntoa” *grep -re “inet_aton” *grep -re “AF_INET” *grep -re “sockaddr_in” *
    13. 13. special caseif 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. 14. special caseif our environment support ipv4 and ipv6, so client must consider priority of DNS conversions and retry connection.
    15. 15. special casebut...... 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.
    16. 16. Thanks a lot.

    ×