Skip to content

Conversation

@luqmana
Copy link
Contributor

@luqmana luqmana commented Oct 30, 2025

Description

The libc crate links against the legacy version of getifaddrs on illumos which only returns AF_INET[6] entries.

As of illumos#11196, getifaddrs was updated to also return AF_LINK entries but was done in such a way to preserve existing binaries that only expected the old behaviour. That is, the symbol getifaddrs would refer to the legacy version but newly compiled C programs would get the new version by linking against __getifaddrs (via a redefine_extname pragma in ifaddrs.h).

fn main() {
    let mut addrs = std::mem::MaybeUninit::uninit();
    if unsafe { libc::getifaddrs(addrs.as_mut_ptr()) } != 0 {
        return;
    }
    let addrs = unsafe { addrs.assume_init() };
    let mut addr = addrs;
    while !addr.is_null() {
        let a = unsafe { &*addr };
        addr = a.ifa_next;
        let name = unsafe { std::ffi::CStr::from_ptr(a.ifa_name) };
        let name = name.to_string_lossy();
        if a.ifa_addr.is_null() {
            continue;
        }
        let fam = match unsafe { (*a.ifa_addr).sa_family } as libc::c_int {
            libc::AF_INET => "AF_INET",
            libc::AF_INET6 => "AF_INET6",
            libc::AF_LINK => "AF_LINK",
            _ => "<other>",
        };
        println!("{name}\t{fam}");
    }
    unsafe {
        libc::freeifaddrs(addrs);
    }
}

Before:

$  cargo r
   Compiling getifaddrs-test v0.1.0 (/home/luqman/tmp/getifaddrs-test)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.43s
     Running `target/debug/getifaddrs-test`
lo0     AF_INET
igb0    AF_INET
lo0     AF_INET6
igb0    AF_INET6

After:

$  cargo r
     Locking 1 package to latest Rust 1.88.0 compatible version
      Adding libc v1.0.0-alpha.1 (/home/luqman/src/libc)
   Compiling libc v1.0.0-alpha.1 (/home/luqman/src/libc)
   Compiling getifaddrs-test v0.1.0 (/home/luqman/tmp/getifaddrs-test)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 1.65s
     Running `target/debug/getifaddrs-test`
lo0     AF_INET
igb0    AF_INET
lo0     AF_INET6
igb0    AF_INET6
igb0    AF_LINK
igb1    AF_LINK

Sources

Checklist

  • Relevant tests in libc-test/semver have been updated (getifaddrs is excluded on illumos)
  • No placeholder or unstable values like *LAST or *MAX are included (see #3131)
  • Tested locally (See above test program demonstrating issue. But libc-test seems broken on illumos on main)

This is potentially a breaking change but it would be nice to get in 0.2. Unsure what the exact policy is there.

@rustbot label +stable-nominated

@rustbot
Copy link
Collaborator

rustbot commented Oct 30, 2025

Some changes occurred in solarish module

cc @jclulow, @pfmooney

@rustbot rustbot added O-solarish O-unix S-waiting-on-review stable-nominated This PR should be considered for cherry-pick to libc's stable release branch labels Oct 30, 2025
@pfmooney
Copy link
Contributor

I believe this will require an updated sysroot to avoid breaking the rust toolchain builds, as the current sysroot is from 2018: https://github.com/illumos/sysroot/releases/tag/20181213-de6af22ae73b-v1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

O-solarish O-unix S-waiting-on-review stable-nominated This PR should be considered for cherry-pick to libc's stable release branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants