Skip to content

Commit

Permalink
Fix IPv4/6 address validation (#308)
Browse files Browse the repository at this point in the history
  • Loading branch information
keeshux authored May 27, 2023
1 parent d05cf71 commit 36cad41
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions Passepartout/App/Reusable/Validators.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,9 @@ struct Validators {
var sin = sockaddr_in()
var sin6 = sockaddr_in6()

guard string.withCString({ cstring in inet_pton(AF_INET6, cstring, &sin6.sin6_addr) }) == 1 else {
throw ValidationError.ipAddress
}
if string.withCString({ cstring in inet_pton(AF_INET, cstring, &sin.sin_addr) }) == 1 {
guard string.withCString({ cstring in inet_pton(AF_INET6, cstring, &sin6.sin6_addr) }) == 1 ||
string.withCString({ cstring in inet_pton(AF_INET, cstring, &sin.sin_addr) }) == 1 else {

throw ValidationError.ipAddress
}
}
Expand Down

0 comments on commit 36cad41

Please sign in to comment.