diff --git a/Sources/LCLPing/HTTP/HTTPPingClient.swift b/Sources/LCLPing/HTTP/HTTPPingClient.swift index b71981f..409da9e 100644 --- a/Sources/LCLPing/HTTP/HTTPPingClient.swift +++ b/Sources/LCLPing/HTTP/HTTPPingClient.swift @@ -259,6 +259,9 @@ extension HTTPPingClient { continue } } + if self.device != nil { + break + } } } diff --git a/Sources/LCLPing/HTTP/NIOHTTPClient.swift b/Sources/LCLPing/HTTP/NIOHTTPClient.swift index 1f25629..f350ba8 100644 --- a/Sources/LCLPing/HTTP/NIOHTTPClient.swift +++ b/Sources/LCLPing/HTTP/NIOHTTPClient.swift @@ -200,27 +200,23 @@ final class NIOHTTPClient: Pingable { } if let device = self.configuration.device { + #if canImport(Darwin) switch device.address { case .v4: - #if canImport(Darwin) return channel.setOption(.ipOption(.ip_bound_if), value: CInt(device.interfaceIndex)) - #elseif canImport(Glibc) - return channel.setOption(.ipOption(.so_bindtodevice), value: device.interfaceIndex) - #endif case .v6: - #if canImport(Darwin) - return channel.setOption(.ipv6Option(.ip_bound_if), value: CInt(device.interfaceIndex)) - #elseif canImport(Glibc) - return channel.setOption(.ipv6Option(.so_bindtodevice), value: device.interfaceIndex) - #endif + return channel.setOption(.ipv6Option(.ipv6_bound_if), value: CInt(device.interfaceIndex)) case .unixDomainSocket: self.stateLock.withLock { self.state = .error } - return channel.eventLoop.makeFailedFuture(PingError.httpBindToUnixDomainSocket) + return channel.eventLoop.makeFailedFuture(PingError.icmpBindToUnixDomainSocket) default: () } + #elseif canImport(Glibc) + return channel.setOption(.socketOption(.so_bindtodevice), value: device.interfaceIndex) + #endif } return channel.eventLoop.makeSucceededVoidFuture() diff --git a/Sources/LCLPing/ICMP/ICMPPingClient.swift b/Sources/LCLPing/ICMP/ICMPPingClient.swift index 79b1db4..0cdef56 100644 --- a/Sources/LCLPing/ICMP/ICMPPingClient.swift +++ b/Sources/LCLPing/ICMP/ICMPPingClient.swift @@ -176,19 +176,12 @@ public final class ICMPPingClient: Pingable { } if let device = self.configuration.device { + #if canImport(Darwin) switch device.address { case .v4: - #if canImport(Darwin) return channel.setOption(.ipOption(.ip_bound_if), value: CInt(device.interfaceIndex)) - #elseif canImport(Glibc) - return channel.setOption(.ipOption(.so_bindtodevice), value: device.interfaceIndex) - #endif case .v6: - #if canImport(Darwin) - return channel.setOption(.ipv6Option(.ip_bound_if), value: CInt(device.interfaceIndex)) - #elseif canImport(Glibc) - return channel.setOption(.ipv6Option(.so_bindtodevice), value: device.interfaceIndex) - #endif + return channel.setOption(.ipv6Option(.ipv6_bound_if), value: CInt(device.interfaceIndex)) case .unixDomainSocket: self.stateLock.withLock { self.state = .error @@ -197,6 +190,9 @@ public final class ICMPPingClient: Pingable { default: () } + #elseif canImport(Glibc) + return channel.setOption(.socketOption(.so_bindtodevice), value: device.interfaceIndex) + #endif } return channel.eventLoop.makeSucceededVoidFuture() @@ -270,6 +266,9 @@ extension ICMPPingClient { continue } } + if self.device != nil { + break + } } } } diff --git a/Sources/LCLPing/Utilities/LCLPing+SocketOption.swift b/Sources/LCLPing/Utilities/LCLPing+SocketOption.swift index 0b47ef9..17d2083 100644 --- a/Sources/LCLPing/Utilities/LCLPing+SocketOption.swift +++ b/Sources/LCLPing/Utilities/LCLPing+SocketOption.swift @@ -16,6 +16,7 @@ import NIOCore extension NIOBSDSocket.Option { #if canImport(Darwin) public static let ip_bound_if: NIOBSDSocket.Option = Self(rawValue: IP_BOUND_IF) + public static let ipv6_bound_if: NIOBSDSocket.Option = Self(rawValue: IPV6_BOUND_IF) #elseif canImport(Glibc) public static let so_bindtodevice = Self(rawValue: SO_BINDTODEVICE) #endif