Skip to content

Commit b31fd05

Browse files
committed
Update globalMaskVLSM when a VLSM requirement entry is deleted
doVLSM checks if new mask bits is too small for VLSM hosts requirements
1 parent f87a09d commit b31fd05

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

Base.lproj/MainMenu.xib

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@
222222
<window title="SubnetCalc" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" animationBehavior="default" id="371">
223223
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/>
224224
<rect key="contentRect" x="0.0" y="0.0" width="670" height="694"/>
225-
<rect key="screenRect" x="0.0" y="0.0" width="1440" height="875"/>
225+
<rect key="screenRect" x="0.0" y="0.0" width="1440" height="900"/>
226226
<value key="minSize" type="size" width="670" height="694"/>
227227
<view key="contentView" id="372">
228228
<rect key="frame" x="0.0" y="0.0" width="670" height="694"/>

SubnetCalcAppDelegate.swift

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class SubnetCalcAppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate,
8585
private var savedTabView: [NSTabViewItem]? //ex tab_tabView
8686
private var ipsc: IPSubnetCalc?
8787
private var subnetsVLSM = [(Int, String, String)]()
88-
private var globalMaskVLSM: UInt32 = IPSubnetCalc.Constants.addr32Empty
88+
private var globalMaskVLSM: UInt32!
8989

9090

9191
//Private IPv4 functions
@@ -269,10 +269,30 @@ class SubnetCalcAppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate,
269269
private func doVLSM()
270270
{
271271
if (ipsc != nil) {
272+
//print("doVLSM")
272273
maskBitsVLSMCombo.selectItem(withObjectValue: String(ipsc!.maskBits))
273-
//globalMaskVLSM = ~IPSubnetCalc.numerize(maskbits: ipsc!.maskBits) + 1
274-
subnetsVLSM.removeAll()
275-
viewVLSM.reloadData()
274+
var maskVLSM = ~IPSubnetCalc.numerize(maskbits: ipsc!.maskBits) + 1
275+
if (subnetsVLSM.count != 0) {
276+
var fitsRequirements = true
277+
for index in (0...(subnetsVLSM.count - 1)) {
278+
let maskbits = subnetsVLSM[index].0
279+
//print("Mask VLSM: \(IPSubnetCalc.digitize(ipAddress: maskVLSM)) Maskbits: \(IPSubnetCalc.digitize(ipAddress: ~IPSubnetCalc.numerize(maskbits: maskbits)))")
280+
if (maskVLSM > ~IPSubnetCalc.numerize(maskbits: maskbits)) {
281+
maskVLSM = maskVLSM - (~IPSubnetCalc.numerize(maskbits: maskbits) + 1)
282+
//print("Mask AFTER VLSM: \(IPSubnetCalc.digitize(ipAddress: maskVLSM))")
283+
}
284+
else {
285+
fitsRequirements = false
286+
}
287+
}
288+
if (fitsRequirements) {
289+
globalMaskVLSM = maskVLSM
290+
}
291+
else {
292+
myAlert(message: "Mask bits too small", info: "Mask bits doest not suit all VLSM hosts requirements")
293+
}
294+
viewVLSM.reloadData()
295+
}
276296
}
277297
}
278298

@@ -982,7 +1002,7 @@ class SubnetCalcAppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate,
9821002
if (viewVLSM.selectedRow != -1) {
9831003
//print ("Row : \(viewVLSM.selectedRow)")
9841004
subnetsVLSM.remove(at: viewVLSM.selectedRow)
985-
viewVLSM.reloadData()
1005+
doVLSM()
9861006
}
9871007
}
9881008
}

0 commit comments

Comments
 (0)