最近遇到一个ipv6的问题,问题描述如下:

#ping6 ::1

unknown host

跟踪代码,发现函数返回gai=-1

gai = getaddrinfo(target, NULL, &hints, &ai);

进一步使用函数检查错误类型

gai_strerror(gai);

得知ai_flagsd值设置错误。

把 hints.ai_flags = AI_IDN;

改为 hints.ai_flags = AI_PASSIVE; 即可。

好了现在可以正常使用了。

-sh-3.2# ./ping6 -I eth0 fe80::280:45ff:fe51:1000 -c 3
PING fe80::280:45ff:fe51:1000(fe80::280:45ff:fe51:1000) from fe80::280:45ff:fe51:1000 eth0: 56 data bytes
64 bytes from fe80::280:45ff:fe51:1000: icmp_seq=1 ttl=64 time=0.572 ms
64 bytes from fe80::280:45ff:fe51:1000: icmp_seq=2 ttl=64 time=0.533 ms
64 bytes from fe80::280:45ff:fe51:1000: icmp_seq=3 ttl=64 time=0.530 ms

--- fe80::280:45ff:fe51:1000 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
rtt min/avg/max/mdev = 0.530/0.545/0.572/0.019 ms

附 ai_flags  常用值

AI_PASSIVE
 Setting the AI_PASSIVE flag indicates the caller intends to use the returned socket address structure in a call to the bind function. When the AI_PASSIVE flag is set and pNodeName is a NULL pointer, the IP address portion of the socket address structure is set to INADDR_ANY for IPv4 addresses and IN6ADDR_ANY_INIT for IPv6 addresses.

When the AI_PASSIVE flag is not set, the returned socket address structure is ready for a call to the connect function for a connection-oriented protocol, or ready for a call to either the connect, sendto, or send functions for a connectionless protocol. If the pNodeName parameter is a NULL pointer in this case, the IP address portion of the socket address structure is set to the loopback address.
 
AI_CANONNAME
 If neither AI_CANONNAME nor AI_NUMERICHOST is used, the GetAddrInfoW function attempts resolution. If a literal string is passed GetAddrInfoW attempts to convert the string, and if a host name is passed the GetAddrInfoW function attempts to resolve the name to an address or multiple addresses.

When the AI_CANONNAME bit is set and the GetAddrInfoW function returns success, the ai_canonname member in the ppResult parameter points to a NULL-terminated string that contains the canonical name of the specified node.

The GetAddrInfoW function can return success when the AI_CANONNAME flag is set, yet the ai_canonname member in the associated addrinfoW structure is NULL. Therefore, the recommended use of the AI_CANONNAME flag includes testing whether the ai_canonname member in the associated addrinfoW structure is NULL.
 
AI_NUMERICHOST
 When the AI_NUMERICHOST bit is set, the pNodeName parameter must contain a non-NULL numeric host address string, otherwise the EAI_NONAME error is returned. This flag prevents a name resolution service from being called.
 
AI_NUMERICSERV
 When the AI_NUMERICSERV bit is set, the pServiceName parameter must contain a non-NULL numeric port number, otherwise the EAI_NONAME error is returned. This flag prevents a name resolution service from being called.

The AI_NUMERICSERV flag is defined on Windows SDK for Windows??Vista and later. The AI_NUMERICSERV flag is not supported by Microsoft providers.
 
AI_ALL
 If the AI_ALL bit is set, a request is made for IPv6 addresses and IPv4 addressses with AI_V4MAPPED.

The AI_ALL flag is defined on the Windows SDK for Windows??Vista and later. The AI_ALL flag is supported on Windows??Vista and later.
 
AI_ADDRCONFIG
 If the AI_ADDRCONFIG bit is set, GetAddrInfoW will resolve only if a global address is configured. If AI_ADDRCONFIG flag is specified, IPv4 addresses shall be returned only if an IPv4 address is configured on the local system, and IPv6 addresses shall be returned only if an IPv6 address is configured on the local system. The IPv4 or IPv6 loopback address is not considered a valid global address.

The AI_ADDRCONFIG flag is defined on the Windows SDK for Windows??Vista and later. The AI_ADDRCONFIG flag is supported on Windows??Vista and later.
 
AI_V4MAPPED
 If the AI_V4MAPPED bit is set and a request for IPv6 addresses fails, a name service request is made for IPv4 addresses and these addresses are converted to IPv4-mapped IPv6 address format.

The AI_V4MAPPED flag is defined on the Windows SDK for Windows??Vista and later. The AI_V4MAPPED flag is supported on Windows??Vista and later.
 
AI_NON_AUTHORITATIVE
 If the AI_NON_AUTHORITATIVE bit is set, the NS_EMAIL namespace provider returns both authoritative and non-authoritative results. If the AI_NON_AUTHORITATIVE bit is not set, the NS_EMAIL namespace provider returns only authoritative results.

The AI_NON_AUTHORITATIVE flag is defined on the Windows SDK for Windows??Vista and later. The AI_NON_AUTHORITATIVE flag is supported on Windows??Vista and later and applies only to the NS_EMAIL namespace.
 
AI_SECURE
 If the AI_SECURE bit is set, the NS_EMAIL namespace provider will return results that were obtained with enhanced security to minimize possible spoofing.

The AI_SECURE flag is defined on the Windows SDK for Windows??Vista and later. The AI_SECURE flag is supported on Windows??Vista and later and applies only to the NS_EMAIL namespace.

AI_RETURN_PREFERRED_NAMES
 If the AI_RETURN_PREFERRED_NAMES is set, then no name should be provided in the pNodeName parameter. The NS_EMAIL namespace provider will return preferred names for publication.

