Skip to content

Commit 96c25b0

Browse files
committed
30 and 31 Mask bits support
change MaxHosts return value to 0 for 32 mask bits Change SubnetRange return value for 32 and 31 mask bits Enable SWIFT_COMPILATION_MODE = wholemodule
1 parent 85f45ae commit 96c25b0

File tree

6 files changed

+30
-21
lines changed

6 files changed

+30
-21
lines changed

Base.lproj/MainMenu.xib

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@
154154
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/>
155155
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
156156
<rect key="contentRect" x="335" y="326" width="670" height="694"/>
157-
<rect key="screenRect" x="0.0" y="0.0" width="1920" height="1080"/>
157+
<rect key="screenRect" x="0.0" y="0.0" width="1440" height="900"/>
158158
<value key="minSize" type="size" width="670" height="694"/>
159159
<view key="contentView" id="372">
160160
<rect key="frame" x="0.0" y="0.0" width="670" height="694"/>
@@ -565,9 +565,9 @@
565565
</textFieldCell>
566566
</textField>
567567
<slider verticalHuggingPriority="750" fixedFrame="YES" allowsExpansionToolTips="YES" translatesAutoresizingMaskIntoConstraints="NO" id="708">
568-
<rect key="frame" x="112" y="0.0" width="360" height="24"/>
568+
<rect key="frame" x="112" y="0.0" width="360" height="28"/>
569569
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMinY="YES"/>
570-
<sliderCell key="cell" continuous="YES" state="on" baseWritingDirection="leftToRight" alignment="left" minValue="1" maxValue="30" doubleValue="1" tickMarkPosition="above" numberOfTickMarks="30" allowsTickMarkValuesOnly="YES" sliderType="linear" id="709"/>
570+
<sliderCell key="cell" continuous="YES" state="on" baseWritingDirection="leftToRight" alignment="left" minValue="1" maxValue="32" doubleValue="1" tickMarkPosition="above" numberOfTickMarks="32" allowsTickMarkValuesOnly="YES" sliderType="linear" id="709"/>
571571
<connections>
572572
<action selector="subnetBitsSlide:" target="b7w-M5-ti7" id="NME-GB-bJ8"/>
573573
</connections>

