Fix IPv4/6 address validation (#308)

This commit is contained in:
Davide De Rosa 2023-05-27 21:34:31 +02:00 committed by GitHub
parent d05cf7140c
commit 36cad41529
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 4 deletions

View File

@ -61,10 +61,9 @@ struct Validators {
var sin = sockaddr_in() var sin = sockaddr_in()
var sin6 = sockaddr_in6() var sin6 = sockaddr_in6()
guard string.withCString({ cstring in inet_pton(AF_INET6, cstring, &sin6.sin6_addr) }) == 1 else { guard string.withCString({ cstring in inet_pton(AF_INET6, cstring, &sin6.sin6_addr) }) == 1 ||
throw ValidationError.ipAddress string.withCString({ cstring in inet_pton(AF_INET, cstring, &sin.sin_addr) }) == 1 else {
}
if string.withCString({ cstring in inet_pton(AF_INET, cstring, &sin.sin_addr) }) == 1 {
throw ValidationError.ipAddress throw ValidationError.ipAddress
} }
} }