getifs 0.6.1

Cross-platform enumeration of network interfaces and their MTU, gateway, multicast, and local/private/public IP addresses.
Documentation
name: CI

on:
  push:
    branches:
      - main
    paths-ignore:
      - 'README'
      - 'COPYRIGHT'
      - 'LICENSE-*'
      - '**.md'
      - '**.txt'
  pull_request:
    paths-ignore:
      - 'README'
      - 'COPYRIGHT'
      - 'LICENSE-*'
      - '**.md'
      - '**.txt'
  workflow_dispatch:
  schedule: 
    - cron: "0 1 1 * *"

env:
  CARGO_TERM_COLOR: always
  # RUSTFLAGS: -Dwarnings
  RUST_BACKTRACE: 1
  nightly: nightly
  stable: stable

jobs:
  # Check formatting
  rustfmt:
    name: rustfmt
    strategy:
      matrix:
        os:
          - ubuntu-latest
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v6
      - name: Install Rust
        # --no-self-update is necessary because the windows environment cannot self-update rustup.exe.
        run: rustup update stable --no-self-update && rustup default stable
      - name: Check formatting
        run: cargo fmt --all -- --check

  # Apply clippy lints
  clippy:
    name: clippy
    strategy:
      matrix:
        os:
          - ubuntu-latest
          - macos-latest
          - windows-latest
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v6
      - name: Install Rust
        # --no-self-update is necessary because the windows environment cannot self-update rustup.exe.
        run: rustup update stable --no-self-update && rustup default stable
      - name: Install cargo-hack
        run: cargo install cargo-hack
      - name: Apply clippy lints
        run: cargo hack clippy --each-feature --exclude-no-default-features

  build:
    name: build
    strategy:
      matrix:
        os:
          - ubuntu-latest
          - macos-latest
          - windows-latest
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v6
      - name: Cache cargo build and registry
        uses: actions/cache@v5
        with:
          path: |
            ~/.cargo/registry
            ~/.cargo/git
            target
          key: ${{ runner.os }}-build-${{ hashFiles('**/Cargo.lock') }}
          restore-keys: |
            ${{ runner.os }}-build-
      - name: Install Rust
        # --no-self-update is necessary because the windows environment cannot self-update rustup.exe.
        run: rustup update stable --no-self-update && rustup default stable
      - name: Cache ~/.cargo
        uses: actions/cache@v5
        with:
          path: ~/.cargo
          key: ${{ runner.os }}-coverage-dotcargo
      - name: Run build
        run: cargo build --all-features
  
  test:
    name: test
    strategy:
      matrix:
        os:
          - ubuntu-latest
          - macos-latest
          - windows-latest
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v6
      - name: Cache cargo build and registry
        uses: actions/cache@v5
        with:
          path: |
            ~/.cargo/registry
            ~/.cargo/git
            target
          key: ${{ runner.os }}-test-${{ hashFiles('**/Cargo.lock') }}
          restore-keys: |
            ${{ runner.os }}-test-
      - name: Install Rust
        # --no-self-update is necessary because the windows environment cannot self-update rustup.exe.
        run: rustup update stable --no-self-update && rustup default stable
      - name: Cache ~/.cargo
        uses: actions/cache@v5
        with:
          path: ~/.cargo
          key: ${{ runner.os }}-coverage-dotcargo
      - name: Run test
        run: cargo test --all-features -- --nocapture

  sanitizer:
    name: sanitizer
    strategy:
      matrix:
        os:
          - ubuntu-latest
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v6
      - name: Cache cargo build and registry
        uses: actions/cache@v5
        with:
          path: |
            ~/.cargo/registry
            ~/.cargo/git
            target
          key: ${{ runner.os }}-sanitizer-${{ hashFiles('**/Cargo.lock') }}
          restore-keys: |
            ${{ runner.os }}-sanitizer-
      - name: Install Rust
        run: rustup update $nightly && rustup default $nightly
      - name: Install rust-src
        run: rustup component add rust-src
      - name: Install cargo-hack
        run: cargo install cargo-hack
      - name: ASAN / LSAN / TSAN (Linux)
        run: ci/sanitizer.sh

  # Verify the library compiles cleanly across every supported target
  # triple. Platform-specific code (`linux_like` / `bsd_like` /
  # `windows` cfgs) is the main source of breakage here — changes to
  # any of the three paths should be caught by this matrix before they
  # land on users' machines.
  #
  # Uses `cargo check` rather than `cargo build` so we don't need a
  # target-specific linker installed in the runner — we're verifying
  # the source compiles for each target, not producing runnable
  # binaries.
  cross:
    name: cross
    strategy:
      fail-fast: false
      matrix:
        target:
          # --- Linux: glibc, musl, multiple architectures -----------
          - aarch64-unknown-linux-gnu
          - aarch64-unknown-linux-musl
          - i686-unknown-linux-gnu
          - powerpc64-unknown-linux-gnu
          - riscv64gc-unknown-linux-gnu

          # --- BSDs (uses the `bsd_like` code path) -----------------
          - x86_64-unknown-freebsd
          - x86_64-unknown-netbsd
          - i686-unknown-freebsd

          # --- Windows (MinGW / MSVC) -------------------------------
          - i686-pc-windows-gnu
          - x86_64-pc-windows-gnu
          - x86_64-pc-windows-msvc

          # --- Android (the `linux_like` path + the SIOCGIF* ioctl
          #     fallback in src/linux/android.rs) ----------------------
          - aarch64-linux-android
          - x86_64-linux-android
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6
      - name: Cache cargo registry
        uses: actions/cache@v5
        with:
          path: |
            ~/.cargo/registry
            ~/.cargo/git
            target
          key: ${{ runner.os }}-cross-${{ matrix.target }}-${{ hashFiles('**/Cargo.lock') }}
          restore-keys: |
            ${{ runner.os }}-cross-${{ matrix.target }}-
      - name: Install Rust + target
        run: |
          rustup update stable && rustup default stable
          rustup target add ${{ matrix.target }}
      - name: cargo check --target ${{ matrix.target }}
        run: cargo check --target ${{ matrix.target }}

  # Run the test suite inside real BSD VMs via https://github.com/vmactions.
  # The `cross` job above only verifies that the BSD cfg paths compile —
  # these jobs exercise them at runtime, which catches bugs (e.g. wrong
  # struct layouts, kernel-form sockaddr parsing) that pure compile
  # checks miss. Each BSD installs Rust from its own package manager.
  test-freebsd:
    name: test (freebsd)
    runs-on: ubuntu-latest
    timeout-minutes: 45
    steps:
      - uses: actions/checkout@v6
      - name: Test on FreeBSD
        uses: vmactions/freebsd-vm@v1
        with:
          usesh: true
          copyback: false
          prepare: |
            pkg install -y rust
          run: |
            cargo build --all-features
            cargo test --all-features -- --nocapture

  test-openbsd:
    name: test (openbsd)
    runs-on: ubuntu-latest
    timeout-minutes: 45
    steps:
      - uses: actions/checkout@v6
      - name: Test on OpenBSD
        uses: vmactions/openbsd-vm@v1
        with:
          usesh: true
          copyback: false
          prepare: |
            pkg_add -I rust
          run: |
            cargo build --all-features
            cargo test --all-features -- --nocapture

  # NetBSD only runs lib tests (`--lib`) — both doctests and the
  # `tests/` integration suite are skipped. Doctests in
  # `src/public_ip_addrs.rs` and the route APIs assume a populated
  # network stack the vmactions VM doesn't provide, and the
  # integration tests in `tests/interfaces.rs` /
  # `tests/filter_variants.rs` hit a `parse_addrs` "invalid address"
  # gap on NetBSD's `RTM_NEWADDR` slot encoding that we can't debug
  # without a real NetBSD shell. The per-test cfg gates in those
  # files stay in place as defensive coverage — if someone later
  # re-enables `--tests` here, the failing tests still skip
  # cleanly. Lib tests give us routine API-shape coverage; deeper
  # NetBSD-specific runtime testing should be done on a real host.
  test-netbsd:
    name: test (netbsd)
    runs-on: ubuntu-latest
    timeout-minutes: 45
    steps:
      - uses: actions/checkout@v6
      - name: Test on NetBSD
        uses: vmactions/netbsd-vm@v1
        with:
          usesh: true
          copyback: false
          prepare: |
            /usr/sbin/pkg_add rust
          run: |
            cargo build --all-features
            cargo test --all-features --lib -- --nocapture

  # DragonFlyBSD's `pkg` ships rust 1.85.x (as of 2026-05). Two
  # dev/dep crates require >1.85, so `cargo update --precise` pulls
  # both back to MSRV-compatible versions in this CI run only — the
  # Cargo.toml deps stay clean for real DragonFly users on a newer
  # toolchain (rustup, source build, etc.).
  #   - `smol_str` 0.3.6 (default `^0.3` resolution) declares
  #     `rust-version = 1.89`. Pin to 0.3.2 (last 0.3.x without a
  #     rust-version field).
  #   - `criterion` 0.8.x declares `rust-version = 1.86`. Pin to
  #     0.7.0 (last release supporting 1.80+).
  # Drop these `cargo update` lines once DragonFly's pkg catches up.
  #
  # DragonFly's `multicast_addrs()` returns
  # `Err(ErrorKind::Unsupported)` because the kernel doesn't expose
  # multicast-group enumeration via sysctl (no `NET_RT_IFMALIST`).
  # The `if_multicast_addrs` test compiles and runs on DragonFly,
  # treating the documented `Unsupported` error as a per-platform
  # skip — see tests/interfaces.rs.
  test-dragonflybsd:
    name: test (dragonflybsd)
    runs-on: ubuntu-latest
    timeout-minutes: 45
    steps:
      - uses: actions/checkout@v6
      - name: Test on DragonFlyBSD
        uses: vmactions/dragonflybsd-vm@v1
        with:
          usesh: true
          copyback: false
          prepare: |
            pkg install -y rust
          run: |
            cargo generate-lockfile
            cargo update -p smol_str --precise 0.3.2
            cargo update -p criterion --precise 0.7.0
            cargo build --all-features
            # Lib-only — same rationale as the NetBSD job above.
            # The vmactions DragonFly VM has too sparse a network
            # configuration (loopback + one non-loopback interface
            # with no IPv4 unicast address) to satisfy
            # `tests/interfaces.rs`'s `check_unicast_stats`
            # assertions, and the `interface_by_index` re-lookup in
            # `ifis` flakes due to interface churn during test runs.
            # The per-test cfg gates stay in place defensively.
            cargo test --all-features --lib -- --nocapture

  # Run the public API inside a real Android app process (the
  # `untrusted_app` SELinux domain) on an x86_64 emulator — the only
  # context that reproduces the SELinux restrictions the Android support
  # works around: the `bind` denial on `netlink_route_socket`
  # (b/155595000) and the `RTM_GETLINK` denial that drives the `SIOCGIF*`
  # ioctl fallback in `src/linux/android.rs`. The `cross` job above only
  # compile-checks the `*-linux-android` targets; this exercises them at
  # runtime. `cargo-ndk` builds the JNI shim crate (`ci/android/harness`)
  # into the app's `jniLibs`, and an instrumented test calls
  # `interfaces()` / `interface_by_index()` / `interface_addrs()` /
  # `gateway_addrs()` inside the app sandbox and asserts they succeed.
  test-android:
    name: test (android)
    runs-on: ubuntu-latest
    timeout-minutes: 45
    steps:
      - uses: actions/checkout@v6
      - name: Enable KVM
        run: |
          echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' \
            | sudo tee /etc/udev/rules.d/99-kvm4all.rules
          sudo udevadm control --reload-rules
          sudo udevadm trigger --name-match=kvm
      - uses: actions/setup-java@v4
        with:
          distribution: temurin
          java-version: "17"
      - name: Set NDK home for cargo-ndk
        run: echo "ANDROID_NDK_HOME=$ANDROID_NDK_LATEST_HOME" >> "$GITHUB_ENV"
      - name: Rust android target
        run: rustup target add x86_64-linux-android
      - name: Install cargo-ndk
        run: cargo install cargo-ndk --locked
      - name: Build native shim into app jniLibs
        working-directory: ci/android/harness
        run: cargo ndk -t x86_64 -o ../app/src/main/jniLibs build --release
      - name: Generate Gradle wrapper (pinned)
        working-directory: ci/android
        run: gradle wrapper --gradle-version 8.9
      - name: Run instrumented test on emulator
        uses: reactivecircus/android-emulator-runner@v2
        with:
          api-level: 34
          target: google_apis
          arch: x86_64
          working-directory: ci/android
          script: ./gradlew connectedAndroidTest