当使用gen_tcp
的connect
方法时,IPv4域将自动解析,即:
:gen_tcp.connect('google.com', 443, [:binary, active: false])
{:ok, #Port<0.116>}
但是,如果解析IPv6域,则无法正确解析
iex(production@b7726c04)3> :gen_tcp.connect('ipv6.google.com', 443, [:binary, active: false])
{:error, :nxdomain}
我是否缺少:gen_tcp.connect
套接字选项中的一个选项,该选项将启用IPv6解析,或者我是否必须在使用之前自己手动解析域?例如:
:inet_res.resolve('ipv6.google.com', :in, :aaaa)
{:ok,
{:dns_rec, {:dns_header, 1, true, :query, false, false, true, true, false, 0},
[{:dns_query, 'ipv6.google.com', :aaaa, :in, false}],
[
{:dns_rr, 'ipv6.google.com', :cname, :in, 0, 604606, 'ipv6.l.google.com',
:undefined, [], false},
{:dns_rr, 'ipv6.l.google.com', :aaaa, :in, 0, 300,
{9220, 26624, 16387, 3072, 0, 0, 0, 101}, :undefined, [], false},
{:dns_rr, 'ipv6.l.google.com', :aaaa, :in, 0, 300,
{9220, 26624, 16387, 3072, 0, 0, 0, 102}, :undefined, [], false},
{:dns_rr, 'ipv6.l.google.com', :aaaa, :in, 0, 300,
{9220, 26624, 16387, 3072, 0, 0, 0, 113}, :undefined, [], false},
{:dns_rr, 'ipv6.l.google.com', :aaaa, :in, 0, 300,
{9220, 26624, 16387, 3072, 0, 0, 0, 100}, :undefined, [], false}
], [], []}}
然后直接使用IPv6元组:
:gen_tcp.connect({9220, 26624, 16387, 3072, 0, 0, 0, 101}, 443, [:binary, active: false])
{:ok, #Port<0.138>}
1条答案
按热度按时间lsmd5eda1#
您可以使用
inet6
: