diff options
author | Jeroen Leenarts <jeroen.leenarts@gmail.com> | 2018-08-16 21:26:24 +0200 |
---|---|---|
committer | Jeroen Leenarts <jeroen.leenarts@gmail.com> | 2018-08-16 21:26:24 +0200 |
commit | d341c8e8e8e50b70dcc1496f907fc626aafa6c3c (patch) | |
tree | cefcd619e36f65acdf7565faf464bf0f850ac5c8 /Shared | |
parent | Added validation before saving any tunnels (diff) | |
download | wireguard-apple-d341c8e8e8e50b70dcc1496f907fc626aafa6c3c.tar.xz wireguard-apple-d341c8e8e8e50b70dcc1496f907fc626aafa6c3c.zip |
Calculate and apply CIDR.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'Shared')
-rw-r--r-- | Shared/Validators.swift | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/Shared/Validators.swift b/Shared/Validators.swift index aef1019..f065f0e 100644 --- a/Shared/Validators.swift +++ b/Shared/Validators.swift @@ -117,4 +117,18 @@ struct CIDRAddress { self.subnet = subnet } + + var subnetString: String { + // We could calculate these. + + var bitMask: UInt32 = 0b11111111111111111111111111111111 + bitMask = bitMask << (32 - subnet) + + let first = UInt8(truncatingIfNeeded: bitMask >> 24) + let second = UInt8(truncatingIfNeeded: bitMask >> 16 ) + let third = UInt8(truncatingIfNeeded: bitMask >> 8) + let fourth = UInt8(truncatingIfNeeded: bitMask) + + return "\(first).\(second).\(third).\(fourth)" + } } |