Files
screen_cast/ios/Receiver/Support/LocalAddress.swift
T
fegger c43dd3ca4a feat(ios): native receiver app (Swift, min iOS 17)
A native iOS receiver so an iPhone can act as the second receiver, speaking the existing signaling + RTP protocol (no C++ changes) and mirroring the Android receiver (Phase 8) source-to-source.

- RTP core (header/packet, jitter buffer, H.264 depacketizer) ported from the Android receiver
- BSD-socket signaling server (dual-stack, most-recent-peer, never-throwing sends) + NSBonjourServices
- VideoToolbox H.264 decode (in-band SPS/PPS, real-time, rebuilds on size change) -> AVSampleBufferDisplayLayer
- PLI keyframe recovery (500 ms) + pendingOffer for late surface attach
- XcodeGen project + bootstrap.sh; XCTest port of the Android suite + new coverage
- .gitignore for generated artifacts; CHANGELOG; PHASES + MEMORY updated

Status: authored; on-device validation pending a Mac + Xcode 26 + iPhone 16.
2026-09-10 21:31:53 +02:00

42 lines
1.6 KiB
Swift

import Foundation
#if canImport(Darwin)
import Darwin
#endif
/// Finds the primary IPv4 address (e.g. on Wi-Fi) for the status overlay and
/// the `--peer` hint. Best-effort; the sender reaches us by IP over the LAN.
enum LocalAddress {
static func primaryIPv4() -> String {
var result = "unknown"
var fallback = "unknown"
var ptr: UnsafeMutablePointer<ifaddrs>?
guard getifaddrs(&ptr) == 0 else { return result }
defer { freeifaddrs(ptr) }
var current = ptr
while let iface = current {
let next = iface.pointee.ifa_next
current = next
guard let sa = iface.pointee.ifa_addr else { continue }
guard sa.pointee.sa_family == sa_family_t(AF_INET) else { continue }
if Int32(iface.pointee.ifa_flags) & IFF_LOOPBACK == 0 {
let inaddr = sa.assumingMemoryBound(to: sockaddr_in.self).pointee
var host = [CChar](repeating: 0, count: Int(INET_ADDRSTRLEN))
if inet_ntop(AF_INET, &inaddr.sin_addr, &host, socklen_t(INET_ADDRSTRLEN)) != nil {
let ip = String(cString: host)
if ip.hasPrefix("169.254") {
continue // link-local; prefer a routable address
}
fallback = ip
let name = String(cString: iface.pointee.ifa_name)
if name.hasPrefix("en") || name.hasPrefix("wlan") {
return ip // Wi-Fi / Ethernet: good enough for the hint
}
}
}
}
return fallback
}
}