加入收藏 | 设为首页 | 会员中心 | 我要投稿 好传媒网 (https://www.haochuanmei.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 移动互联 > 评测 > 正文

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

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

  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

(编辑:好传媒网)

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

热点阅读