IPSubnetcalc.swift

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ class IPSubnetCalc: NSObject {
267267
var maxHosts: UInt32 = 0
268268

269269
if (self.maskBits == 32) {
270-
return (1)
270+
return (0)
271271
}
272272
maxHosts = (Constants.addr32Full >> self.maskBits) - 1
273273
return (Int(maxHosts))
@@ -311,8 +311,14 @@ class IPSubnetCalc: NSObject {
311311
var firstIP: UInt32 = 0
312312
var lastIP: UInt32 = 0
313313

314-
firstIP = IPSubnetCalc.numerize(ipAddress: subnetId()) + 1
315-
lastIP = IPSubnetCalc.numerize(ipAddress: subnetBroadcast()) - 1
314+
if (maskBits == 31 || maskBits == 32) {
315+
firstIP = IPSubnetCalc.numerize(ipAddress: subnetId())
316+
lastIP = IPSubnetCalc.numerize(ipAddress: subnetBroadcast())
317+
}
318+
else {
319+
firstIP = IPSubnetCalc.numerize(ipAddress: subnetId()) + 1
320+
lastIP = IPSubnetCalc.numerize(ipAddress: subnetBroadcast()) - 1
321+
}
316322
range = IPSubnetCalc.digitize(ipAddress: firstIP) + " - " + IPSubnetCalc.digitize(ipAddress: lastIP)
317323
return (range)
318324
}

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ Subnet Calculator for MacOS
33

44
What's New in version 2.0:
55
- IPv6 support!
6+
- Address Class D (Multicast) and Class E (Reserved) support
7+
- 31 and 32 mask bits support
68
- New Tab presentation
79
- Recoded in Swift
810
- Add alerts for bad IP or mask format

SubnetCalc.xcodeproj/project.pbxproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@
203203
29B97313FDCFA39411CA2CEA /* Project object */ = {
204204
isa = PBXProject;
205205
attributes = {
206-
LastUpgradeCheck = 1220;
206+
LastUpgradeCheck = 1230;
207207
TargetAttributes = {
208208
8D1107260486CEB800E47090 = {
209209
LastSwiftMigration = 1220;
@@ -534,6 +534,7 @@
534534
PROVISIONING_PROFILE = "";
535535
SDKROOT = macosx;
536536
STRIP_INSTALLED_PRODUCT = YES;
537+
SWIFT_COMPILATION_MODE = wholemodule;
537538
};
538539
name = Release;
539540
};

SubnetCalc.xcodeproj/xcshareddata/xcschemes/SubnetCalc.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "1220"
3+
LastUpgradeVersion = "1230"
44
version = "1.7">
55
<BuildAction
66
parallelizeBuildables = "YES"

SubnetCalcAppDelegate.swift

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -78,43 +78,43 @@ class SubnetCalcAppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate,
7878

7979
//Private IPv4 functions
8080
private func initCIDRTab() {
81-
for bits in (1...30) {
81+
for bits in (1...32) {
8282
supernetMaskBitsCombo.addItem(withObjectValue: String(bits))
8383
}
8484

85-
for index in (2...31).reversed() {
85+
for index in (0...31).reversed() {
8686
supernetMaskCombo.addItem(withObjectValue: IPSubnetCalc.digitize(ipAddress: (IPSubnetCalc.Constants.addr32Full << index)))
8787
}
88-
for index in (0...29) {
88+
for index in (0...31) {
8989
supernetMaxCombo.addItem(withObjectValue: NSDecimalNumber(decimal: pow(2, index)).stringValue)
9090
}
9191
for index in (1...31) {
9292
supernetMaxAddr.addItem(withObjectValue: NSDecimalNumber(decimal: (pow(2, index) - 2)).stringValue)
9393
}
94-
for index in (0...31) {
94+
for index in (0...32) {
9595
supernetMaxSubnetsCombo.addItem(withObjectValue: NSDecimalNumber(decimal: pow(2, index)).stringValue)
9696
}
9797
}
9898

9999
private func initSubnetsTab() {
100-
for index in (2...24).reversed() {
100+
for index in (0...24).reversed() {
101101
if (wildcard.state == NSControl.StateValue.on) {
102102
subnetMaskCombo.addItem(withObjectValue: IPSubnetCalc.digitize(ipAddress: ~(IPSubnetCalc.Constants.addr32Full << index)))
103103
}
104104
else {
105105
subnetMaskCombo.addItem(withObjectValue: IPSubnetCalc.digitize(ipAddress: (IPSubnetCalc.Constants.addr32Full << index)))
106106
}
107107
}
108-
for bits in (8...30) {
108+
for bits in (8...32) {
109109
maskBitsCombo.addItem(withObjectValue: String(bits))
110110
}
111-
for bits in (0...22) {
111+
for bits in (0...24) {
112112
subnetBitsCombo.addItem(withObjectValue: String(bits))
113113
}
114-
for index in (2...24) {
114+
for index in (1...24) {
115115
maxHostsBySubnetCombo.addItem(withObjectValue: NSDecimalNumber(decimal: (pow(2, index) - 2)).stringValue)
116116
}
117-
for index in (0...22) {
117+
for index in (0...24) {
118118
maxSubnetsCombo.addItem(withObjectValue: NSDecimalNumber(decimal: pow(2, index)).stringValue)
119119
}
120120
classBitMap.stringValue = "nnnnnnnn.hhhhhhhh.hhhhhhhh.hhhhhhhh"
@@ -489,7 +489,7 @@ class SubnetCalcAppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate,
489489
ipsc = IPSubnetCalc(Constants.defaultIP)
490490
}
491491
if (sender.indexOfSelectedItem != -1) {
492-
ipsc!.maskBits = 30 - sender.indexOfSelectedItem()
492+
ipsc!.maskBits = 31 - sender.indexOfSelectedItem()
493493
self.doIPSubnetCalc()
494494
}
495495
else {
@@ -699,7 +699,7 @@ class SubnetCalcAppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate,
699699
ipsc = IPSubnetCalc(Constants.defaultIP)
700700
}
701701
if (sender.indexOfSelectedItem != -1) {
702-
if ((32 - sender.indexOfSelectedItem) < 32) {
702+
if ((32 - sender.indexOfSelectedItem) <= 32) {
703703
doCIDR(maskbits: (32 - sender.indexOfSelectedItem))
704704
}
705705
else {
@@ -793,15 +793,15 @@ class SubnetCalcAppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate,
793793
{
794794
subnetMaskCombo.removeAllItems()
795795
if (wildcard.state == NSControl.StateValue.on) {
796-
for index in (2...24).reversed() {
796+
for index in (0...24).reversed() {
797797
subnetMaskCombo.addItem(withObjectValue: IPSubnetCalc.digitize(ipAddress: ~(IPSubnetCalc.Constants.addr32Full << index)))
798798
}
799799
if (ipsc != nil) {
800800
subnetMaskCombo.selectItem(withObjectValue: ipsc!.wildcardMask())
801801
}
802802
}
803803
else {
804-
for index in (2...24).reversed() {
804+
for index in (0...24).reversed() {
805805
subnetMaskCombo.addItem(withObjectValue: IPSubnetCalc.digitize(ipAddress: (IPSubnetCalc.Constants.addr32Full << index)))
806806
}
807807
if (ipsc != nil) {

0 commit comments

Comments
 (0)