Jumping from IPv4 to IPv6
来源:互联网 发布:mac make alias 编辑:程序博客网 时间:2024/05/18 00:41
zz from: http://beej.us/guide/bgnet/output/html/multipage/ip4to6.html
But I just want to know what to change in my code to get it going with IPv6! Tell me now!
Ok! Ok!
Almost everything in here is something I've gone over, above, but it's the short version for the impatient. (Of course, there is more than this, but this is what applies to the guide.)
- First of all, try to use getaddrinfo() to get all the
struct sockaddr info, instead of packing the structures by hand. This will keep you IP version-agnostic, and will eliminate many of the subsequent steps. - Any place that you find you're hard-coding anything related to the IP version, try to wrap up in a helper function.
- Change AF_INET to AF_INET6.
- Change PF_INET to PF_INET6.
Change INADDR_ANY assignments to in6addr_any assignments, which are slightly different:
struct sockaddr_in sa;struct sockaddr_in6 sa6;sa.sin_addr.s_addr = INADDR_ANY; // use my IPv4 addresssa6.sin6_addr = in6addr_any; // use my IPv6 address
Also, the value IN6ADDR_ANY_INIT can be used as an initializer when the
struct in6_addr is declared, like so:struct in6_addr ia6 = IN6ADDR_ANY_INIT;
- Instead of
struct sockaddr_in usestruct sockaddr_in6 , being sure to add "6" to the fields as appropriate (seestruct s, above). There is no sin6_zero field. - Instead of
struct in_addr usestruct in6_addr , being sure to add "6" to the fields as appropriate (seestruct s, above). - Instead of inet_aton() or inet_addr(), use inet_pton().
- Instead of inet_ntoa(), use inet_ntop().
- Instead of gethostbyname(), use the superior getaddrinfo().
- Instead of gethostbyaddr(), use the superior getnameinfo() (although gethostbyaddr() can still work with IPv6).
- INADDR_BROADCAST no longer works. Use IPv6 multicast instead.
Et voila!
- Jumping from IPv4 to IPv6
- c/c++ ipv4 to ipv6 support
- IPv4/IPv6
- ipv4&ipv6
- IPv4, IPv6,
- IPv4,IPv6
- IPV6、IPV4
- Accepting connections from both IPv6 and IPv4 clients
- How to enable packet forwarding for IPv4 and IPv6
- ip过度之ipv6 to ipv4 隧道技术
- 在家上用宽带IPv6网站,下载六维,IPv4 to IPv6
- 在家上用宽带IPv6网站,下载六维,IPv4 to IPv6
- IPv4和IPv6
- 什么是IP/IPv4/IPv6
- IPV6和IPV4
- ipv4与ipv6包头
- IPV4 上搭建 IPV6
- ubuntu+apache+ipv4+ipv6
- JAVA线程池ThreadPoolExecutor与阻塞队列BlockingQueue
- 如何用 JavaScript 获取当前 URL 的文件名
- SCM软件配置管理
- C#对Outlook2010 编程
- Android 中的WiFi学习笔记——经典
- Jumping from IPv4 to IPv6
- 笔论 蔡邕
- 关于DeviceIoControl实现异步的笔记
- 敏捷开发之每日站立会议
- mysql插入变量值
- 协同例程使用setjmp实现
- jquery 自定义事件
- Navigation Failed: Cannot Find Application……\HTML\1033\default.htm
- 关于struts中result的一点记录