From fa8575fa273bd3e1bdf7797c066cbb0d2cc8eb08 Mon Sep 17 00:00:00 2001 From: Julien Mulot Date: Fri, 19 Feb 2021 15:14:42 +0100 Subject: [PATCH 01/17] Update to 2.1 version and build 5 Update Copyright to 2021 --- SubnetCalc-Info.plist | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/SubnetCalc-Info.plist b/SubnetCalc-Info.plist index 27f8f5a..ccb87d0 100644 --- a/SubnetCalc-Info.plist +++ b/SubnetCalc-Info.plist @@ -15,17 +15,17 @@ CFBundlePackageType APPL CFBundleShortVersionString - 2.0 + 2.1 CFBundleSignature JMUL CFBundleVersion - 4 + 5 LSApplicationCategoryType public.app-category.utilities LSMinimumSystemVersion ${MACOSX_DEPLOYMENT_TARGET} NSHumanReadableCopyright - Copyright 2020 Julien Mulot + Copyright 2021 Julien Mulot NSMainNibFile MainMenu NSPrincipalClass From f04925e89cd823331ded123b5853464c93cbf91a Mon Sep 17 00:00:00 2001 From: Julien Mulot Date: Thu, 8 Jul 2021 16:57:07 +0200 Subject: [PATCH 02/17] Add FLSM and VLSM UI Tab FSLM computation is working --- Base.lproj/MainMenu.xib | 428 +++++++++++++++++++++++---- SubnetCalc.xcodeproj/project.pbxproj | 6 +- SubnetCalcAppDelegate.swift | 124 ++++++-- 3 files changed, 482 insertions(+), 76 deletions(-) diff --git a/Base.lproj/MainMenu.xib b/Base.lproj/MainMenu.xib index 15abda1..1c089a4 100644 --- a/Base.lproj/MainMenu.xib +++ b/Base.lproj/MainMenu.xib @@ -1,8 +1,8 @@ - + - + @@ -150,6 +150,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -157,7 +214,7 @@ - + @@ -470,9 +527,9 @@ - + - + @@ -752,6 +809,318 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1065,54 +1434,5 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/SubnetCalc.xcodeproj/project.pbxproj b/SubnetCalc.xcodeproj/project.pbxproj index 19c1567..5cbce32 100644 --- a/SubnetCalc.xcodeproj/project.pbxproj +++ b/SubnetCalc.xcodeproj/project.pbxproj @@ -36,7 +36,7 @@ 8D1107310486CEB800E47090 /* SubnetCalc-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "SubnetCalc-Info.plist"; sourceTree = ""; }; 8D1107320486CEB800E47090 /* SubnetCalc.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SubnetCalc.app; sourceTree = BUILT_PRODUCTS_DIR; }; 945E62EF25658A9500CDC9C7 /* SubnetCalc.xctestplan */ = {isa = PBXFileReference; lastKnownFileType = text; path = SubnetCalc.xctestplan; sourceTree = ""; }; - 945E62F525658DBF00CDC9C7 /* SubnetCalcUITests-Runner.app */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "SubnetCalcUITests-Runner.app"; sourceTree = BUILT_PRODUCTS_DIR; }; + 945E62F525658DBF00CDC9C7 /* SubnetCalcUITests-Runner.app */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; name = "SubnetCalcUITests-Runner.app"; path = SubnetCalcUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 945E62F925658DBF00CDC9C7 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 9482A32625765B30008D2C56 /* SubnetCalcUITest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SubnetCalcUITest.swift; sourceTree = ""; }; 949420B712D3C62A00E2F57D /* License.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = License.txt; sourceTree = ""; }; @@ -410,7 +410,7 @@ INFOPLIST_FILE = "SubnetCalc-Info.plist"; INSTALL_PATH = "$(HOME)/Applications"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = net.mulot.subnetcalc; + PRODUCT_BUNDLE_IDENTIFIER = org.mulot.subnetcalc; PRODUCT_NAME = SubnetCalc; PROVISIONING_PROFILE_SPECIFIER = ""; SWIFT_OBJC_BRIDGING_HEADER = ""; @@ -436,7 +436,7 @@ INFOPLIST_FILE = "SubnetCalc-Info.plist"; INSTALL_PATH = /Applications; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = net.mulot.subnetcalc; + PRODUCT_BUNDLE_IDENTIFIER = org.mulot.subnetcalc; PRODUCT_NAME = SubnetCalc; PROVISIONING_PROFILE_SPECIFIER = ""; SWIFT_OBJC_BRIDGING_HEADER = ""; diff --git a/SubnetCalcAppDelegate.swift b/SubnetCalcAppDelegate.swift index b17de97..374541b 100644 --- a/SubnetCalcAppDelegate.swift +++ b/SubnetCalcAppDelegate.swift @@ -54,6 +54,14 @@ class SubnetCalcAppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate, @IBOutlet var tabViewClassLess: NSButton! @IBOutlet var wildcard: NSButton! @IBOutlet var dotted: NSButton! + @IBOutlet var maskBitsFLSMCombo: NSComboBox! + @IBOutlet var maskBitsVLSMCombo: NSComboBox! + @IBOutlet var viewFLSM: NSTableView! + @IBOutlet var slideFLSM: NSSlider! + @IBOutlet var maxSubnetsFLSM: NSTextField! + @IBOutlet var maxHostsBySubnetFLSM: NSTextField! + @IBOutlet var maxHostsFLSM: NSTextField! + @IBOutlet var viewVLSM: NSTableView! //IPv6 UI elements @IBOutlet var ipv6Address: NSTextField! @@ -122,6 +130,12 @@ class SubnetCalcAppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate, classHexaMap.stringValue = "01.00.00.00" } + private func initFLSMTab() { + for bits in (8...32) { + maskBitsFLSMCombo.addItem(withObjectValue: String(bits)) + } + } + private func bitsOnSlidePos() { var coordLabel = bitsOnSlide.frame @@ -197,6 +211,7 @@ class SubnetCalcAppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate, if (ipsc != nil) { subnetBitsCombo.selectItem(withObjectValue: String(ipsc!.subnetBits())) maskBitsCombo.selectItem(withObjectValue: String(ipsc!.maskBits)) + maskBitsFLSMCombo.selectItem(withObjectValue: String(ipsc!.maskBits)) maxSubnetsCombo.selectItem(withObjectValue: String(ipsc!.maxSubnets())) maxHostsBySubnetCombo.selectItem(withObjectValue: String(ipsc!.maxHosts())) subnetId.stringValue = ipsc!.subnetId() @@ -221,6 +236,29 @@ class SubnetCalcAppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate, } } + private func doFLSM() + { + if (ipsc != nil) { + //bitsOnSlide.stringValue = String(ipsc!.maskBits) + //subnetBitsSlide.intValue = Int32(ipsc!.maskBits) + //self.bitsOnSlidePos() + self.maxSubnetsFLSM.stringValue = NSDecimalNumber(decimal: (pow(2, slideFLSM.integerValue))).stringValue + self.maxHostsBySubnetFLSM.stringValue = NSDecimalNumber(decimal: (pow(2, (32 - (ipsc!.maskBits + slideFLSM.integerValue)))) - 2).stringValue + self.maxHostsFLSM.stringValue = NSDecimalNumber(decimal: ((pow(2, (32 - (ipsc!.maskBits + slideFLSM.integerValue)))) - 2) * (pow(2, slideFLSM.integerValue))).stringValue + viewFLSM.reloadData() + } + } + + private func doVLSM() + { + if (ipsc != nil) { + //bitsOnSlide.stringValue = String(ipsc!.maskBits) + //subnetBitsSlide.intValue = Int32(ipsc!.maskBits) + //self.bitsOnSlidePos() + viewVLSM.reloadData() + } + } + private func doCIDR(maskbits: Int? = nil) { if (ipsc != nil) { @@ -716,12 +754,17 @@ class SubnetCalcAppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate, func numberOfRows(in tableView: NSTableView) -> Int { if (ipsc != nil) { - if (tabViewClassLess.state == NSControl.StateValue.on) { - //print("numberOfRows: Maskbits : \(ipsc!.maskBits) Bits compute: \(ipsc!.maskBits - Constants.NETWORK_BITS_MIN_CLASSLESS) Power: \(NSDecimalNumber(decimal: pow(2, (ipsc!.maskBits - Constants.NETWORK_BITS_MIN_CLASSLESS))))") - return Int(truncating: NSDecimalNumber(decimal: pow(2, (ipsc!.maskBits - Constants.NETWORK_BITS_MIN_CLASSLESS)))) + if (tableView == subnetsHostsView) { + if (tabViewClassLess.state == NSControl.StateValue.on) { + //print("numberOfRows: Maskbits : \(ipsc!.maskBits) Bits compute: \(ipsc!.maskBits - Constants.NETWORK_BITS_MIN_CLASSLESS) Power: \(NSDecimalNumber(decimal: pow(2, (ipsc!.maskBits - Constants.NETWORK_BITS_MIN_CLASSLESS))))") + return Int(truncating: NSDecimalNumber(decimal: pow(2, (ipsc!.maskBits - Constants.NETWORK_BITS_MIN_CLASSLESS)))) + } + else { + return (ipsc!.maxSubnets()) + } } - else { - return (ipsc!.maxSubnets()) + else if (tableView == viewFLSM) { + return Int(truncating: NSDecimalNumber(decimal: pow(2, slideFLSM.integerValue))) } } return 0 @@ -732,21 +775,47 @@ class SubnetCalcAppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate, row: Int) -> Any? { if (ipsc != nil) { - let ipaddr: UInt32 = (((IPSubnetCalc.numerize(ipAddress: ipsc!.ipv4Address) & ipsc!.classMask()) >> (32 - ipsc!.maskBits)) + UInt32(row)) << (32 - ipsc!.maskBits) - let ipsc_tmp = IPSubnetCalc(ipAddress: IPSubnetCalc.digitize(ipAddress: ipaddr), maskbits: ipsc!.maskBits) - //print("tableView Row: \(row) IP num : \(ipaddr) IP: \(IPSubnetCalc.digitize(ipAddress: ipaddr)) IP Subnet: \(ipsc_tmp!.subnetId())") - if (tableColumn != nil && ipsc_tmp != nil) { - if (tableColumn!.identifier.rawValue == "numCol") { - return (row + 1) - } - else if (tableColumn!.identifier.rawValue == "subnetCol") { - return (ipsc_tmp!.subnetId()) - } - else if (tableColumn!.identifier.rawValue == "rangeCol") { - return (ipsc_tmp!.subnetRange()) + //print("Refresh TableView: \(String(describing: tableView.identifier))") + if (tableView == subnetsHostsView) { + let ipaddr: UInt32 = (((IPSubnetCalc.numerize(ipAddress: ipsc!.ipv4Address) & ipsc!.classMask()) >> (32 - ipsc!.maskBits)) + UInt32(row)) << (32 - ipsc!.maskBits) + let ipsc_tmp = IPSubnetCalc(ipAddress: IPSubnetCalc.digitize(ipAddress: ipaddr), maskbits: ipsc!.maskBits) + //print("tableView Row: \(row) IP num : \(ipaddr) IP: \(IPSubnetCalc.digitize(ipAddress: ipaddr)) IP Subnet: \(ipsc_tmp!.subnetId())") + if (tableColumn != nil && ipsc_tmp != nil) { + if (tableColumn!.identifier.rawValue == "numCol") { + return (row + 1) + } + else if (tableColumn!.identifier.rawValue == "subnetCol") { + return (ipsc_tmp!.subnetId()) + } + else if (tableColumn!.identifier.rawValue == "rangeCol") { + return (ipsc_tmp!.subnetRange()) + } + else if (tableColumn!.identifier.rawValue == "broadcastCol") { + return (ipsc_tmp!.subnetBroadcast()) + } } - else if (tableColumn!.identifier.rawValue == "broadcastCol") { - return (ipsc_tmp!.subnetBroadcast()) + } + else if (tableView == viewFLSM) { + //print("refresh View FLSM") + var ipaddr: UInt32 = ((IPSubnetCalc.numerize(ipAddress: ipsc!.ipv4Address) & ipsc!.classMask()) >> (32 - ipsc!.maskBits)) << (32 - ipsc!.maskBits) + ipaddr = (ipaddr >> (32 - (ipsc!.maskBits + slideFLSM.integerValue)) + UInt32(row)) << (32 - (ipsc!.maskBits + slideFLSM.integerValue)) + let ipsc_tmp = IPSubnetCalc(ipAddress: IPSubnetCalc.digitize(ipAddress: ipaddr), maskbits: (ipsc!.maskBits + slideFLSM.integerValue)) + if (tableColumn != nil && ipsc_tmp != nil) { + if (tableColumn!.identifier.rawValue == "numFLSMCol") { + return (row + 1) + } + else if (tableColumn!.identifier.rawValue == "subnetFLSMCol") { + return (ipsc_tmp!.subnetId()) + } + else if (tableColumn!.identifier.rawValue == "maskFLSMCol") { + return ("/\(ipsc!.maskBits + slideFLSM.integerValue)") + } + else if (tableColumn!.identifier.rawValue == "rangeFLSMCol") { + return (ipsc_tmp!.subnetRange()) + } + else if (tableColumn!.identifier.rawValue == "broadcastFLSMCol") { + return (ipsc_tmp!.subnetBroadcast()) + } } } } @@ -778,6 +847,22 @@ class SubnetCalcAppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate, } } + @IBAction func changeSlideFLSM(_ sender: AnyObject) + { + if (ipsc == nil) + { + ipsc = IPSubnetCalc(Constants.defaultIP) + } + if ((ipsc!.maskBits + (sender.intValue as Int)) <= 29) + { + print("FLSM Bits: \(sender.intValue as Int)") + self.doFLSM() + } + else { + + } + } + @IBAction func changeTableViewClass(_ sender: AnyObject) { if (tabViewClassLess.state == NSControl.StateValue.off) { @@ -962,6 +1047,7 @@ class SubnetCalcAppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate, initSubnetsTab() initCIDRTab() initIPv6Tab() + initFLSMTab() } func applicationWillTerminate(_ aNotification: Notification) { From e8d002f5f4a8f1d2c9b2cdaf4beb35d81588f698 Mon Sep 17 00:00:00 2001 From: Julien Mulot Date: Thu, 8 Jul 2021 18:58:24 +0200 Subject: [PATCH 03/17] Adapt FLSM slide to number of value possible --- SubnetCalcAppDelegate.swift | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/SubnetCalcAppDelegate.swift b/SubnetCalcAppDelegate.swift index 374541b..726d646 100644 --- a/SubnetCalcAppDelegate.swift +++ b/SubnetCalcAppDelegate.swift @@ -55,12 +55,12 @@ class SubnetCalcAppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate, @IBOutlet var wildcard: NSButton! @IBOutlet var dotted: NSButton! @IBOutlet var maskBitsFLSMCombo: NSComboBox! - @IBOutlet var maskBitsVLSMCombo: NSComboBox! @IBOutlet var viewFLSM: NSTableView! @IBOutlet var slideFLSM: NSSlider! @IBOutlet var maxSubnetsFLSM: NSTextField! @IBOutlet var maxHostsBySubnetFLSM: NSTextField! @IBOutlet var maxHostsFLSM: NSTextField! + @IBOutlet var maskBitsVLSMCombo: NSComboBox! @IBOutlet var viewVLSM: NSTableView! //IPv6 UI elements @@ -134,6 +134,7 @@ class SubnetCalcAppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate, for bits in (8...32) { maskBitsFLSMCombo.addItem(withObjectValue: String(bits)) } + slideFLSM.integerValue = 1 } private func bitsOnSlidePos() @@ -211,7 +212,6 @@ class SubnetCalcAppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate, if (ipsc != nil) { subnetBitsCombo.selectItem(withObjectValue: String(ipsc!.subnetBits())) maskBitsCombo.selectItem(withObjectValue: String(ipsc!.maskBits)) - maskBitsFLSMCombo.selectItem(withObjectValue: String(ipsc!.maskBits)) maxSubnetsCombo.selectItem(withObjectValue: String(ipsc!.maxSubnets())) maxHostsBySubnetCombo.selectItem(withObjectValue: String(ipsc!.maxHosts())) subnetId.stringValue = ipsc!.subnetId() @@ -242,9 +242,19 @@ class SubnetCalcAppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate, //bitsOnSlide.stringValue = String(ipsc!.maskBits) //subnetBitsSlide.intValue = Int32(ipsc!.maskBits) //self.bitsOnSlidePos() - self.maxSubnetsFLSM.stringValue = NSDecimalNumber(decimal: (pow(2, slideFLSM.integerValue))).stringValue - self.maxHostsBySubnetFLSM.stringValue = NSDecimalNumber(decimal: (pow(2, (32 - (ipsc!.maskBits + slideFLSM.integerValue)))) - 2).stringValue - self.maxHostsFLSM.stringValue = NSDecimalNumber(decimal: ((pow(2, (32 - (ipsc!.maskBits + slideFLSM.integerValue)))) - 2) * (pow(2, slideFLSM.integerValue))).stringValue + maskBitsFLSMCombo.selectItem(withObjectValue: String(ipsc!.maskBits)) + if (ipsc!.maskBits <= 29) { + slideFLSM.numberOfTickMarks = (30 - ipsc!.maskBits) + slideFLSM.maxValue = Double(30 - ipsc!.maskBits) + self.maxSubnetsFLSM.stringValue = NSDecimalNumber(decimal: (pow(2, slideFLSM.integerValue))).stringValue + self.maxHostsBySubnetFLSM.stringValue = NSDecimalNumber(decimal: (pow(2, (32 - (ipsc!.maskBits + slideFLSM.integerValue)))) - 2).stringValue + self.maxHostsFLSM.stringValue = NSDecimalNumber(decimal: ((pow(2, (32 - (ipsc!.maskBits + slideFLSM.integerValue)))) - 2) * (pow(2, slideFLSM.integerValue))).stringValue + } + else { + self.maxSubnetsFLSM.stringValue = "" + self.maxHostsBySubnetFLSM.stringValue = "" + self.maxHostsFLSM.stringValue = "" + } viewFLSM.reloadData() } } @@ -353,6 +363,7 @@ class SubnetCalcAppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate, self.doSubnetHost() self.doCIDR() self.doIPv6() + self.doFLSM() } } else { @@ -452,6 +463,7 @@ class SubnetCalcAppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate, self.doSubnet() self.doSubnetHost() self.doCIDR() + self.doFLSM() self.doIPv6() } } @@ -764,7 +776,9 @@ class SubnetCalcAppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate, } } else if (tableView == viewFLSM) { - return Int(truncating: NSDecimalNumber(decimal: pow(2, slideFLSM.integerValue))) + if (ipsc!.maskBits <= 29) { + return Int(truncating: NSDecimalNumber(decimal: pow(2, slideFLSM.integerValue))) + } } } return 0 @@ -853,9 +867,9 @@ class SubnetCalcAppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate, { ipsc = IPSubnetCalc(Constants.defaultIP) } - if ((ipsc!.maskBits + (sender.intValue as Int)) <= 29) + if ((ipsc!.maskBits + (sender.intValue as Int)) <= 30) { - print("FLSM Bits: \(sender.intValue as Int)") + //print("FLSM Bits: \(sender.intValue as Int)") self.doFLSM() } else { From f03735c6a2569335e314ba892e283a06221adb0f Mon Sep 17 00:00:00 2001 From: Julien Mulot Date: Thu, 8 Jul 2021 19:16:19 +0200 Subject: [PATCH 04/17] Fix UI Tests --- Base.lproj/MainMenu.xib | 10 +++++----- SubnetCalcAppDelegate.swift | 14 ++++++++++---- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/Base.lproj/MainMenu.xib b/Base.lproj/MainMenu.xib index 1c089a4..211edca 100644 --- a/Base.lproj/MainMenu.xib +++ b/Base.lproj/MainMenu.xib @@ -527,7 +527,7 @@ - + @@ -840,7 +840,7 @@ - + @@ -852,7 +852,7 @@ - + @@ -864,7 +864,7 @@ - + @@ -876,7 +876,7 @@ - + diff --git a/SubnetCalcAppDelegate.swift b/SubnetCalcAppDelegate.swift index 726d646..ce649c1 100644 --- a/SubnetCalcAppDelegate.swift +++ b/SubnetCalcAppDelegate.swift @@ -353,10 +353,12 @@ class SubnetCalcAppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate, ipsc = IPSubnetCalc(ipAddress: ipaddr, maskbits: Int(ipmask!)!) } if (ipsc != nil) { - if (tabView.numberOfTabViewItems != 4 && savedTabView != nil) { + if (tabView.numberOfTabViewItems != 6 && savedTabView != nil) { tabView.addTabViewItem(savedTabView![1]) tabView.addTabViewItem(savedTabView![2]) tabView.addTabViewItem(savedTabView![3]) + tabView.addTabViewItem(savedTabView![4]) + tabView.addTabViewItem(savedTabView![5]) } self.doAddressMap() self.doSubnet() @@ -454,10 +456,12 @@ class SubnetCalcAppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate, //print("IP Address: \(ipaddr) mask: \(ipmask)") ipsc = IPSubnetCalc(ipv6: ipaddr, maskbits: Int(ipmask!)!) if (ipsc != nil) { - if (tabView.numberOfTabViewItems != 4 && savedTabView != nil) { + if (tabView.numberOfTabViewItems != 6 && savedTabView != nil) { tabView.addTabViewItem(savedTabView![1]) tabView.addTabViewItem(savedTabView![2]) tabView.addTabViewItem(savedTabView![3]) + tabView.addTabViewItem(savedTabView![4]) + tabView.addTabViewItem(savedTabView![5]) } self.doAddressMap() self.doSubnet() @@ -477,10 +481,12 @@ class SubnetCalcAppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate, //IPv4 UI actions @IBAction func changeAddrClassType(_ sender: AnyObject) { - if (tabView.numberOfTabViewItems != 4 && savedTabView != nil) { + if (tabView.numberOfTabViewItems != 6 && savedTabView != nil) { tabView.addTabViewItem(savedTabView![1]) tabView.addTabViewItem(savedTabView![2]) tabView.addTabViewItem(savedTabView![3]) + tabView.addTabViewItem(savedTabView![4]) + tabView.addTabViewItem(savedTabView![5]) } if (sender.indexOfSelectedItem() == 0) { @@ -969,7 +975,7 @@ class SubnetCalcAppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate, { if (addrField.stringValue.contains(":")) { self.doIPv6SubnetCalc() - tabView.selectTabViewItem(at: 3) + tabView.selectTabViewItem(at: 5) } else { self.doIPSubnetCalc() From 16db78e69466631d39fd809207e1a83237acfdcf Mon Sep 17 00:00:00 2001 From: Julien Mulot Date: Fri, 9 Jul 2021 10:16:54 +0200 Subject: [PATCH 05/17] Create VLSM Tab UI Add fittingSubnet to determine which subnet mask fit the number of required hosts --- Base.lproj/MainMenu.xib | 67 +++++++++++++++++++++++++++++++++---- IPSubnetcalc.swift | 13 +++++++ SubnetCalcAppDelegate.swift | 33 ++++++++++++++---- 3 files changed, 100 insertions(+), 13 deletions(-) diff --git a/Base.lproj/MainMenu.xib b/Base.lproj/MainMenu.xib index 211edca..a9bd2c4 100644 --- a/Base.lproj/MainMenu.xib +++ b/Base.lproj/MainMenu.xib @@ -184,6 +184,7 @@ + @@ -191,6 +192,7 @@ + @@ -527,7 +529,7 @@ - + @@ -1039,7 +1041,7 @@ - + @@ -1051,8 +1053,8 @@ - - + + @@ -1063,8 +1065,8 @@ - - + + @@ -1118,6 +1120,59 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/IPSubnetcalc.swift b/IPSubnetcalc.swift index c0de9de..e0e7450 100644 --- a/IPSubnetcalc.swift +++ b/IPSubnetcalc.swift @@ -502,6 +502,19 @@ class IPSubnetCalc: NSObject { return (bitMap) } + // return maskbits and number of max hosts for this mask + static func fittingSubnet(hosts: UInt) -> (Int, UInt) { + var maxHosts: UInt + + for index in 1...31 { + maxHosts = UInt(truncating: NSDecimalNumber(decimal: pow(2, index))) - 2 + if (hosts <= maxHosts) { + return (32 - index, maxHosts) + } + } + return (0, 0) + } + func displayIPInfo() { print("IP Host : " + self.ipv4Address) print("Mask bits : \(self.maskBits)") diff --git a/SubnetCalcAppDelegate.swift b/SubnetCalcAppDelegate.swift index ce649c1..55b8d53 100644 --- a/SubnetCalcAppDelegate.swift +++ b/SubnetCalcAppDelegate.swift @@ -61,6 +61,8 @@ class SubnetCalcAppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate, @IBOutlet var maxHostsBySubnetFLSM: NSTextField! @IBOutlet var maxHostsFLSM: NSTextField! @IBOutlet var maskBitsVLSMCombo: NSComboBox! + @IBOutlet var requiredHostsVLSM: NSTextField! + @IBOutlet var subnetNameVLSM: NSTextField! @IBOutlet var viewVLSM: NSTableView! //IPv6 UI elements @@ -137,6 +139,12 @@ class SubnetCalcAppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate, slideFLSM.integerValue = 1 } + private func initVLSMTab() { + for bits in (8...32) { + maskBitsVLSMCombo.addItem(withObjectValue: String(bits)) + } + } + private func bitsOnSlidePos() { var coordLabel = bitsOnSlide.frame @@ -239,9 +247,6 @@ class SubnetCalcAppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate, private func doFLSM() { if (ipsc != nil) { - //bitsOnSlide.stringValue = String(ipsc!.maskBits) - //subnetBitsSlide.intValue = Int32(ipsc!.maskBits) - //self.bitsOnSlidePos() maskBitsFLSMCombo.selectItem(withObjectValue: String(ipsc!.maskBits)) if (ipsc!.maskBits <= 29) { slideFLSM.numberOfTickMarks = (30 - ipsc!.maskBits) @@ -262,9 +267,7 @@ class SubnetCalcAppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate, private func doVLSM() { if (ipsc != nil) { - //bitsOnSlide.stringValue = String(ipsc!.maskBits) - //subnetBitsSlide.intValue = Int32(ipsc!.maskBits) - //self.bitsOnSlidePos() + maskBitsVLSMCombo.selectItem(withObjectValue: String(ipsc!.maskBits)) viewVLSM.reloadData() } } @@ -366,6 +369,7 @@ class SubnetCalcAppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate, self.doCIDR() self.doIPv6() self.doFLSM() + self.doVLSM() } } else { @@ -468,6 +472,7 @@ class SubnetCalcAppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate, self.doSubnetHost() self.doCIDR() self.doFLSM() + self.doVLSM() self.doIPv6() } } @@ -878,8 +883,21 @@ class SubnetCalcAppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate, //print("FLSM Bits: \(sender.intValue as Int)") self.doFLSM() } + } + + @IBAction func addSubnetVLSM(_ sender: AnyObject) + { + if (ipsc == nil) + { + ipsc = IPSubnetCalc(Constants.defaultIP) + } + if (requiredHostsVLSM.integerValue != 0) { + print("VLSM Hosts required: \(requiredHostsVLSM.integerValue)") + print("VLSM fitting subnet: \(IPSubnetCalc.fittingSubnet(hosts: UInt(requiredHostsVLSM.integerValue)))") + self.doVLSM() + } else { - + myAlert(message: "Bad VLSM required Hosts number", info: "\(requiredHostsVLSM.integerValue) is not a number") } } @@ -1068,6 +1086,7 @@ class SubnetCalcAppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate, initCIDRTab() initIPv6Tab() initFLSMTab() + initVLSMTab() } func applicationWillTerminate(_ aNotification: Notification) { From 3724249616a7bdd535b945f0bf58f13d6c290eae Mon Sep 17 00:00:00 2001 From: Julien Mulot Date: Fri, 9 Jul 2021 12:23:17 +0200 Subject: [PATCH 06/17] Register VLSM required subnets Display required VLSM subnets in sorted order --- Base.lproj/MainMenu.xib | 8 +++--- SubnetCalcAppDelegate.swift | 52 +++++++++++++++++++++++++++++++++++-- 2 files changed, 54 insertions(+), 6 deletions(-) diff --git a/Base.lproj/MainMenu.xib b/Base.lproj/MainMenu.xib index a9bd2c4..a336919 100644 --- a/Base.lproj/MainMenu.xib +++ b/Base.lproj/MainMenu.xib @@ -1010,7 +1010,7 @@ - + @@ -1054,7 +1054,7 @@ - + @@ -1141,7 +1141,7 @@ - + @@ -1153,7 +1153,7 @@ - + diff --git a/SubnetCalcAppDelegate.swift b/SubnetCalcAppDelegate.swift index 55b8d53..1cc1f03 100644 --- a/SubnetCalcAppDelegate.swift +++ b/SubnetCalcAppDelegate.swift @@ -84,6 +84,7 @@ class SubnetCalcAppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate, //Private global vars private var savedTabView: [NSTabViewItem]? //ex tab_tabView private var ipsc: IPSubnetCalc? + private var subnetsVLSM = [(String, Int, String, String)]() //Private IPv4 functions @@ -791,6 +792,9 @@ class SubnetCalcAppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate, return Int(truncating: NSDecimalNumber(decimal: pow(2, slideFLSM.integerValue))) } } + else if (tableView == viewVLSM) { + return (subnetsVLSM.count) + } } return 0 } @@ -843,6 +847,26 @@ class SubnetCalcAppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate, } } } + else if (tableView == viewVLSM) { + print("refresh View VLSM") + if (tableColumn != nil) { + if (tableColumn!.identifier.rawValue == "numVLSMCol") { + return (row + 1) + } + else if (tableColumn!.identifier.rawValue == "subnetVLSMCol") { + return (subnetsVLSM[row].0) + } + else if (tableColumn!.identifier.rawValue == "maskVLSMCol") { + return (subnetsVLSM[row].1) + } + else if (tableColumn!.identifier.rawValue == "nameVLSMCol") { + return (subnetsVLSM[row].2) + } + else if (tableColumn!.identifier.rawValue == "usedVLSMCol") { + return (subnetsVLSM[row].3) + } + } + } } return (nil) } @@ -887,18 +911,42 @@ class SubnetCalcAppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate, @IBAction func addSubnetVLSM(_ sender: AnyObject) { + var maskbits: Int + var hosts: UInt + var used: Int + if (ipsc == nil) { ipsc = IPSubnetCalc(Constants.defaultIP) } if (requiredHostsVLSM.integerValue != 0) { print("VLSM Hosts required: \(requiredHostsVLSM.integerValue)") - print("VLSM fitting subnet: \(IPSubnetCalc.fittingSubnet(hosts: UInt(requiredHostsVLSM.integerValue)))") - self.doVLSM() + (maskbits, hosts) = IPSubnetCalc.fittingSubnet(hosts: UInt(requiredHostsVLSM.integerValue)) + if (maskbits != 0) { + used = (requiredHostsVLSM.integerValue * 100) / Int(hosts) + print("VLSM fitting subnet mask: \(maskbits) with \(hosts) max hosts") + if (subnetsVLSM.count != 0) { + print("VLSM subnets NOT empty") + if let index = subnetsVLSM.firstIndex(where: { $0.1 > maskbits }) { + subnetsVLSM.insert(("dsds", maskbits, subnetNameVLSM.stringValue, "\(requiredHostsVLSM.stringValue)/\(hosts) (\(used)%)"), at: index) + } + else { + subnetsVLSM.append(("dsds", maskbits, subnetNameVLSM.stringValue, "\(requiredHostsVLSM.stringValue)/\(hosts) (\(used)%)")) + } + //subnetsVLSM.append(("dsds", maskbits, subnetNameVLSM.stringValue, "\(requiredHostsVLSM.stringValue)/\(hosts) (\(used)%)")) + } + else { + print("VLSM subnets empty") + subnetsVLSM.append((ipsc!.subnetId(), maskbits, subnetNameVLSM.stringValue, "\(requiredHostsVLSM.stringValue)/\(hosts) (\(used)%)")) + } + self.doVLSM() + } } else { myAlert(message: "Bad VLSM required Hosts number", info: "\(requiredHostsVLSM.integerValue) is not a number") } + requiredHostsVLSM.stringValue = "" + subnetNameVLSM.stringValue = "" } @IBAction func changeTableViewClass(_ sender: AnyObject) From e542a792e6684f0c6b608da93bd171eebc515f4e Mon Sep 17 00:00:00 2001 From: Julien Mulot Date: Fri, 9 Jul 2021 19:02:32 +0200 Subject: [PATCH 07/17] VLSM is working --- SubnetCalcAppDelegate.swift | 39 +++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/SubnetCalcAppDelegate.swift b/SubnetCalcAppDelegate.swift index 1cc1f03..54451a5 100644 --- a/SubnetCalcAppDelegate.swift +++ b/SubnetCalcAppDelegate.swift @@ -84,7 +84,8 @@ class SubnetCalcAppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate, //Private global vars private var savedTabView: [NSTabViewItem]? //ex tab_tabView private var ipsc: IPSubnetCalc? - private var subnetsVLSM = [(String, Int, String, String)]() + private var subnetsVLSM = [(Int, String, String)]() + private var globalMaskVLSM: UInt32 = IPSubnetCalc.Constants.addr32Full //Private IPv4 functions @@ -848,22 +849,28 @@ class SubnetCalcAppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate, } } else if (tableView == viewVLSM) { - print("refresh View VLSM") + //print("refresh View VLSM") if (tableColumn != nil) { if (tableColumn!.identifier.rawValue == "numVLSMCol") { return (row + 1) } else if (tableColumn!.identifier.rawValue == "subnetVLSMCol") { - return (subnetsVLSM[row].0) + var subnet = IPSubnetCalc.numerize(ipAddress: ipsc!.subnetId()) + if (row > 0) { + for index in (0...(row - 1)) { + subnet = subnet + ~IPSubnetCalc.numerize(maskbits: subnetsVLSM[index].0) + 1 + } + } + return (IPSubnetCalc.digitize(ipAddress: subnet)) } else if (tableColumn!.identifier.rawValue == "maskVLSMCol") { - return (subnetsVLSM[row].1) + return (subnetsVLSM[row].0) } else if (tableColumn!.identifier.rawValue == "nameVLSMCol") { - return (subnetsVLSM[row].2) + return (subnetsVLSM[row].1) } else if (tableColumn!.identifier.rawValue == "usedVLSMCol") { - return (subnetsVLSM[row].3) + return (subnetsVLSM[row].2) } } } @@ -927,17 +934,29 @@ class SubnetCalcAppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate, print("VLSM fitting subnet mask: \(maskbits) with \(hosts) max hosts") if (subnetsVLSM.count != 0) { print("VLSM subnets NOT empty") - if let index = subnetsVLSM.firstIndex(where: { $0.1 > maskbits }) { - subnetsVLSM.insert(("dsds", maskbits, subnetNameVLSM.stringValue, "\(requiredHostsVLSM.stringValue)/\(hosts) (\(used)%)"), at: index) + print("Mask VLSM: \(IPSubnetCalc.digitize(ipAddress: globalMaskVLSM))") + if (globalMaskVLSM > ~IPSubnetCalc.numerize(maskbits: maskbits)) { + globalMaskVLSM = globalMaskVLSM - ~IPSubnetCalc.numerize(maskbits: maskbits) + print("Mask AFTER VLSM: \(IPSubnetCalc.digitize(ipAddress: globalMaskVLSM))") + if let index = subnetsVLSM.firstIndex(where: { $0.0 > maskbits }) { + subnetsVLSM.insert((maskbits, subnetNameVLSM.stringValue, "\(requiredHostsVLSM.stringValue)/\(hosts) (\(used)%)"), at: index) } else { - subnetsVLSM.append(("dsds", maskbits, subnetNameVLSM.stringValue, "\(requiredHostsVLSM.stringValue)/\(hosts) (\(used)%)")) + subnetsVLSM.append((maskbits, subnetNameVLSM.stringValue, "\(requiredHostsVLSM.stringValue)/\(hosts) (\(used)%)")) } //subnetsVLSM.append(("dsds", maskbits, subnetNameVLSM.stringValue, "\(requiredHostsVLSM.stringValue)/\(hosts) (\(used)%)")) + } + else { + myAlert(message: "No more subnet space for Hosts requirement", info: "") + } } else { print("VLSM subnets empty") - subnetsVLSM.append((ipsc!.subnetId(), maskbits, subnetNameVLSM.stringValue, "\(requiredHostsVLSM.stringValue)/\(hosts) (\(used)%)")) + globalMaskVLSM = ~IPSubnetCalc.numerize(maskbits: ipsc!.maskBits) + print("Mask VLSM: \(IPSubnetCalc.digitize(ipAddress: globalMaskVLSM))") + globalMaskVLSM = globalMaskVLSM - ~IPSubnetCalc.numerize(maskbits: maskbits) + print("Mask AFTER VLSM: \(IPSubnetCalc.digitize(ipAddress: globalMaskVLSM))") + subnetsVLSM.append((maskbits, subnetNameVLSM.stringValue, "\(requiredHostsVLSM.stringValue)/\(hosts) (\(used)%)")) } self.doVLSM() } From b0f3cbcb19e72a446eee597b25153881a5d79374 Mon Sep 17 00:00:00 2001 From: Julien Mulot Date: Sat, 10 Jul 2021 11:46:10 +0200 Subject: [PATCH 08/17] Fix VLSM that authorize ading a last /30 subnet when no more space available Add a VLSM clear button --- Base.lproj/MainMenu.xib | 25 ++++++++++++++++++------- IPSubnetcalc.swift | 14 +++++++------- SubnetCalcAppDelegate.swift | 27 ++++++++++++++++----------- 3 files changed, 41 insertions(+), 25 deletions(-) diff --git a/Base.lproj/MainMenu.xib b/Base.lproj/MainMenu.xib index a336919..2cacabf 100644 --- a/Base.lproj/MainMenu.xib +++ b/Base.lproj/MainMenu.xib @@ -529,7 +529,7 @@ - + @@ -821,7 +821,7 @@ - + @@ -1121,7 +1121,7 @@ - + @@ -1130,7 +1130,7 @@ - + @@ -1139,7 +1139,7 @@ - + @@ -1151,7 +1151,7 @@ - + @@ -1162,8 +1162,19 @@ + + diff --git a/SubnetCalcAppDelegate.swift b/SubnetCalcAppDelegate.swift index 159038d..55cde9b 100644 --- a/SubnetCalcAppDelegate.swift +++ b/SubnetCalcAppDelegate.swift @@ -933,38 +933,38 @@ class SubnetCalcAppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate, (maskbits, hosts) = IPSubnetCalc.fittingSubnet(hosts: UInt(requiredHostsVLSM.integerValue)) if (maskbits != 0) { used = (requiredHostsVLSM.integerValue * 100) / Int(hosts) - print("VLSM fitting subnet mask: \(maskbits) with \(hosts) max hosts") + //print("VLSM fitting subnet mask: \(maskbits) with \(hosts) max hosts") if (subnetsVLSM.count != 0) { - print("VLSM subnets NOT empty") - print("Mask VLSM: \(IPSubnetCalc.digitize(ipAddress: globalMaskVLSM)) Maskbits: \(IPSubnetCalc.digitize(ipAddress: ~IPSubnetCalc.numerize(maskbits: maskbits)))") + //print("VLSM subnets NOT empty") + //print("Mask VLSM: \(IPSubnetCalc.digitize(ipAddress: globalMaskVLSM)) Maskbits: \(IPSubnetCalc.digitize(ipAddress: ~IPSubnetCalc.numerize(maskbits: maskbits)))") if (globalMaskVLSM > ~IPSubnetCalc.numerize(maskbits: maskbits)) { globalMaskVLSM = globalMaskVLSM - (~IPSubnetCalc.numerize(maskbits: maskbits) + 1) - print("Mask AFTER VLSM: \(IPSubnetCalc.digitize(ipAddress: globalMaskVLSM))") - if let index = subnetsVLSM.firstIndex(where: { $0.0 > maskbits }) { - subnetsVLSM.insert((maskbits, subnetNameVLSM.stringValue, "\(requiredHostsVLSM.stringValue)/\(hosts) (\(used)%)"), at: index) - } - else { - subnetsVLSM.append((maskbits, subnetNameVLSM.stringValue, "\(requiredHostsVLSM.stringValue)/\(hosts) (\(used)%)")) - } - //subnetsVLSM.append(("dsds", maskbits, subnetNameVLSM.stringValue, "\(requiredHostsVLSM.stringValue)/\(hosts) (\(used)%)")) + //print("Mask AFTER VLSM: \(IPSubnetCalc.digitize(ipAddress: globalMaskVLSM))") + if let index = subnetsVLSM.firstIndex(where: { $0.0 > maskbits }) { + subnetsVLSM.insert((maskbits, subnetNameVLSM.stringValue, "\(requiredHostsVLSM.stringValue)/\(hosts) (\(used)%)"), at: index) + } + else { + subnetsVLSM.append((maskbits, subnetNameVLSM.stringValue, "\(requiredHostsVLSM.stringValue)/\(hosts) (\(used)%)")) + } + //subnetsVLSM.append(("dsds", maskbits, subnetNameVLSM.stringValue, "\(requiredHostsVLSM.stringValue)/\(hosts) (\(used)%)")) } else { myAlert(message: "No space for Hosts requirement", info: "\(requiredHostsVLSM.integerValue) hosts require /\(maskbits) Mask bits") } } else { - print("VLSM subnets empty") + //print("VLSM subnets empty") globalMaskVLSM = ~IPSubnetCalc.numerize(maskbits: ipsc!.maskBits) + 1 - print("Mask VLSM: \(IPSubnetCalc.digitize(ipAddress: globalMaskVLSM)) Maskbits: \(IPSubnetCalc.digitize(ipAddress: ~IPSubnetCalc.numerize(maskbits: maskbits)))") + //print("Mask VLSM: \(IPSubnetCalc.digitize(ipAddress: globalMaskVLSM)) Maskbits: \(IPSubnetCalc.digitize(ipAddress: ~IPSubnetCalc.numerize(maskbits: maskbits)))") if (globalMaskVLSM > ~IPSubnetCalc.numerize(maskbits: maskbits)) { - globalMaskVLSM = globalMaskVLSM - (~IPSubnetCalc.numerize(maskbits: maskbits) + 1) - print("Mask AFTER VLSM: \(IPSubnetCalc.digitize(ipAddress: globalMaskVLSM))") + globalMaskVLSM = globalMaskVLSM - (~IPSubnetCalc.numerize(maskbits: maskbits) + 1) + //print("Mask AFTER VLSM: \(IPSubnetCalc.digitize(ipAddress: globalMaskVLSM))") subnetsVLSM.append((maskbits, subnetNameVLSM.stringValue, "\(requiredHostsVLSM.stringValue)/\(hosts) (\(used)%)")) } else { myAlert(message: "No space for Hosts requirement", info: "\(requiredHostsVLSM.integerValue) hosts require /\(maskbits) Mask bits") } - + } viewVLSM.reloadData() } @@ -976,6 +976,17 @@ class SubnetCalcAppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate, subnetNameVLSM.stringValue = "" } + @IBAction func deleteSubnetVLSM(_ sender: AnyObject) + { + if (subnetsVLSM.count != 0) { + if (viewVLSM.selectedRow != -1) { + //print ("Row : \(viewVLSM.selectedRow)") + subnetsVLSM.remove(at: viewVLSM.selectedRow) + viewVLSM.reloadData() + } + } + } + @IBAction func clearSubnetsVLSM(_ sender: AnyObject) { subnetsVLSM.removeAll() doVLSM() From 0aa035a4e46054f2a3142f1d78dca2828bbf445e Mon Sep 17 00:00:00 2001 From: Julien Mulot Date: Sat, 10 Jul 2021 20:23:06 +0200 Subject: [PATCH 12/17] Updated README with FLSM and VLSM support --- README.md | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index afa0f02..ef4fb4b 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,11 @@ # SubnetCalc Subnet Calculator for MacOS -What's New in version 2.0: -- IPv6 support! -- Address Class D (Multicast) and Class E (Reserved) support -- 31 and 32 mask bits support -- New Tab presentation -- Recoded in Swift -- Add alerts for bad IP or mask format -- Fix bugs +What's New in version 2.1: +- FLSM (Fixed Length Subnet Mask) support +- VLSM (Variable Length Subnet Mask) support +- Export FSLM result in a CSV file +- Export VSLM result in a CSV file For more information: http://subnetcalc.mulot.org From f87a09dea833addc54f48cc352a6e77819a0deac Mon Sep 17 00:00:00 2001 From: Julien Mulot Date: Sun, 11 Jul 2021 09:18:45 +0200 Subject: [PATCH 13/17] update gitignore change window size height --- .gitignore | 2 ++ Base.lproj/MainMenu.xib | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 84b3f80..f57123a 100644 --- a/.gitignore +++ b/.gitignore @@ -91,3 +91,5 @@ iOSInjectionProject/ __MACOSX .DS_Store +.zhistory + diff --git a/Base.lproj/MainMenu.xib b/Base.lproj/MainMenu.xib index cb533c4..c19e67f 100644 --- a/Base.lproj/MainMenu.xib +++ b/Base.lproj/MainMenu.xib @@ -222,7 +222,7 @@ - + @@ -973,7 +973,7 @@ - + @@ -982,7 +982,7 @@ - + @@ -999,7 +999,7 @@ - + From b31fd0590eafbb182113210ac99be1a33647ca1b Mon Sep 17 00:00:00 2001 From: Julien Mulot Date: Sun, 11 Jul 2021 10:18:37 +0200 Subject: [PATCH 14/17] Update globalMaskVLSM when a VLSM requirement entry is deleted doVLSM checks if new mask bits is too small for VLSM hosts requirements --- Base.lproj/MainMenu.xib | 2 +- SubnetCalcAppDelegate.swift | 30 +++++++++++++++++++++++++----- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/Base.lproj/MainMenu.xib b/Base.lproj/MainMenu.xib index c19e67f..c680f3c 100644 --- a/Base.lproj/MainMenu.xib +++ b/Base.lproj/MainMenu.xib @@ -222,7 +222,7 @@ - + diff --git a/SubnetCalcAppDelegate.swift b/SubnetCalcAppDelegate.swift index 55cde9b..f7f0664 100644 --- a/SubnetCalcAppDelegate.swift +++ b/SubnetCalcAppDelegate.swift @@ -85,7 +85,7 @@ class SubnetCalcAppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate, private var savedTabView: [NSTabViewItem]? //ex tab_tabView private var ipsc: IPSubnetCalc? private var subnetsVLSM = [(Int, String, String)]() - private var globalMaskVLSM: UInt32 = IPSubnetCalc.Constants.addr32Empty + private var globalMaskVLSM: UInt32! //Private IPv4 functions @@ -269,10 +269,30 @@ class SubnetCalcAppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate, private func doVLSM() { if (ipsc != nil) { + //print("doVLSM") maskBitsVLSMCombo.selectItem(withObjectValue: String(ipsc!.maskBits)) - //globalMaskVLSM = ~IPSubnetCalc.numerize(maskbits: ipsc!.maskBits) + 1 - subnetsVLSM.removeAll() - viewVLSM.reloadData() + var maskVLSM = ~IPSubnetCalc.numerize(maskbits: ipsc!.maskBits) + 1 + if (subnetsVLSM.count != 0) { + var fitsRequirements = true + for index in (0...(subnetsVLSM.count - 1)) { + let maskbits = subnetsVLSM[index].0 + //print("Mask VLSM: \(IPSubnetCalc.digitize(ipAddress: maskVLSM)) Maskbits: \(IPSubnetCalc.digitize(ipAddress: ~IPSubnetCalc.numerize(maskbits: maskbits)))") + if (maskVLSM > ~IPSubnetCalc.numerize(maskbits: maskbits)) { + maskVLSM = maskVLSM - (~IPSubnetCalc.numerize(maskbits: maskbits) + 1) + //print("Mask AFTER VLSM: \(IPSubnetCalc.digitize(ipAddress: maskVLSM))") + } + else { + fitsRequirements = false + } + } + if (fitsRequirements) { + globalMaskVLSM = maskVLSM + } + else { + myAlert(message: "Mask bits too small", info: "Mask bits doest not suit all VLSM hosts requirements") + } + viewVLSM.reloadData() + } } } @@ -982,7 +1002,7 @@ class SubnetCalcAppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate, if (viewVLSM.selectedRow != -1) { //print ("Row : \(viewVLSM.selectedRow)") subnetsVLSM.remove(at: viewVLSM.selectedRow) - viewVLSM.reloadData() + doVLSM() } } } From 3c307432a03b1b2d3168636fb5b5c9f4dbdf6117 Mon Sep 17 00:00:00 2001 From: Julien Mulot Date: Sun, 11 Jul 2021 10:44:43 +0200 Subject: [PATCH 15/17] clean code and removing savedTabView --- SubnetCalcAppDelegate.swift | 49 ------------------------------------- 1 file changed, 49 deletions(-) diff --git a/SubnetCalcAppDelegate.swift b/SubnetCalcAppDelegate.swift index f7f0664..92f153d 100644 --- a/SubnetCalcAppDelegate.swift +++ b/SubnetCalcAppDelegate.swift @@ -82,7 +82,6 @@ class SubnetCalcAppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate, //Private global vars - private var savedTabView: [NSTabViewItem]? //ex tab_tabView private var ipsc: IPSubnetCalc? private var subnetsVLSM = [(Int, String, String)]() private var globalMaskVLSM: UInt32! @@ -173,15 +172,6 @@ class SubnetCalcAppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate, else if (c == "D") { classType.selectItem(at: 3) - /* - savedTabView = tabView.tabViewItems - if (savedTabView != nil) - { - tabView.removeTabViewItem(savedTabView![1]) - tabView.removeTabViewItem(savedTabView![2]) - tabView.removeTabViewItem(savedTabView![3]) - } - */ } else if (c == "E") { @@ -380,13 +370,6 @@ class SubnetCalcAppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate, ipsc = IPSubnetCalc(ipAddress: ipaddr, maskbits: Int(ipmask!)!) } if (ipsc != nil) { - if (tabView.numberOfTabViewItems != 6 && savedTabView != nil) { - tabView.addTabViewItem(savedTabView![1]) - tabView.addTabViewItem(savedTabView![2]) - tabView.addTabViewItem(savedTabView![3]) - tabView.addTabViewItem(savedTabView![4]) - tabView.addTabViewItem(savedTabView![5]) - } self.doAddressMap() self.doSubnet() self.doSubnetHost() @@ -484,13 +467,6 @@ class SubnetCalcAppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate, //print("IP Address: \(ipaddr) mask: \(ipmask)") ipsc = IPSubnetCalc(ipv6: ipaddr, maskbits: Int(ipmask!)!) if (ipsc != nil) { - if (tabView.numberOfTabViewItems != 6 && savedTabView != nil) { - tabView.addTabViewItem(savedTabView![1]) - tabView.addTabViewItem(savedTabView![2]) - tabView.addTabViewItem(savedTabView![3]) - tabView.addTabViewItem(savedTabView![4]) - tabView.addTabViewItem(savedTabView![5]) - } self.doAddressMap() self.doSubnet() self.doSubnetHost() @@ -510,13 +486,6 @@ class SubnetCalcAppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate, //IPv4 UI actions @IBAction func changeAddrClassType(_ sender: AnyObject) { - if (tabView.numberOfTabViewItems != 6 && savedTabView != nil) { - tabView.addTabViewItem(savedTabView![1]) - tabView.addTabViewItem(savedTabView![2]) - tabView.addTabViewItem(savedTabView![3]) - tabView.addTabViewItem(savedTabView![4]) - tabView.addTabViewItem(savedTabView![5]) - } if (sender.indexOfSelectedItem() == 0) { classBitMap.stringValue = "nnnnnnnn.hhhhhhhh.hhhhhhhh.hhhhhhhh" @@ -537,30 +506,12 @@ class SubnetCalcAppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate, } else if (sender.indexOfSelectedItem() == 3) { - /* - savedTabView = tabView.tabViewItems - if (savedTabView != nil) - { - tabView.removeTabViewItem(savedTabView![1]) - tabView.removeTabViewItem(savedTabView![2]) - tabView.removeTabViewItem(savedTabView![3]) - } - */ classBitMap.stringValue = "hhhhhhhh.hhhhhhhh.hhhhhhhh.hhhhhhhh" classBinaryMap.stringValue = "11100000.00000000.00000000.00000000" classHexaMap.stringValue = "E0.00.00.00" } else if (sender.indexOfSelectedItem() == 4) { - /* - savedTabView = tabView.tabViewItems - if (savedTabView != nil) - { - tabView.removeTabViewItem(savedTabView![1]) - tabView.removeTabViewItem(savedTabView![2]) - tabView.removeTabViewItem(savedTabView![3]) - } - */ classBitMap.stringValue = "hhhhhhhh.hhhhhhhh.hhhhhhhh.hhhhhhhh" classBinaryMap.stringValue = "11110000.00000000.00000000.00000000" classHexaMap.stringValue = "F0.00.00.00" From 49d66ec8e9e10a0369d79e534fc359e8e55dfdd2 Mon Sep 17 00:00:00 2001 From: Julien Mulot Date: Sun, 11 Jul 2021 11:23:59 +0200 Subject: [PATCH 16/17] Fix bug when clear VLSM entries --- SubnetCalc-Info.plist | 2 +- SubnetCalc.xcodeproj/project.pbxproj | 6 ++++-- SubnetCalcAppDelegate.swift | 5 ++++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/SubnetCalc-Info.plist b/SubnetCalc-Info.plist index ccb87d0..0a089da 100644 --- a/SubnetCalc-Info.plist +++ b/SubnetCalc-Info.plist @@ -19,7 +19,7 @@ CFBundleSignature JMUL CFBundleVersion - 5 + $(CURRENT_PROJECT_VERSION) LSApplicationCategoryType public.app-category.utilities LSMinimumSystemVersion diff --git a/SubnetCalc.xcodeproj/project.pbxproj b/SubnetCalc.xcodeproj/project.pbxproj index 5cbce32..dab2636 100644 --- a/SubnetCalc.xcodeproj/project.pbxproj +++ b/SubnetCalc.xcodeproj/project.pbxproj @@ -401,6 +401,7 @@ CODE_SIGN_IDENTITY = "Mac Developer"; COMBINE_HIDPI_IMAGES = YES; COPY_PHASE_STRIP = NO; + CURRENT_PROJECT_VERSION = 6; DEVELOPMENT_TEAM = VNLK894MAE; ENABLE_HARDENED_RUNTIME = YES; GCC_DYNAMIC_NO_PIC = NO; @@ -410,7 +411,7 @@ INFOPLIST_FILE = "SubnetCalc-Info.plist"; INSTALL_PATH = "$(HOME)/Applications"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = org.mulot.subnetcalc; + PRODUCT_BUNDLE_IDENTIFIER = net.mulot.subnetcalc; PRODUCT_NAME = SubnetCalc; PROVISIONING_PROFILE_SPECIFIER = ""; SWIFT_OBJC_BRIDGING_HEADER = ""; @@ -428,6 +429,7 @@ CODE_SIGN_ENTITLEMENTS = SubnetCalc.entitlements; CODE_SIGN_IDENTITY = "Mac Developer"; COMBINE_HIDPI_IMAGES = YES; + CURRENT_PROJECT_VERSION = 6; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEVELOPMENT_TEAM = VNLK894MAE; ENABLE_HARDENED_RUNTIME = YES; @@ -436,7 +438,7 @@ INFOPLIST_FILE = "SubnetCalc-Info.plist"; INSTALL_PATH = /Applications; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = org.mulot.subnetcalc; + PRODUCT_BUNDLE_IDENTIFIER = net.mulot.subnetcalc; PRODUCT_NAME = SubnetCalc; PROVISIONING_PROFILE_SPECIFIER = ""; SWIFT_OBJC_BRIDGING_HEADER = ""; diff --git a/SubnetCalcAppDelegate.swift b/SubnetCalcAppDelegate.swift index 92f153d..2f1ccc1 100644 --- a/SubnetCalcAppDelegate.swift +++ b/SubnetCalcAppDelegate.swift @@ -281,8 +281,11 @@ class SubnetCalcAppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate, else { myAlert(message: "Mask bits too small", info: "Mask bits doest not suit all VLSM hosts requirements") } - viewVLSM.reloadData() } + else { + globalMaskVLSM = maskVLSM + } + viewVLSM.reloadData() } } From 295e241ef0ca6e350f4824dcc7884d06c5238f2f Mon Sep 17 00:00:00 2001 From: Julien Mulot Date: Mon, 12 Jul 2021 08:50:13 +0200 Subject: [PATCH 17/17] Remove / for FLSM maskbits column --- SubnetCalc.xcodeproj/project.pbxproj | 4 ++-- SubnetCalcAppDelegate.swift | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/SubnetCalc.xcodeproj/project.pbxproj b/SubnetCalc.xcodeproj/project.pbxproj index dab2636..3021f2a 100644 --- a/SubnetCalc.xcodeproj/project.pbxproj +++ b/SubnetCalc.xcodeproj/project.pbxproj @@ -401,7 +401,7 @@ CODE_SIGN_IDENTITY = "Mac Developer"; COMBINE_HIDPI_IMAGES = YES; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 6; + CURRENT_PROJECT_VERSION = 7; DEVELOPMENT_TEAM = VNLK894MAE; ENABLE_HARDENED_RUNTIME = YES; GCC_DYNAMIC_NO_PIC = NO; @@ -429,7 +429,7 @@ CODE_SIGN_ENTITLEMENTS = SubnetCalc.entitlements; CODE_SIGN_IDENTITY = "Mac Developer"; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 6; + CURRENT_PROJECT_VERSION = 7; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEVELOPMENT_TEAM = VNLK894MAE; ENABLE_HARDENED_RUNTIME = YES; diff --git a/SubnetCalcAppDelegate.swift b/SubnetCalcAppDelegate.swift index 2f1ccc1..e8e9271 100644 --- a/SubnetCalcAppDelegate.swift +++ b/SubnetCalcAppDelegate.swift @@ -814,7 +814,7 @@ class SubnetCalcAppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate, return (ipsc_tmp!.subnetId()) } else if (tableColumn!.identifier.rawValue == "maskFLSMCol") { - return ("/\(ipsc!.maskBits + slideFLSM.integerValue)") + return (ipsc!.maskBits + slideFLSM.integerValue) } else if (tableColumn!.identifier.rawValue == "rangeFLSMCol") { return (ipsc_tmp!.subnetRange())