Discussion:
getting busybox DNS (ping, nslookup) to work on android
rouble
2011-04-13 19:59:32 UTC
Permalink
BB Gurus,

I have compiled busybox as a static binary for an android system.

Most things work great, but I can not get any of the DNS related
applets (nslookup, ping, traceroute etc) to work for domain names.
They work fine for IP addresses. I think what is happening is that
busybox is looking for some specific libc libraries that are missing -
since android uses bionic instead of libc.

Does anyone know of a way to get this to work?

Here is what happens on the command line:
# strace -tt -s99 -oLOG nslookup www.google.com
Server:??? 0.0.0.0
Address 1: 0.0.0.0

nslookup: can't resolve 'www.google.com'

I can provide detailed logs if required.

tia,
rouble
rouble
2011-04-13 20:06:44 UTC
Permalink
BB Gurus,

(My emails seem to be bouncing off busybox.net, so please excuse me if
this posts twice)

I have compiled busybox as a static binary for an android system.

Most things work great, but I can not get any of the DNS related
applets (nslookup, ping, traceroute etc) to work for domain names.
They work fine for IP addresses. I think what is happening is that
busybox is looking for some specific libc libraries that are missing -
since android uses bionic instead of libc.

Does anyone know of a way to get this to work?

Here is what happens on the command line:
# strace -tt -s99 -oLOG nslookup www.google.com
Server:??? 0.0.0.0
Address 1: 0.0.0.0

nslookup: can't resolve 'www.google.com'

I can provide detailed logs if required.

tia,
rouble
--
this message is composed of 100% recycled ascii
Mikhail Gusarov
2011-04-13 20:03:45 UTC
Permalink
Twas brillig at 15:59:32 13.04.2011 UTC-04 when r.ouble at gmail.com did gyre and gimble:

r> I have compiled busybox as a static binary for an android system.

Did you build against glibc or uclibc?
--
http://fossarchy.blogspot.com/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 489 bytes
Desc: not available
URL: <http://lists.busybox.net/pipermail/busybox/attachments/20110413/c3958e39/attachment.asc>
Dan Fandrich
2011-04-13 20:12:05 UTC
Permalink
Post by rouble
I have compiled busybox as a static binary for an android system.
Most things work great, but I can not get any of the DNS related
applets (nslookup, ping, traceroute etc) to work for domain names.
They work fine for IP addresses. I think what is happening is that
busybox is looking for some specific libc libraries that are missing -
since android uses bionic instead of libc.
Does anyone know of a way to get this to work?
You don't say which libc you used when you statically linked Busybox. If you
used bionic, then it should just work. If you used glibc, then you've
probably hit that well-known broken-by-design feature such that the DNS
functions can't be statically linked and must be available in a dynamic
library at run-time. You could either make those libs available, or link
against another libc.
Post by rouble
Dan
rouble
2011-04-13 20:41:00 UTC
Permalink
Hi Dan, Mikhail,

I was told that the toolchain I was using is setup to use bionic. Is
there a way to tell what libc is being used?

Could this have something to do with the fact that I am building a
static binary?

tia,
rouble
Post by Dan Fandrich
Post by rouble
I have compiled busybox as a static binary for an android system.
Most things work great, but I can not get any of the DNS related
applets (nslookup, ping, traceroute etc) to work for domain names.
They work fine for IP addresses. I think what is happening is that
busybox is looking for some specific libc libraries that are missing -
since android uses bionic instead of libc.
Does anyone know of a way to get this to work?
You don't say which libc you used when you statically linked Busybox. If you
used bionic, then it should just work. If you used glibc, then you've
probably hit that well-known broken-by-design feature such that the DNS
functions can't be statically linked and must be available in a dynamic
library at run-time. ?You could either make those libs available, or link
against another libc.
Post by rouble
Dan
_______________________________________________
busybox mailing list
busybox at busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
Dan Fandrich
2011-04-13 20:55:57 UTC
Permalink
Post by rouble
I was told that the toolchain I was using is setup to use bionic. Is
there a way to tell what libc is being used?
The easiest way is to look at the link command line and look at the paths
and libraries being used.
Post by rouble
Could this have something to do with the fact that I am building a
static binary?
As I described, the problem you're seeing could very well be due to this.
Post by rouble
Dan
Tito
2011-04-14 05:57:18 UTC
Permalink
Post by rouble
BB Gurus,
I have compiled busybox as a static binary for an android system.
Most things work great, but I can not get any of the DNS related
applets (nslookup, ping, traceroute etc) to work for domain names.
They work fine for IP addresses. I think what is happening is that
busybox is looking for some specific libc libraries that are missing -
since android uses bionic instead of libc.
Does anyone know of a way to get this to work?
# strace -tt -s99 -oLOG nslookup www.google.com
Server:??? 0.0.0.0
Address 1: 0.0.0.0
nslookup: can't resolve 'www.google.com'
I can provide detailed logs if required.
tia,
rouble
Hi,
You have to add a resolv.conf file in /system/etc like:

---------------------------------------------------------------------------------------------
nameserver 8.8.8.8
nameserver 8.8.4.4


---------------------------------------------------------------------------------------------

Ciao,
Tito
Tito
2011-04-14 18:51:30 UTC
Permalink
I do have a /etc/resolv.conf. It points to the localhost that routes the DNS
queries appropriately. I have also tried using another valid name server -
which yields the same result.
# cat /etc/resolv.conf
nameserver 127.0.0.1:53
# strace -tt -s99 -oLOG nslookup www.google.com
Server: 0.0.0.0
Address 1: 0.0.0.0
nslookup: can't resolve 'www.google.com'
# cat LOG
15:10:32.686311 execve("/system/xbin/nslookup", ["nslookup", "www.google.com"],
[/* 14 vars */]) = 0
15:10:32.694534 uname({sys="Linux", node="localhost", ...}) = 0
15:10:32.695684 brk(0) = 0x8718000
15:10:32.695915 brk(0x8718cd0) = 0x8718cd0
15:10:32.696221 set_thread_area({entry_number:-1 -> 6, base_addr:0x8718850,
limit:1048575, seg_32bit:1, contents:0, read_exec_only:0, limit_in_pages:1,
seg_not_present:0, useable:1}) = 0
15:10:32.696676 brk(0x8739cd0) = 0x8739cd0
15:10:32.696903 brk(0x873a000) = 0x873a000
15:10:32.697341 getuid32() = 0
15:10:32.697582 getpid() = 30438
15:10:32.697868 open("/etc/resolv.conf", O_RDONLY) = 3
15:10:32.698275 fstat64(3, {st_mode=S_IFREG|0666, st_size=24, ...}) = 0
15:10:32.698773 mmap2(NULL, 4096, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb77ea000
15:10:32.699038 read(3, "nameserver 127.0.0.1:53\n", 1024) = 24
15:10:32.699421 read(3, "", 1024) = 0
15:10:32.699654 close(3) = 0
15:10:32.699882 munmap(0xb77ea000, 4096) = 0
15:10:32.700188 uname({sys="Linux", node="localhost", ...}) = 0
15:10:32.701512 fstat64(1, {st_mode=S_IFCHR|0600, st_rdev=makedev(136, 0),
...}) = 0
15:10:32.701985 mmap2(NULL, 4096, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb77ea000
15:10:32.702267 write(1, "Server: 0.0.0.0\n", 19) = 19
15:10:32.702659 socket(PF_UNIX, SOCK_STREAM, 0) = 3
15:10:32.703056 fcntl64(3, F_GETFL) = 0x2 (flags O_RDWR)
15:10:32.703316 fcntl64(3, F_SETFL, O_RDWR|O_NONBLOCK) = 0
15:10:32.703573 connect(3, {sa_family=AF_UNIX, path="/var/run/nscd/socket"},
110) = -1 ENOENT (No such file or directory)
15:10:32.704146 close(3) = 0
15:10:32.704571 socket(PF_UNIX, SOCK_STREAM, 0) = 3
15:10:32.704817 fcntl64(3, F_GETFL) = 0x2 (flags O_RDWR)
15:10:32.705150 fcntl64(3, F_SETFL, O_RDWR|O_NONBLOCK) = 0
15:10:32.705470 connect(3, {sa_family=AF_UNIX, path="/var/run/nscd/socket"},
110) = -1 ENOENT (No such file or directory)
15:10:32.706137 close(3) = 0
15:10:32.706406 open("/etc/nsswitch.conf", O_RDONLY) = -1 ENOENT (No such
file or directory)
15:10:32.706831 open("/system/lib/libnss_dns.so.2", O_RDONLY) = -1 ENOENT
(No such file or directory)
15:10:32.707143 stat64("/system/lib", {st_mode=S_IFDIR|0755, st_size=10240,
...}) = 0
15:10:32.707639 open("/system/lib/egl/libnss_dns.so.2", O_RDONLY) = -1
ENOENT (No such file or directory)
15:10:32.707955 stat64("/system/lib/egl", {st_mode=S_IFDIR|0755,
st_size=1024, ...}) = 0
15:10:32.708496 open("/system/lib/anyconnect-lib/libnss_dns.so.2", O_RDONLY)
= -1 ENOENT (No such file or directory)
15:10:32.708868 stat64("/system/lib/anyconnect-lib", {st_mode=S_IFDIR|0755,
st_size=1024, ...}) = 0
15:10:32.709611 open("/etc/ld.so.cache", O_RDONLY) = -1 ENOENT (No such file
or directory)
15:10:32.709940 open("/lib/libnss_dns.so.2", O_RDONLY) = -1 ENOENT (No such
file or directory)
15:10:32.710238 stat64("/lib", 0xbfc5a5a8) = -1 ENOENT (No such file or
directory)
15:10:32.710497 open("/usr/lib/libnss_dns.so.2", O_RDONLY) = -1 ENOENT (No
such file or directory)
15:10:32.710801 stat64("/usr/lib", 0xbfc5a5a8) = -1 ENOENT (No such file or
directory)
15:10:32.711093 open("/system/lib/libnss_files.so.2", O_RDONLY) = -1 ENOENT
(No such file or directory)
15:10:32.711413 open("/system/lib/egl/libnss_files.so.2", O_RDONLY) = -1
ENOENT (No such file or directory)
15:10:32.711741 open("/system/lib/anyconnect-lib/libnss_files.so.2",
O_RDONLY) = -1 ENOENT (No such file or directory)
15:10:32.712153 write(1, "Address 1: 0.0.0.0\n", 19) = 19
15:10:32.712469 write(1, "\n", 1) = 1
15:10:32.712762 write(2, "nslookup: can\'t resolve \'www.google.com\'\n",
41) = 41
15:10:32.713347 exit_group(1) = ?
Post by Tito
Post by rouble
BB Gurus,
I have compiled busybox as a static binary for an android system.
Most things work great, but I can not get any of the DNS related
applets (nslookup, ping, traceroute etc) to work for domain names.
They work fine for IP addresses. I think what is happening is that
busybox is looking for some specific libc libraries that are missing -
since android uses bionic instead of libc.
Does anyone know of a way to get this to work?
# strace -tt -s99 -oLOG nslookup www.google.com
Server: 0.0.0.0
Address 1: 0.0.0.0
nslookup: can't resolve 'www.google.com'
I can provide detailed logs if required.
tia,
rouble
Hi,
---------------------------------------------------------------------------------------------
Post by Tito
nameserver 8.8.8.8
nameserver 8.8.4.4
---------------------------------------------------------------------------------------------
Post by Tito
Ciao,
Tito
Seems to me you miss lib_dns* and nsswitch.conf.
Try a statically compiled busybox or add the missing libraries
to your system.

Ciao,
Tito
Denys Vlasenko
2011-04-16 16:44:52 UTC
Permalink
I do have a /etc/resolv.conf. It points to the localhost that routes the DNS
queries appropriately. I have also tried using another valid name server -
which yields the same result.
# cat /etc/resolv.conf
nameserver 127.0.0.1:53
# strace -tt -s99 -oLOG nslookup www.google.com
Server: 0.0.0.0
Address 1: 0.0.0.0
nslookup: can't resolve 'www.google.com'
# cat LOG
15:10:32.686311 execve("/system/xbin/nslookup", ["nslookup", "www.google.com"],
[/* 14 vars */]) = 0
15:10:32.694534 uname({sys="Linux", node="localhost", ...}) = 0
15:10:32.695684 brk(0) = 0x8718000
15:10:32.695915 brk(0x8718cd0) = 0x8718cd0
15:10:32.696221 set_thread_area({entry_number:-1 -> 6, base_addr:0x8718850,
limit:1048575, seg_32bit:1, contents:0, read_exec_only:0, limit_in_pages:1,
seg_not_present:0, useable:1}) = 0
15:10:32.696676 brk(0x8739cd0) = 0x8739cd0
15:10:32.696903 brk(0x873a000) = 0x873a000
15:10:32.697341 getuid32() = 0
15:10:32.697582 getpid() = 30438
15:10:32.697868 open("/etc/resolv.conf", O_RDONLY) = 3
15:10:32.698275 fstat64(3, {st_mode=S_IFREG|0666, st_size=24, ...}) = 0
15:10:32.698773 mmap2(NULL, 4096, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb77ea000
15:10:32.699038 read(3, "nameserver 127.0.0.1:53\n", 1024) = 24
15:10:32.699421 read(3, "", 1024) = 0
15:10:32.699654 close(3) = 0
15:10:32.699882 munmap(0xb77ea000, 4096) = 0
15:10:32.700188 uname({sys="Linux", node="localhost", ...}) = 0
15:10:32.701512 fstat64(1, {st_mode=S_IFCHR|0600, st_rdev=makedev(136, 0),
...}) = 0
15:10:32.701985 mmap2(NULL, 4096, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb77ea000
15:10:32.702267 write(1, "Server: 0.0.0.0\n", 19) = 19
15:10:32.702659 socket(PF_UNIX, SOCK_STREAM, 0) = 3
15:10:32.703056 fcntl64(3, F_GETFL) = 0x2 (flags O_RDWR)
15:10:32.703316 fcntl64(3, F_SETFL, O_RDWR|O_NONBLOCK) = 0
15:10:32.703573 connect(3, {sa_family=AF_UNIX, path="/var/run/nscd/socket"},
110) = -1 ENOENT (No such file or directory)
15:10:32.704146 close(3) = 0
15:10:32.704571 socket(PF_UNIX, SOCK_STREAM, 0) = 3
15:10:32.704817 fcntl64(3, F_GETFL) = 0x2 (flags O_RDWR)
15:10:32.705150 fcntl64(3, F_SETFL, O_RDWR|O_NONBLOCK) = 0
15:10:32.705470 connect(3, {sa_family=AF_UNIX, path="/var/run/nscd/socket"},
110) = -1 ENOENT (No such file or directory)
15:10:32.706137 close(3) = 0
15:10:32.706406 open("/etc/nsswitch.conf", O_RDONLY) = -1 ENOENT (No such
file or directory)
This (access to /etc/nsswitch.conf) looks glibc-like.

Is Bionic based on glibc or uses glibc-like NSS plug-in name resolution?
If not, then your program is statically linked against glibc, not Bionic.
15:10:32.706831 open("/system/lib/libnss_dns.so.2", O_RDONLY) = -1 ENOENT
(No such file or directory)
15:10:32.707143 stat64("/system/lib", {st_mode=S_IFDIR|0755, st_size=10240,
...}) = 0
15:10:32.707639 open("/system/lib/egl/libnss_dns.so.2", O_RDONLY) = -1
ENOENT (No such file or directory)
15:10:32.707955 stat64("/system/lib/egl", {st_mode=S_IFDIR|0755,
st_size=1024, ...}) = 0
15:10:32.708496 open("/system/lib/anyconnect-lib/libnss_dns.so.2", O_RDONLY)
= -1 ENOENT (No such file or directory)
15:10:32.708868 stat64("/system/lib/anyconnect-lib", {st_mode=S_IFDIR|0755,
st_size=1024, ...}) = 0
15:10:32.709611 open("/etc/ld.so.cache", O_RDONLY) = -1 ENOENT (No such file
or directory)
15:10:32.709940 open("/lib/libnss_dns.so.2", O_RDONLY) = -1 ENOENT (No such
file or directory)
15:10:32.710238 stat64("/lib", 0xbfc5a5a8) = -1 ENOENT (No such file or
directory)
15:10:32.710497 open("/usr/lib/libnss_dns.so.2", O_RDONLY) = -1 ENOENT (No
such file or directory)
15:10:32.710801 stat64("/usr/lib", 0xbfc5a5a8) = -1 ENOENT (No such file or
directory)
15:10:32.711093 open("/system/lib/libnss_files.so.2", O_RDONLY) = -1 ENOENT
(No such file or directory)
15:10:32.711413 open("/system/lib/egl/libnss_files.so.2", O_RDONLY) = -1
ENOENT (No such file or directory)
15:10:32.711741 open("/system/lib/anyconnect-lib/libnss_files.so.2",
O_RDONLY) = -1 ENOENT (No such file or directory)
15:10:32.712153 write(1, "Address 1: 0.0.0.0\n", 19) = 19
15:10:32.712469 write(1, "\n", 1) = 1
15:10:32.712762 write(2, "nslookup: can\'t resolve \'www.google.com\'\n",
41) = 41
So, it found neither NSS config (thus used default one) nor any NSS libraries.
The system you took this strace on is definitely has no NSS stuff.

I would hazard to guess you (possibly unknowingly) linked against glibc
but Android doesn't use glibc.
--
vda
Loading...