File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed
Sources/CornucopiaCore/Extensions/String Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change 1+ //
2+ // Cornucopia – (C) Dr. Lauer Information Technology
3+ //
4+ import Foundation
5+
6+ public extension String {
7+
8+ /// A simplified check if this and another string are in the same IPv4 subnet.
9+ func CC_isInSameIPv4SubnetAs( other: String ) -> Bool {
10+
11+ if self . hasPrefix ( " 169.254. " ) && other. hasPrefix ( " 169.254. " ) {
12+ // Link-local uses /16
13+ let part1 = self . components ( separatedBy: " . " ) [ ... 1 ] . joined ( separator: " . " )
14+ let part2 = other. components ( separatedBy: " . " ) [ ... 1 ] . joined ( separator: " . " )
15+ return part1 == part2
16+ } else {
17+ // Assume /24 for everything else
18+ let part1 = self . components ( separatedBy: " . " ) [ ... 2 ] . joined ( separator: " . " )
19+ let part2 = other. components ( separatedBy: " . " ) [ ... 2 ] . joined ( separator: " . " )
20+ return part1 == part2
21+ }
22+ }
23+ }
You can’t perform that action at this time.
0 commit comments