加入收藏 | 设为首页 | 会员中心 | 我要投稿 西安站长网 (https://www.029zz.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 移动 > 正文

一份完整的 IPv6 环境下 DNS 相关测试

发布时间:2019-07-24 18:38:43 所属栏目:移动 来源:董涛 张欣接
导读:副标题#e# 董涛,网易游戏高级运维工程师,主要工作方向为网易集团 DNS 的运维与开发。 张欣接,网易集团 DNS 团队负责人,负责网易域名系统的架构设计及生态建设。 一、IPv6 支持度报告 IPv6 简介 IPv6(Internet Protocol version 6,互联网通信协议第 6

客户端获取到解析地址后,会同时使用 IPv4 与 IPv6 两种链路尝试建立连接,对应下图中的 6-7。当 IPv6 链路比 IPv4 链路先建立连接,或者 IPv4 已经建立连接,但是在很短的时间间隔内,IPv6 也成功建立连接后,则这两种情况下客户端应该使用 IPv6 链路完成后续的网络请求,对应图中的 8-12

一份完整的 IPv6 环境下 DNS 相关测试

测试方法

解析域名

C/ C ++

  • gethostbyname

Linux

  1. #include <stdio.h> 
  2.     #include <netdb.h> 
  3.     #include <arpa/inet.h> 
  4.  
  5.     int main(void) 
  6.         int i = 0; 
  7.         char str[32] = {0}; 
  8.          struct hostent* phost = NULL; 
  9.  
  10.         phost = gethostbyname("IPv6test.ntes53.netease.com"); 
  11.         printf("%s", inet_ntoa(*((struct in_addr*)phost->h_addr)));  
  12.          
  13.         return 0; 
  14.     } 

Windows

  1.  #include <winsock.h> 
  2.     #include <Windows.h> 
  3.     #include <stdio.h> 
  4.  
  5.     #pragma comment (lib, "ws2_32.lib") 
  6.  
  7.     int main(void) { 
  8.         WSADATA wsaData = {0,}; 
  9.         struct in_addr addr = {0,}; 
  10.         struct hostent *res; 
  11.         int i = 0; 
  12.  
  13.         WSAStartup(MAKEWORD(2, 2), &wsaData); 
  14.  
  15.         res = gethostbyname("IPv6test.ntes53.netease.com."); 
  16.         while (res->h_addr_list[i] != 0) { 
  17.             addr.s_addr = *(u_long *) res->h_addr_list[i++]; 
  18.             printf("IP Address: %sn", inet_ntoa(addr)); 
  19.         } 
  20.  
  21.         WSACleanup(); 

getaddrinfo

  1. #include <stdio.h> 
  2.     #include <string.h> 
  3.     #include <stdlib.h> 
  4.     #include <netdb.h> 
  5.     #include <sys/types.h> 
  6.     #include <sys/socket.h> 
  7.     #include <arpa/inet.h> 
  8.  
  9.     int lookup_host () 
  10.       struct addrinfo hints, *res; 
  11.       int errcode; 
  12.       char addrstr[100]; 
  13.       void *ptr; 
  14.  
  15.       memset (&hints, 0, sizeof (hints)); 
  16.       hints.ai_family = AF_INET; 
  17.  
  18.       errcode = getaddrinfo ("IPv6test.ntes53.netease.com", NULL, &hints, &res); 
  19.       if (errcode != 0) 
  20.         { 
  21.           perror ("getaddrinfo"); 
  22.           return -1; 
  23.         } 
  24.       while (res) 
  25.         { 
  26.           inet_ntop (res->ai_family, res->ai_addr->sa_data, addrstr, 100); 
  27.           switch (res->ai_family) 
  28.             { 
  29.             case AF_INET: 
  30.               ptr = &((struct sockaddr_in *) res->ai_addr)->sin_addr; 
  31.               break; 
  32.             case AF_INET6: 
  33.               ptr = &((struct sockaddr_in6 *) res->ai_addr)->sin6_addr; 
  34.               break; 
  35.             } 
  36.           inet_ntop (res->ai_family, ptr, addrstr, 100); 
  37.           printf ("IPv%d address: %s (%s)n", res->ai_family == PF_INET6 ? 6 : 4, 
  38.                   addrstr, res->ai_canonname); 
  39.           res = res->ai_next; 
  40.         } 
  41.       return 0; 
  42.     } 
  43.     int main (void) 
  44.         lookup_host(); 
  45.     } 

windows

(编辑:西安站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

热点阅读