The AI_RETURN_PREFERRED_NAMES flag is defined on the Windows SDK for Windows??Vista and later. The AI_RETURN_PREFERRED_NAMES flag is supported on Windows??Vista and later and applies only to the NS_EMAIL namespace.
 
AI_FQDN
 If the AI_FQDN is set and a flat name (single label) is specified, GetAddrInfoW will return the fully qualified domain name that the name eventually resolved to. The fully qualified domain name is returned in the ai_canonname member in the associated addrinfoW structure. This is different than AI_CANONNAME bit flag that returns the canonical name registered in DNS which may be different than the fully qualified domain name that the flat name resolved to. Only one of the AI_FQDN and AI_CANONNAME bits can be set. The GetAddrInfoW function will fail if both flags are present with EAI_BADFLAGS.

The AI_FQDN flag is defined on the Windows SDK for Windows??7 and later. The AI_FQDN flag is supported on Windows??7 and later. 
AI_FILESERVER
 If the AI_FILESERVER is set, this is a hint to the namespace provider that the hostname being queried is being used in file share scenario. The namespace provider may ignore this hint.

The AI_FILESERVER flag is defined on the Windows SDK for Windows??7 and later. The AI_FILESERVER flag is supported on Windows??7 and later. 
AI_DISABLE_IDN_ENCODING
 If the AI_DISABLE_IDN_ENCODING is set, this disables the automatic International Domain Name encoding using Punycode in the name resolution functions called by the GetAddrInfoW function.

Windows Developer Preview:????The AI_DISABLE_IDN_ENCODING flag is defined on the Windows SDK for Windows Developer Preview and later. The AI_DISABLE_IDN_ENCODING flag is supported on Windows Developer Preview and later.

ping6 之 unknown host 解决方法相关推荐

  1. ssh_exchange_identification: Connection closed by remote host 解决方法

    ssh_exchange_identification: Connection closed by remote host 解决方法 参考文章: (1)ssh_exchange_identificat ...

  2. FTP错误 [ftp: connect: No route to host] 解决方法

    FTP错误 [ftp: connect: No route to host] 解决方法 参考文章: (1)FTP错误 [ftp: connect: No route to host] 解决方法 (2) ...

  3. curl: (7) couldn‘t connect to host 解决方法

    curl: (7) couldn't connect to host 解决方法 参考文章: (1)curl: (7) couldn't connect to host 解决方法 (2)https:// ...

  4. keil5软件仿真出现unknown signal解决方法。

    用keil uvision5软件仿真时,MDK Logic Analyzer添加current logic analyzer signals时总是显示Unknown Signal? 解决方法如下: D ...

  5. PHP Primary script unknown 终极解决方法

    PHP Primary script unknown 终极解决方法 参考文章: (1)PHP Primary script unknown 终极解决方法 (2)https://www.cnblogs. ...

  6. java.net.NoRouteToHostException: No route to host解决方法

    java.net.NoRouteToHostException: No route to host解决方法 参考文章: (1)java.net.NoRouteToHostException: No r ...

  7. 计算机打印unknow,系统安装打印机驱动提示unknown device解决方法

    原标题:"WinXP系统安装打印机驱动提示unknown device怎么办"关于电脑问题教程分享. - 来源:191路由网. XP系统电脑安装打印机驱动时提示unknown de ...

  8. git send-email 时unknown AUTH解决方法

    fatal: 只允许"http"和"https"方案. 参数名: requestUri Command unknown: 'AUTH' at C:/Progra ...

  9. git报错:git commit命令后显示Author identity unknown的解决方法

    一.报错截图 使用git commit命令之后, 报错:Author identity unknown 二.报错原因 没有配置用户信息或者配置的用户信息已过期 三.解决方法 重新配置用户信息 先输入: ...

最新文章

  1. android读取xml 字符串,Android 读取本地Xml文件,并转换成String
  2. 如何把一段逗号分割的字符串转换成一个数组?
  3. spring 源码_spring源码系列(一)——spring循环引用
  4. linux mysql 5.5 安装_Linux 安装 mysql5.5.19
  5. java中sesion
  6. MySQL-InnoDB-事务
  7. Android XML解析之PULL及单元测试
  8. linker command failed with exit code 1
  9. 2007年8月28日 月全食 照片
  10. 酒店IPTV数字电视系统解决方案
  11. Mac如何关闭开机启动项?
  12. 检察机关认定河北涞源反杀案为正当防卫 决定不起诉女生父母
  13. mysql启动服务报Found option without preceding group in config file
  14. 三翼鸟,用两年开启下一个十年
  15. FTP服务器vsftpd配置项-黑白名单(userlist_enable、userlist_deny)
  16. 终于有人把标签设计讲明白了
  17. 汇聚全球200多颗在轨遥感卫星,今日影像,今日推送!
  18. Microsoft Azure IoT Hub应用 – 第一部分:向云端发送数据
  19. linux教程deepin,国产系统Linux Deepin 2014详细评测
  20. 基于单片机的无线红外报警系统-单片机课设毕设资料

热门文章

  1. 【LSP简史】里氏替换原则表述方式的变化,从学术到「人话」
  2. Linux下为命令取别名
  3. js 数组操作的push pop shift unshift 等方法
  4. 思科5505/5506防火墙配置與範例
  5. Mysql的utf8与utf8mb4区别,utf8mb4_bin、utf8mb4_general_ci、utf8mb4_unicode_ci区别
  6. 为什么月薪2万的大数据职位都必须学习Python?
  7. 常用小工具:一款好用、实用的“日常工作安排”桌面日历
  8. JQuery 模糊匹配(JQuery 选择器模糊匹配、选择指定属性是以给定字符串开始的元素 )
  9. VMware Workstation虚拟机设置联网(Linux)
  10. 我希望用Java拥有的十大锡兰语言功能