Go /etc/resolv.conf missing in android

huangapple go评论97阅读模式
英文:

Go /etc/resolv.conf missing in android

问题

我将我的Go源代码交叉编译为Arm架构,以在Android上运行。程序在Android设备的终端中运行,但是我收到一个错误,说/etc/resolv.conf文件丢失。我的程序在进行http调用时严重依赖于net/http库。

我该如何在Android中处理这个错误?

英文:

I cross compiled my Go source code to Arm to run in Android .The program runs in the terminal in the Android device, but I get an error saying that /etc/resolv.conf is missing. My program heavily relies on the net/http library in making http calls.

How can I handle this error in Android?

答案1

得分: 5

截至目前,你无法使用内置的net/http连接到主机名,可以查看这个问题(https://code.google.com/p/go/issues/detail?id=8020&q=%2Fetc%2Fresolv.conf&colspec=ID%20Status%20Stars%20Release%20Owner%20Repo%20Summary)。

有几种解决方法可以使用。

  1. 如果你有root访问权限,可以在程序启动时生成/etc/resolv.conf,虽然不太美观但简单易行。

  2. 将resolv.conf存储在某个地方,并修补http://golang.org/src/pkg/net/dnsclient_unix.go#L169以使用自定义路径。

  3. 修补$GOROOT/src/pkg/net/dnsconfig_unix.go以通过执行getprop net.dns1getprop net.dns2获取名称服务器。

  4. 实现完整的修补程序,参考https://gist.github.com/ernesto-jimenez/8042366。

英文:

As of right now you can't use the built in net/http to connect to hostnames, check this issue.

There are few workarounds you could use.

  1. generate /etc/resolv.conf on your program start if you have root access, ugly but easy and simple.

  2. store resolv.conf somewhere and patch http://golang.org/src/pkg/net/dnsclient_unix.go#L169 to use that custom path.

  3. patch $GOROOT/src/pkg/net/dnsconfig_unix.go to get the nameservers by executing getprop net.dns1 and getprop net.dns2.

  4. implement the full patch at https://gist.github.com/ernesto-jimenez/8042366

huangapple
  • 本文由 发表于 2014年9月11日 18:52:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/25785568.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定