-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow ICMP and HTTP Ping Client to bind to a specific device (#12)
- Loading branch information
Showing
7 changed files
with
175 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// | ||
// This source file is part of the LCL open source project | ||
// | ||
// Copyright (c) 2021-2024 Local Connectivity Lab and the project authors | ||
// Licensed under Apache License v2.0 | ||
// | ||
// See LICENSE for license information | ||
// See CONTRIBUTORS for the list of project authors | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
import Foundation | ||
import NIOCore | ||
|
||
extension ChannelOption where Self == ChannelOptions.Types.SocketOption { | ||
public static func ipv6Option(_ name: NIOBSDSocket.Option) -> Self { | ||
.init(level: .ipv6, name: name) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// | ||
// This source file is part of the LCL open source project | ||
// | ||
// Copyright (c) 2021-2024 Local Connectivity Lab and the project authors | ||
// Licensed under Apache License v2.0 | ||
// | ||
// See LICENSE for license information | ||
// See CONTRIBUTORS for the list of project authors | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
import Foundation | ||
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 | ||
} | ||
|
||
extension SocketOptionProvider { | ||
#if canImport(Glibc) | ||
/// Sets the socket option SO_BINDTODEVICE to `value`. | ||
/// | ||
/// - parameters: | ||
/// - value: The value to set SO_BINDTODEVICE to. | ||
/// - returns: An `EventLoopFuture` that fires when the option has been set, | ||
/// or if an error has occurred. | ||
public func setBindToDevice(_ value: String) -> EventLoopFuture<Void> { | ||
self.unsafeSetSocketOption(level: .socket, name: .so_bindtodevice, value: value) | ||
} | ||
#endif | ||
} |