Do not try to resolve a valid ip address.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
Jeroen Leenarts 2018-10-03 10:39:04 +02:00
parent c10532acd9
commit ce02b7a4c0
1 changed files with 8 additions and 3 deletions

View File

@ -49,11 +49,16 @@ struct Endpoint {
}
hostString = hostString.replacingOccurrences(of: "[", with: "").replacingOccurrences(of: "]", with: "")
let ipString = convertToipAddress(from: hostString)
var addressType = validateIpAddress(ipToValidate: hostString)
let ipString: String
if addressType == .other {
ipString = convertToipAddress(from: hostString)
} else {
ipString = hostString
}
ipAddress = String(ipString)
let addressType = validateIpAddress(ipToValidate: ipAddress)
addressType = validateIpAddress(ipToValidate: ipAddress)
guard addressType == .IPv4 || addressType == .IPv6 else {
throw EndpointValidationError.invalidIP(ipAddress)
}