Skip to content

Commit bd9712e

Browse files
committed
Fix Subnet/Hosts listing which did not begin at first subnet
Add classMask func which returns the Mask of the Class type in UInt32 format
1 parent 0cd9f0d commit bd9712e

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

IPSubnetcalc.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,27 @@ class IPSubnetCalc: NSObject {
394394
return (32)
395395
}
396396

397+
func classMask() -> UInt32 {
398+
let classType = self.netClass()
399+
400+
if (classType == "A") {
401+
return (Constants.maskClassA)
402+
}
403+
else if (classType == "B") {
404+
return (Constants.maskClassB)
405+
}
406+
else if (classType == "C") {
407+
return (Constants.maskClassC)
408+
}
409+
else if (classType == "D") {
410+
return (Constants.maskClassD)
411+
}
412+
else if (classType == "E") {
413+
return (Constants.maskClassE)
414+
}
415+
return (Constants.maskClassE)
416+
}
417+
397418
static func maskBits(maskAddr: String) -> Int {
398419
var bits: Int = 0
399420

SubnetCalcAppDelegate.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,7 @@ class SubnetCalcAppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate,
731731
row: Int) -> Any?
732732
{
733733
if (ipsc != nil) {
734-
let ipaddr: UInt32 = (((IPSubnetCalc.numerize(ipAddress: ipsc!.subnetId())) >> (32 - ipsc!.maskBits)) + UInt32(row)) << (32 - ipsc!.maskBits)
734+
let ipaddr: UInt32 = (((IPSubnetCalc.numerize(ipAddress: ipsc!.ipv4Address) & ipsc!.classMask()) >> (32 - ipsc!.maskBits)) + UInt32(row)) << (32 - ipsc!.maskBits)
735735
let ipsc_tmp = IPSubnetCalc(ipAddress: IPSubnetCalc.digitize(ipAddress: ipaddr), maskbits: ipsc!.maskBits)
736736
//print("tableView Row: \(row) IP num : \(ipaddr) IP: \(IPSubnetCalc.digitize(ipAddress: ipaddr)) IP Subnet: \(ipsc_tmp!.subnetId())")
737737
if (tableColumn != nil && ipsc_tmp != nil) {

0 commit comments

Comments
 (0)