{"id":870,"date":"2014-05-27T18:33:12","date_gmt":"2014-05-27T10:33:12","guid":{"rendered":"http:\/\/www.myvoipapp.com\/blogs\/yxh\/?p=870"},"modified":"2019-02-12T20:11:49","modified_gmt":"2019-02-12T12:11:49","slug":"linux%e7%8e%af%e5%a2%83%e4%b8%adgetnameinfo%e7%9a%84%e9%97%ae%e9%a2%98","status":"publish","type":"post","link":"https:\/\/www.myvoipapp.com\/blogs\/yxh\/2014\/05\/27\/linux%e7%8e%af%e5%a2%83%e4%b8%adgetnameinfo%e7%9a%84%e9%97%ae%e9%a2%98\/","title":{"rendered":"linux\u73af\u5883\u4e2dgetnameinfo\u7684\u95ee\u9898"},"content":{"rendered":"<p>\u5728linux\u73af\u5883\u4e0b\u83b7\u53d6\u672c\u5730IP\u5730\u5740\u7684\u65b9\u6cd5\uff0c\u901a\u5e38\u90fd\u662f\u5148getifaddrs\u83b7\u53d6\u5f53\u524d\u8ba1\u7b97\u673a\u4e2d\u6240\u6709\u7684\u63a5\u53e3\u4fe1\u606f\uff0c\u7136\u540e\u5faa\u73af\u8c03\u7528getnameinfo\u83b7\u53d6\u5404\u63a5\u53e3\u7684IP\u5730\u5740\u3002<\/p>\n<p>\u8fd9\u662f\u7f51\u7edc\u4e0a\u5e38\u89c1\u7684\u63cf\u8ff0\u65b9\u5f0f\u3002\u5728IPv4\u7ec4\u7f51\u65f6\uff0c\u6ca1\u6709\u4efb\u4f55\u95ee\u9898\u3002\u4f46\u662f\u5728IPv6\u7ec4\u7f51\uff08\u83b7\u53d6IPv6\u5730\u5740\uff09\u65f6\uff0c\u51fa\u73b0\u4e86\u95ee\u9898\u3002\u7531\u8be5\u51fd\u6570\u8fd4\u56de\u7684IP\u5730\u5740\u5b57\u7b26\u4e32\u4e2d\u5305\u542b\u4e86\u5f53\u524d\u63a5\u53e3\u7684\u540d\u79f0\uff0c\u4f8b\u5982\u4ee5\u4e0b\u8fd4\u56de\u503c\uff1a<\/p>\n<pre>fe80::5a94:6bff:fe48:4cec%wlan1<\/pre>\n<p>\u5982\u679c\u60f3\u83b7\u5f97\u7eaf\u7cb9\u7684IPv6\u5730\u5740\uff0c\u5e94\u5f53\u901a\u8fc7\u63a5\u53e3\u5730\u5740\u4fe1\u606f\uff0c\u8c03\u7528inet_ntop\u6765\u8f6c\u6362IP\u5730\u5740\u4e3a\u5b57\u7b26\u4e32\uff0c\u5982\u4e0b\u5904\u7406\uff1a<\/p>\n<pre><span style=\"color: #808000;\">char\u00a0<\/span><span style=\"color: #000000;\">ipstr<\/span><span style=\"color: #000000;\">[<\/span><span style=\"color: #000080;\">512<\/span><span style=\"color: #000000;\">]={<\/span><span style=\"color: #000080;\">0<\/span><span style=\"color: #000000;\">};\r\n<span style=\"color: #800080;\">sockaddr_in6<\/span>* sockaddr_ipv6=<\/span><span style=\"color: #808000;\">reinterpret_cast<\/span>&lt;<span style=\"color: #800080;\">sockaddr_in6<\/span>*&gt;(ifa-&gt;<span style=\"color: #800000;\">ifa_addr<\/span>);\r\ninet_ntop(AF_INET6,&amp;sockaddr_ipv6-&gt;<span style=\"color: #800000;\">sin6_addr<\/span>,ipstr,<span style=\"color: #808000;\">sizeof<\/span>(ipstr));<\/pre>\n<p>\u6b64\u65f6\u83b7\u53d6\u7684IP\u5730\u5740\u5b57\u7b26\u4e32\u4fe1\u606f\u5c31\u4e0d\u518d\u5305\u542b\u5f53\u524d\u63a5\u53e3\u7684\u540d\u79f0\uff1a<\/p>\n<pre>fe80::5a94:6bff:fe48:4cec<\/pre>\n<p>IPv6\u5730\u5740\u5e26\u63a5\u53e3\u540d\u79f0\u5b9e\u9645\u662f\u201czone identifier (\u533a\u57df\u6807\u8bc6)\u201d\uff0c\u5728<a href=\"https:\/\/tools.ietf.org\/html\/rfc6874\" target=\"_blank\">RFC6874<\/a>\u89c4\u8303\u4e2d\u6709\u76f8\u5e94\u7684\u5b9a\u4e49\u3002<\/p>\n<h2>2014-06-08 updated:<\/h2>\n<p>\u5728Linux\u7cfb\u7edf\u4e2d\uff0c\u8981\u4f7f\u7528ping6\u547d\u4ee4\u6765ping IPv6\u7684\u5730\u5740\uff0c\u5e76\u4e14\u8981\u6c42\u5e26\u4e0a\u63a5\u53e3\u7d22\u5f15\u3002\u4f8b\u5982\u5982\u679c\u53ea\u662fping IPv6\u5730\u5740\uff0c\u4f1a\u8fd4\u56de\u4ee5\u4e0b\u9519\u8bef\uff1a<\/p>\n<pre>ping6 fe80::a00:27ff:fe37:a9d0\r\nconnect: Invalid argument<\/pre>\n<p>\u6b63\u786e\u7684\u4f7f\u7528\u65b9\u6cd5\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre>ping6 fe80::a00:27ff:fe37:a9d0%eth0<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5728linux\u73af\u5883\u4e0b\u83b7\u53d6\u672c\u5730IP\u5730\u5740\u7684\u65b9\u6cd5\uff0c\u901a\u5e38\u90fd\u662f\u5148getifaddrs\u83b7\u53d6\u5f53\u524d\u8ba1\u7b97\u673a\u4e2d\u6240\u6709\u7684\u63a5\u53e3\u4fe1\u606f\uff0c\u7136\u540e\u5faa\u73af\u8c03\u7528getnameinfo\u83b7\u53d6\u5404\u63a5\u53e3\u7684IP\u5730\u5740\u3002&#8230;<\/p>\n<p class=\"read-more\"><a class=\"btn btn-default\" href=\"https:\/\/www.myvoipapp.com\/blogs\/yxh\/2014\/05\/27\/linux%e7%8e%af%e5%a2%83%e4%b8%adgetnameinfo%e7%9a%84%e9%97%ae%e9%a2%98\/\"> Read More<span class=\"screen-reader-text\">  Read More<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[78,229,346,31],"class_list":["post-870","post","type-post","status-publish","format-standard","hentry","category-6","tag-debian","tag-ip","tag-local","tag-ubuntu"],"_links":{"self":[{"href":"https:\/\/www.myvoipapp.com\/blogs\/yxh\/wp-json\/wp\/v2\/posts\/870","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.myvoipapp.com\/blogs\/yxh\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.myvoipapp.com\/blogs\/yxh\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.myvoipapp.com\/blogs\/yxh\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.myvoipapp.com\/blogs\/yxh\/wp-json\/wp\/v2\/comments?post=870"}],"version-history":[{"count":9,"href":"https:\/\/www.myvoipapp.com\/blogs\/yxh\/wp-json\/wp\/v2\/posts\/870\/revisions"}],"predecessor-version":[{"id":1190,"href":"https:\/\/www.myvoipapp.com\/blogs\/yxh\/wp-json\/wp\/v2\/posts\/870\/revisions\/1190"}],"wp:attachment":[{"href":"https:\/\/www.myvoipapp.com\/blogs\/yxh\/wp-json\/wp\/v2\/media?parent=870"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.myvoipapp.com\/blogs\/yxh\/wp-json\/wp\/v2\/categories?post=870"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.myvoipapp.com\/blogs\/yxh\/wp-json\/wp\/v2\/tags?post=870"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}