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

std.net.getAddressList on android platform #22031

Open
Iced-Sun opened this issue Nov 20, 2024 · 0 comments
Open

std.net.getAddressList on android platform #22031

Iced-Sun opened this issue Nov 20, 2024 · 0 comments
Labels
bug Observed behavior contradicts documented or intended behavior

Comments

@Iced-Sun
Copy link

Zig Version

0.13.0, 0.14.0-dev.2211+05a3ac43e, 0.14.0-dev.2254+73f2671c7

Steps to Reproduce and Observed Behavior

  1. create a simple snippet:
const std = @import("std");

pub fn main() !void {
    const address_list = try std.net.getAddressList(std.heap.page_allocator, "google.com", 443);

    std.debug.print("{any}\n", .{address_list});
}
  1. create android-libc.txt to point ndk libc:
include_dir=thirdparty/android/sysroot/usr/include/
sys_include_dir=thirdparty/android/sysroot/usr/include/arm-linux-androideabi
crt_dir=thirdparty/android/sysroot/usr/lib/arm-linux-androideabi/30
static_crt_dir=thirdparty/android/sysroot/usr/lib/arm-linux-androideabi
msvc_lib_dir=
kernel32_lib_dir=
gcc_dir=
  1. build exe with target=arm-linux-android, link_libc=true, linkage=dynamic, libc_file=android-libc.txt, run exe on android:
net.AddressList{ .arena = heap.arena_allocator.ArenaAllocator{ .child_allocator = mem.Allocator{ .ptr = anyopaque@0, .vtable = mem.Allocator.VTable{ ... } }, .state = heap.arena_allocator.ArenaAllocator.State{ .buffer_list = linked_list.SinglyLinkedList(usize){ ... }, .end_index = 32 } }, .addrs = {  }, .canon_name = null }
  1. build exe with simply target=arm-linux-android, run exe on android
error.TemporaryNameServerFailure
  1. run exe from step 4 on linux host with qemu-arm
net.AddressList{ .arena = heap.arena_allocator.ArenaAllocator{ .child_allocator = mem.Allocator{ .ptr = anyopaque@0, .vtable = mem.Allocator.VTable{ ... } }, .state = heap.arena_allocator.ArenaAllocator.State{ .buffer_list = linked_list.SinglyLinkedList(usize){ ... }, .end_index = 276 } }, .addrs = { 93.46.8.90:443, [2404:6800:4012:5::200e]:443 }, .canon_name = { 103, 111, 111, 103, 108, 101, 46, 99, 111, 109 } }

Expected Behavior

The result in step 5 is expected.

The result in step 4 is not expected, although intentional. std.net.getAddressList invokes std.net.linuxLookupName, which requires a hard-coded /etc/resolv.conf to work. Android has no /etc/resolv.conf.

The result in step 3 is not expected and seems to be a bug. std.net.getAddressList invokes std.posix.system.getaddrinfo with link_libc=true. By providing an wrapped getaddrinfo, I confirm that getaddrinfo does write a valid sockaddr on C-side, but the resulting zig-side addr is null, producing an empty address list. As a workaround, I have to wrap getaddrinfo to fill back result.addrs.

@Iced-Sun Iced-Sun added the bug Observed behavior contradicts documented or intended behavior label Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior
Projects
None yet
Development

No branches or pull requests

1 participant