Skip to content

Commit 5b94853

Browse files
committed
Change address field behaviour: mask is always remove after calc and the address field is preserved if there is already an address
Support for Class E Allow calculation on Class D and E address
1 parent 8e7e273 commit 5b94853

File tree

3 files changed

+56
-25
lines changed

3 files changed

+56
-25
lines changed

Base.lproj/MainMenu.xib

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -406,15 +406,16 @@
406406
<popUpButton identifier="addrclasstype" verticalHuggingPriority="750" fixedFrame="YES" imageHugsTitle="YES" translatesAutoresizingMaskIntoConstraints="NO" id="t0E-pd-tOK">
407407
<rect key="frame" x="14" y="10" width="556" height="26"/>
408408
<autoresizingMask key="autoresizingMask" widthSizable="YES"/>
409-
<popUpButtonCell key="cell" type="push" title="Class A : 1.0.0.0 - 126.255.255.255" bezelStyle="rounded" alignment="left" lineBreakMode="clipping" state="on" borderStyle="borderAndBezel" identifier="addrclasstypecell" inset="2" arrowPosition="arrowAtCenter" preferredEdge="maxY" selectedItem="ti9-uV-lnh" id="0wI-q0-Xip">
409+
<popUpButtonCell key="cell" type="push" title="Class A: 1.0.0.0 - 126.255.255.255" bezelStyle="rounded" alignment="left" lineBreakMode="clipping" state="on" borderStyle="borderAndBezel" identifier="addrclasstypecell" inset="2" arrowPosition="arrowAtCenter" preferredEdge="maxY" selectedItem="ti9-uV-lnh" id="0wI-q0-Xip">
410410
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
411411
<font key="font" metaFont="menu"/>
412412
<menu key="menu" title="OtherViews" id="YLV-1Z-ut8">
413413
<items>
414-
<menuItem title="Class A : 1.0.0.0 - 126.255.255.255" state="on" id="ti9-uV-lnh"/>
415-
<menuItem title="Class B : 128.0.0.0 - 191.255.255.255" id="onb-2U-6s3"/>
416-
<menuItem title="Class C : 192.0.0.0 - 223.255.255.255" id="CrS-JW-HI8"/>
417-
<menuItem title="Class D/Multicast : 224.0.0.0 - 239.255.255.255" id="lRR-gY-0lr"/>
414+
<menuItem title="Class A: 1.0.0.0 - 126.255.255.255" state="on" id="ti9-uV-lnh"/>
415+
<menuItem title="Class B: 128.0.0.0 - 191.255.255.255" id="onb-2U-6s3"/>
416+
<menuItem title="Class C: 192.0.0.0 - 223.255.255.255" id="CrS-JW-HI8"/>
417+
<menuItem title="Class D/Multicast: 224.0.0.0 - 239.255.255.255" id="lRR-gY-0lr"/>
418+
<menuItem title="Class E/Reserved: 240.0.0.0 - 255.255.255.255" id="tvt-9u-nNy"/>
418419
</items>
419420
</menu>
420421
</popUpButtonCell>
@@ -470,7 +471,7 @@
470471
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
471472
<clipView key="contentView" id="L0l-HJ-flz">
472473
<rect key="frame" x="1" y="1" width="567" height="485"/>
473-
<autoresizingMask key="autoresizingMask"/>
474+
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
474475
<subviews>
475476
<tableView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnSelection="YES" multipleSelection="NO" autosaveColumns="NO" headerView="583" id="586">
476477
<rect key="frame" x="0.0" y="0.0" width="567" height="462"/>

IPSubnetcalc.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,12 @@ class IPSubnetCalc: NSObject {
6464
static let maskClassA: UInt32 = 0xFF000000
6565
static let netIdClassB: UInt32 = 0x80000000
6666
static let maskClassB: UInt32 = 0xFFFF0000
67-
static let netIdClassC: UInt32 = 0xc0000000
67+
static let netIdClassC: UInt32 = 0xC0000000
6868
static let maskClassC: UInt32 = 0xFFFFFF00
69+
static let netIdClassD: UInt32 = 0xE0000000
70+
static let maskClassD: UInt32 = 0xF0000000
71+
static let netIdClassE: UInt32 = 0xF0000000
72+
static let maskClassE: UInt32 = 0xF0000000
6973
}
7074

7175
//****************
@@ -336,7 +340,10 @@ class IPSubnetCalc: NSObject {
336340
if (addr1stByte >= 192 && addr1stByte < 224) {
337341
return ("C")
338342
}
339-
return ("D")
343+
if (addr1stByte >= 224 && addr1stByte < 240) {
344+
return ("D")
345+
}
346+
return ("E")
340347
}
341348

