From ded98ec2a24ed3837c164028d8d7464767878f1f Mon Sep 17 00:00:00 2001 From: Mads Odgaard Date: Sun, 8 Feb 2026 12:34:35 +0100 Subject: [PATCH 1/2] gate getifaddrs behind android availability --- Sources/NIOCore/SystemCallHelpers.swift | 7 +++++++ Sources/NIOCore/Utilities.swift | 6 ++++++ Sources/NIOMulticastChat/main.swift | 14 +++++++++++++- 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/Sources/NIOCore/SystemCallHelpers.swift b/Sources/NIOCore/SystemCallHelpers.swift index 8894fd2d6c1..cf374cf497a 100644 --- a/Sources/NIOCore/SystemCallHelpers.swift +++ b/Sources/NIOCore/SystemCallHelpers.swift @@ -56,6 +56,9 @@ private let sysRead: @convention(c) (CInt, UnsafeMutableRawPointer?, size_t) -> #if os(Android) private let sysIfNameToIndex: @convention(c) (UnsafePointer) -> CUnsignedInt = if_nametoindex +#if compiler(>=6.3) +@available(Android 24, *) +#endif private let sysGetifaddrs: @convention(c) (UnsafeMutablePointer?>) -> CInt = getifaddrs #elseif !os(WASI) private let sysIfNameToIndex: @convention(c) (UnsafePointer?) -> CUnsignedInt = if_nametoindex @@ -228,8 +231,12 @@ enum SystemCalls { } #if !os(Windows) + @inline(never) @usableFromInline +#if compiler(>=6.3) + @available(Android 24, *) +#endif internal static func getifaddrs(_ addrs: UnsafeMutablePointer?>) throws { _ = try syscall(blocking: false) { sysGetifaddrs(addrs) diff --git a/Sources/NIOCore/Utilities.swift b/Sources/NIOCore/Utilities.swift index b9a0c788cb4..6d5e550bb09 100644 --- a/Sources/NIOCore/Utilities.swift +++ b/Sources/NIOCore/Utilities.swift @@ -160,6 +160,9 @@ public enum System: Sendable { /// - Returns: An array of network interfaces available on this machine. /// - Throws: If an error is encountered while enumerating interfaces. @available(*, deprecated, renamed: "enumerateDevices") +#if compiler(>=6.3) + @available(Android 24, *) +#endif public static func enumerateInterfaces() throws -> [NIONetworkInterface] { var interfaces: [NIONetworkInterface] = [] interfaces.reserveCapacity(12) // Arbitrary choice. @@ -190,6 +193,9 @@ public enum System: Sendable { /// /// - Returns: An array of network devices available on this machine. /// - Throws: If an error is encountered while enumerating interfaces. +#if compiler(>=6.3) + @available(Android 24, *) +#endif public static func enumerateDevices() throws -> [NIONetworkDevice] { var devices: [NIONetworkDevice] = [] devices.reserveCapacity(12) // Arbitrary choice. diff --git a/Sources/NIOMulticastChat/main.swift b/Sources/NIOMulticastChat/main.swift index b71f6bb9a54..a6a839ff7a5 100644 --- a/Sources/NIOMulticastChat/main.swift +++ b/Sources/NIOMulticastChat/main.swift @@ -53,7 +53,19 @@ let targetDevice: NIONetworkDevice? = { if let interfaceAddress = CommandLine.arguments.dropFirst().first, let targetAddress = try? SocketAddress(ipAddress: interfaceAddress, port: 0) { - for device in try! System.enumerateDevices() { + let devices: [NIONetworkDevice] + +#if compiler(>=6.3) + if #available(Android 24, *) { + devices = try! System.enumerateDevices() + } else { + fatalError("This demo only works on Android API 24+") + } +#else + devices = try! System.enumerateDevices() +#endif + + for device in devices { if device.address == targetAddress { return device } From 01b30a5d36d40a792ed39d0f35da1180fd3bd993 Mon Sep 17 00:00:00 2001 From: Mads Odgaard Date: Mon, 9 Feb 2026 18:27:27 +0100 Subject: [PATCH 2/2] run swift format --- Sources/NIOCore/SystemCallHelpers.swift | 6 +++--- Sources/NIOCore/Utilities.swift | 8 ++++---- Sources/NIOMulticastChat/main.swift | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Sources/NIOCore/SystemCallHelpers.swift b/Sources/NIOCore/SystemCallHelpers.swift index cf374cf497a..d1e00224e30 100644 --- a/Sources/NIOCore/SystemCallHelpers.swift +++ b/Sources/NIOCore/SystemCallHelpers.swift @@ -231,12 +231,12 @@ enum SystemCalls { } #if !os(Windows) - + @inline(never) @usableFromInline -#if compiler(>=6.3) + #if compiler(>=6.3) @available(Android 24, *) -#endif + #endif internal static func getifaddrs(_ addrs: UnsafeMutablePointer?>) throws { _ = try syscall(blocking: false) { sysGetifaddrs(addrs) diff --git a/Sources/NIOCore/Utilities.swift b/Sources/NIOCore/Utilities.swift index 6d5e550bb09..db5a6bcc15f 100644 --- a/Sources/NIOCore/Utilities.swift +++ b/Sources/NIOCore/Utilities.swift @@ -160,9 +160,9 @@ public enum System: Sendable { /// - Returns: An array of network interfaces available on this machine. /// - Throws: If an error is encountered while enumerating interfaces. @available(*, deprecated, renamed: "enumerateDevices") -#if compiler(>=6.3) + #if compiler(>=6.3) @available(Android 24, *) -#endif + #endif public static func enumerateInterfaces() throws -> [NIONetworkInterface] { var interfaces: [NIONetworkInterface] = [] interfaces.reserveCapacity(12) // Arbitrary choice. @@ -193,9 +193,9 @@ public enum System: Sendable { /// /// - Returns: An array of network devices available on this machine. /// - Throws: If an error is encountered while enumerating interfaces. -#if compiler(>=6.3) + #if compiler(>=6.3) @available(Android 24, *) -#endif + #endif public static func enumerateDevices() throws -> [NIONetworkDevice] { var devices: [NIONetworkDevice] = [] devices.reserveCapacity(12) // Arbitrary choice. diff --git a/Sources/NIOMulticastChat/main.swift b/Sources/NIOMulticastChat/main.swift index a6a839ff7a5..453c5022d00 100644 --- a/Sources/NIOMulticastChat/main.swift +++ b/Sources/NIOMulticastChat/main.swift @@ -55,15 +55,15 @@ let targetDevice: NIONetworkDevice? = { { let devices: [NIONetworkDevice] -#if compiler(>=6.3) + #if compiler(>=6.3) if #available(Android 24, *) { devices = try! System.enumerateDevices() } else { fatalError("This demo only works on Android API 24+") } -#else + #else devices = try! System.enumerateDevices() -#endif + #endif for device in devices { if device.address == targetAddress {