Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set DefaultResolver for Android #572

Merged
merged 10 commits into from
Jan 2, 2021
Merged

set DefaultResolver for Android #572

merged 10 commits into from
Jan 2, 2021

Conversation

CalmLong
Copy link
Contributor

@CalmLong CalmLong commented Jan 1, 2021

修复 v2ray/v2ray-core/issues/1909

实现原理

Go 的程序启动后,会读取 /etc/resolv.conf 内的 DNS,用于域名解析的 net.DefaultResolver 变量会使用这些 DNS

默认情况下所有域名解析相关的函数都会使用 net.DefaultResolver,其他项目也会使用这个,比如已存在的 QUIC 包

由于 Android 并不存在 /etc/resolv.conf ,Go 语言使用了它的默认值 127.0.0.1:53 地址作为 DNS 服务器,但 Android 也同样不存在这个 DNS 服务器

这时 net.DefaultResolver 内的 DNS 地址为 127.0.0.1:53

所以在 Android 操作系统中运行二进制程序会出现域名解析的问题

由此,此 PR 为 Android 系统替换默认的 net.DefaultResolver,为其设置 DNS 8.8.8.8:53

编译时按照文档编译即可

@kslr
Copy link
Contributor

kslr commented Jan 1, 2021

有两个做法:

  1. 新建 dns_android.go 通过 build tag 指定平台编译
  2. 移动到 common 中,添加 build tag 然后引入到 dns.go 里

@CalmLong
Copy link
Contributor Author

CalmLong commented Jan 2, 2021

Test 只能这样写了 (无奈

@kslr kslr merged commit 3eb1386 into v2fly:master Jan 2, 2021
@kslr
Copy link
Contributor

kslr commented Jan 2, 2021

Thanks for your work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants