Handle IPv4/IPv6 variants in SocketType
This commit is contained in:
parent
c7595ed295
commit
6f235e9ea2
@ -33,4 +33,16 @@ public enum SocketType: String {
|
||||
|
||||
/// TCP socket type.
|
||||
case tcp = "TCP"
|
||||
|
||||
/// UDP socket type (IPv4).
|
||||
case udp4 = "UDP4"
|
||||
|
||||
/// TCP socket type (IPv4).
|
||||
case tcp4 = "TCP4"
|
||||
|
||||
/// UDP socket type (IPv6).
|
||||
case udp6 = "UDP6"
|
||||
|
||||
/// TCP socket type (IPv6).
|
||||
case tcp6 = "TCP6"
|
||||
}
|
||||
|
@ -156,11 +156,11 @@ private extension NEProvider {
|
||||
func createSocket(to address: String, protocol endpointProtocol: EndpointProtocol) -> GenericSocket {
|
||||
let endpoint = NWHostEndpoint(hostname: address, port: "\(endpointProtocol.port)")
|
||||
switch endpointProtocol.socketType {
|
||||
case .udp:
|
||||
case .udp, .udp4, .udp6:
|
||||
let impl = createUDPSession(to: endpoint, from: nil)
|
||||
return NEUDPSocket(impl: impl)
|
||||
|
||||
case .tcp:
|
||||
case .tcp, .tcp4, .tcp6:
|
||||
let impl = createTCPConnection(to: endpoint, enableTLS: false, tlsParameters: nil, delegate: nil)
|
||||
return NETCPSocket(impl: impl)
|
||||
}
|
||||
|
@ -62,11 +62,11 @@ extension OpenVPN {
|
||||
|
||||
// MARK: Client
|
||||
|
||||
static let proto = NSRegularExpression("^proto +(udp6?|tcp6?)")
|
||||
static let proto = NSRegularExpression("^proto +(udp[46]?|tcp[46]?)")
|
||||
|
||||
static let port = NSRegularExpression("^port +\\d+")
|
||||
|
||||
static let remote = NSRegularExpression("^remote +[^ ]+( +\\d+)?( +(udp6?|tcp6?))?")
|
||||
static let remote = NSRegularExpression("^remote +[^ ]+( +\\d+)?( +(udp[46]?|tcp[46]?))?")
|
||||
|
||||
static let eku = NSRegularExpression("^remote-cert-tls +server")
|
||||
|
||||
@ -817,10 +817,6 @@ private extension String {
|
||||
|
||||
private extension SocketType {
|
||||
init?(protoString: String) {
|
||||
var str = protoString
|
||||
if str.hasSuffix("6") {
|
||||
str.removeLast()
|
||||
}
|
||||
self.init(rawValue: str.uppercased())
|
||||
self.init(rawValue: protoString.uppercased())
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user