342349
func netClass() -> String {

SubnetCalcAppDelegate.swift

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,19 @@ class SubnetCalcAppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate,
147147
else if (c == "D")
148148
{
149149
classType.selectItem(at: 3)
150+
/*
150151
savedTabView = tabView.tabViewItems
151152
if (savedTabView != nil)
152153
{
153154
tabView.removeTabViewItem(savedTabView![1])
154155
tabView.removeTabViewItem(savedTabView![2])
155156
tabView.removeTabViewItem(savedTabView![3])
156157
}
158+
*/
159+
}
160+
else if (c == "E")
161+
{
162+
classType.selectItem(at: 4)
157163
}
158164
}
159165

@@ -271,6 +277,7 @@ class SubnetCalcAppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate,
271277
}
272278
else {
273279
(ipaddr, ipmask) = splitAddrMask(address: addrField.stringValue)
280+
addrField.stringValue = ipaddr
274281
if (IPSubnetCalc.isValidIPv6(ipAddress: ipaddr, mask: Int(ipmask ?? Constants.defaultIPv6Mask)) == true) {
275282
if (ipsc != nil) {
276283
ipaddr = ipsc!.ipv4Address
@@ -290,7 +297,6 @@ class SubnetCalcAppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate,
290297
}
291298
if (IPSubnetCalc.isValidIP(ipAddress: ipaddr, mask: ipmask) == true) {
292299
//print("IP Address: \(ipaddr) mask: \(ipmask)")
293-
addrField.stringValue = ipaddr
294300
if (ipmask == nil) {
295301
ipsc = IPSubnetCalc(ipaddr)
296302
}
@@ -311,7 +317,7 @@ class SubnetCalcAppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate,
311317
}
312318
}
313319
else {
314-
myAlert(message: "Bad IPv4 Address", info: "Bad format")
320+
myAlert(message: "Bad IPv4 Address", info: "Bad format: \(ipaddr)/\(ipmask ?? "")")
315321
return
316322
}
317323
}
@@ -374,6 +380,7 @@ class SubnetCalcAppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate,
374380
var ipmask: String?
375381

376382
(ipaddr, ipmask) = splitAddrMask(address: addrField.stringValue)
383+
addrField.stringValue = ipaddr
377384
if (IPSubnetCalc.isValidIP(ipAddress: ipaddr, mask: ipmask) == true) {
378385
if (ipsc != nil) {
379386
ipaddr = ipsc!.ipv6Address
@@ -390,12 +397,11 @@ class SubnetCalcAppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate,
390397
}
391398
}
392399
else if (Int(ipmask!) == nil) {
393-
myAlert(message: "Bad IPv6 mask", info: "Bad format")
400+
myAlert(message: "Bad IPv6 mask", info: "Bad format: \(ipmask!)")
394401
return
395402
}
396403
if (IPSubnetCalc.isValidIPv6(ipAddress: ipaddr, mask: Int(ipmask!)) == true) {
397404
//print("IP Address: \(ipaddr) mask: \(ipmask)")
398-
addrField.stringValue = ipaddr
399405
ipsc = IPSubnetCalc(ipv6: ipaddr, maskbits: Int(ipmask!)!)
400406
if (ipsc != nil) {
401407
if (tabView.numberOfTabViewItems != 4 && savedTabView != nil) {
@@ -411,7 +417,7 @@ class SubnetCalcAppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate,
411417
}
412418
}
413419
else {
414-
myAlert(message: "Bad IPv6 Address", info: "Bad format")
420+
myAlert(message: "Bad IPv6 Address", info: "Bad format: \(ipaddr)/\(ipmask ?? "")")
415421
return
416422
}
417423
}
@@ -445,17 +451,34 @@ class SubnetCalcAppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate,
445451
}
446452
else if (sender.indexOfSelectedItem() == 3)
447453
{
454+
/*
448455
savedTabView = tabView.tabViewItems
449456
if (savedTabView != nil)
450457
{
451458
tabView.removeTabViewItem(savedTabView![1])
452459
tabView.removeTabViewItem(savedTabView![2])
453460
tabView.removeTabViewItem(savedTabView![3])
454461
}
462+
*/
455463
classBitMap.stringValue = "hhhhhhhh.hhhhhhhh.hhhhhhhh.hhhhhhhh"
456464
classBinaryMap.stringValue = "11100000.00000000.00000000.00000000"
457465
classHexaMap.stringValue = "E0.00.00.00"
458466
}
467+
else if (sender.indexOfSelectedItem() == 4)
468+
{
469+
/*
470+
savedTabView = tabView.tabViewItems
471+
if (savedTabView != nil)
472+
{
473+
tabView.removeTabViewItem(savedTabView![1])
474+
tabView.removeTabViewItem(savedTabView![2])
475+
tabView.removeTabViewItem(savedTabView![3])
476+
}
477+
*/
478+
classBitMap.stringValue = "hhhhhhhh.hhhhhhhh.hhhhhhhh.hhhhhhhh"
479+
classBinaryMap.stringValue = "11110000.00000000.00000000.00000000"
480+
classHexaMap.stringValue = "F0.00.00.00"
481+
}
459482
}
460483

461484
@IBAction func changeMaxHosts(_ sender: AnyObject)
@@ -469,7 +492,7 @@ class SubnetCalcAppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate,
469492
self.doIPSubnetCalc()
470493
}
471494
else {
472-
myAlert(message: "Bad Max Hosts", info: "Bad value")
495+
myAlert(message: "Bad Max Hosts", info: "Bad selection")
473496
return
474497
}
475498
}
@@ -485,7 +508,7 @@ class SubnetCalcAppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate,
485508
self.doIPSubnetCalc()
486509
}
487510
else {
488-
myAlert(message: "Bad Max Subnets", info: "Bad value")
511+
myAlert(message: "Bad Max Subnets", info: "Bad selection")
489512
return
490513
}
491514
}
@@ -501,7 +524,7 @@ class SubnetCalcAppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate,
501524
self.doIPSubnetCalc()
502525
}
503526
else {
504-
myAlert(message: "Bad Subnet Bits", info: "Bad format")
527+
myAlert(message: "Bad Subnet Bits", info: "Bad selection")
505528
return
506529
}
507530
}
@@ -525,7 +548,7 @@ class SubnetCalcAppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate,
525548
self.doIPSubnetCalc()
526549
}
527550
else {
528-
myAlert(message: "Bad Subnet Mask", info: "Bad format")
551+
myAlert(message: "Bad Subnet Mask", info: "Bad selection")
529552
return
530553
}
531554
}
@@ -541,7 +564,7 @@ class SubnetCalcAppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate,
541564
self.doIPSubnetCalc()
542565
}
543566
else {
544-
myAlert(message: "Bad Mask Bits", info: "Bad format")
567+
myAlert(message: "Bad Mask Bits", info: "Bad selection")
545568
return
546569
}
547570
}
@@ -574,7 +597,7 @@ class SubnetCalcAppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate,
574597
}
575598
}
576599
else {
577-
myAlert(message: "Bad CIDR Mask Bits", info: "Bad format")
600+
myAlert(message: "Bad CIDR Mask Bits", info: "Bad selection")
578601
return
579602
}
580603
}
@@ -609,7 +632,7 @@ class SubnetCalcAppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate,
609632
}
610633
}
611634
else {
612-
myAlert(message: "Bad CIDR Mask", info: "Bad format")
635+
myAlert(message: "Bad CIDR Mask", info: "Bad selection")
613636
return
614637
}
615638
}
@@ -642,7 +665,7 @@ class SubnetCalcAppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate,
642665
}
643666
}
644667
else {
645-
myAlert(message: "Bad Max Supernets", info: "Bad value")
668+
myAlert(message: "Bad Max Supernets", info: "Bad selection")
646669
return
647670
}
648671
}
@@ -663,7 +686,7 @@ class SubnetCalcAppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate,
663686
}
664687
}
665688
else {
666-
myAlert(message: "Bad Max Adresses", info: "Bad value")
689+
myAlert(message: "Bad Max Adresses", info: "Bad selection")
667690
return
668691
}
669692
}
@@ -684,7 +707,7 @@ class SubnetCalcAppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate,
684707
}
685708
}
686709
else {
687-
myAlert(message: "Bad Max Subnets", info: "Bad value")
710+
myAlert(message: "Bad Max Subnets", info: "Bad selection")
688711
return
689712
}
690713
}
@@ -809,7 +832,7 @@ class SubnetCalcAppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate,
809832
self.doIPv6SubnetCalc()
810833
}
811834
else {
812-
myAlert(message: "Bad IPv6 Mask Bits", info: "Bad format")
835+
myAlert(message: "Bad IPv6 Mask Bits", info: "Bad selection")
813836
return
814837
}
815838
}
@@ -834,7 +857,7 @@ class SubnetCalcAppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate,
834857
self.doIPv6SubnetCalc()
835858
}
836859
else {
837-
myAlert(message: "Bad Max Hosts", info: "Bad format")
860+
myAlert(message: "Bad Max Hosts", info: "Bad selection")
838861
return
839862
}
840863
}

0 commit comments

Comments
 (0)