Skip to content

Commit f8a553e

Browse files
author
Steve Trease
committed
Link-layer filtering implemented
1 parent 44d0701 commit f8a553e

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

IP Address/ViewController.swift

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSour
3232
}
3333

3434

35+
override func viewDidAppear(_ animated: Bool) {
36+
print (NSURL (fileURLWithPath: "\(#file)").lastPathComponent!, "\(#function)")
37+
refreshAndSortAndFilterData()
38+
self.tableView.reloadData()
39+
}
40+
41+
42+
3543
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
3644
return interfaces.count
3745
}
@@ -43,11 +51,11 @@ class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSour
4351
cell.textLabel?.text = interfaces[indexPath.row].description
4452
cell.detailTextLabel?.text = interfaces[indexPath.row].address
4553

46-
// print ("\(interfaces[indexPath.row].debugDescription)")
47-
4854
return cell
4955
}
5056

57+
58+
// Toggle switches toggled
5159
@IBAction func switchToggled(_ sender: UISwitch) {
5260
print (NSURL (fileURLWithPath: "\(#file)").lastPathComponent!, "\(#function)")
5361
refreshAndSortAndFilterData()
@@ -66,24 +74,29 @@ class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSour
6674
func refreshAndSortAndFilterData () {
6775
interfaces = Interface.allInterfaces()
6876

69-
let IPv4Interfaces = interfaces.filter { $0.family == .ipv4 }
70-
let IPv6Interfaces = interfaces.filter { $0.family == .ipv6 }
77+
var IPv4Interfaces = interfaces.filter { $0.family == .ipv4 }
78+
var IPv6Interfaces = interfaces.filter { $0.family == .ipv6 }
7179

7280
print ("\(IPv4Interfaces.count) \(IPv6Interfaces.count) \(interfaces.count)")
7381

74-
interfaces = []
75-
if (IPv4filterSwitch.isOn) {
76-
interfaces = interfaces + IPv4Interfaces
82+
if (!IPv4filterSwitch.isOn) {
83+
IPv4Interfaces = []
7784
}
78-
if (IPv6filterSwitch.isOn) {
79-
interfaces = interfaces + IPv6Interfaces
85+
if (!IPv6filterSwitch.isOn) {
86+
IPv6Interfaces = []
87+
} else {
88+
if (!linkLayerfilterSwitch.isOn) {
89+
IPv6Interfaces = IPv6Interfaces.filter { !($0.address?.hasPrefix ("fe80"))! }
90+
}
8091
}
8192

82-
print (interfaces.count)
93+
interfaces = IPv4Interfaces + IPv6Interfaces
8394

8495
interfaces.sort {
8596
if $0.description == $1.description { return $0.address! < $1.address! }
8697
return $0.description < $1.description
8798
}
99+
100+
print (interfaces.count)
88101
}
89102
}

0 commit comments

Comments
 (0)