Calculate and apply CIDR.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
Jeroen Leenarts
2018-08-16 21:26:24 +02:00
parent b306149222
commit d341c8e8e8
3 changed files with 108 additions and 22 deletions
+14
View File
@@ -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)"
}
}