@@ -933,7 +933,7 @@ class SubnetCalcAppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate,
933933 ( maskbits, hosts) = IPSubnetCalc . fittingSubnet ( hosts: UInt ( requiredHostsVLSM. integerValue) )
934934 if ( maskbits != 0 ) {
935935 used = ( requiredHostsVLSM. integerValue * 100 ) / Int( hosts)
936- // print("VLSM fitting subnet mask: \(maskbits) with \(hosts) max hosts")
936+ print ( " VLSM fitting subnet mask: \( maskbits) with \( hosts) max hosts " )
937937 if ( subnetsVLSM. count != 0 ) {
938938 print ( " VLSM subnets NOT empty " )
939939 print ( " Mask VLSM: \( IPSubnetCalc . digitize ( ipAddress: globalMaskVLSM) ) Maskbits: \( IPSubnetCalc . digitize ( ipAddress: ~ IPSubnetCalc. numerize ( maskbits: maskbits) ) ) " )
@@ -955,10 +955,16 @@ class SubnetCalcAppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate,
955955 else {
956956 print ( " VLSM subnets empty " )
957957 globalMaskVLSM = ~ IPSubnetCalc. numerize ( maskbits: ipsc!. maskBits) + 1
958- print ( " Mask VLSM: \( IPSubnetCalc . digitize ( ipAddress: globalMaskVLSM) ) " )
958+ print ( " Mask VLSM: \( IPSubnetCalc . digitize ( ipAddress: globalMaskVLSM) ) Maskbits: \( IPSubnetCalc . digitize ( ipAddress: ~ IPSubnetCalc. numerize ( maskbits: maskbits) ) ) " )
959+ if ( globalMaskVLSM > ~ IPSubnetCalc. numerize ( maskbits: maskbits) ) {
959960 globalMaskVLSM = globalMaskVLSM - ( ~ IPSubnetCalc. numerize ( maskbits: maskbits) + 1 )
960961 print ( " Mask AFTER VLSM: \( IPSubnetCalc . digitize ( ipAddress: globalMaskVLSM) ) " )
961- subnetsVLSM. append ( ( maskbits, subnetNameVLSM. stringValue, " \( requiredHostsVLSM. stringValue) / \( hosts) ( \( used) %) " ) )
962+ subnetsVLSM. append ( ( maskbits, subnetNameVLSM. stringValue, " \( requiredHostsVLSM. stringValue) / \( hosts) ( \( used) %) " ) )
963+ }
964+ else {
965+ myAlert ( message: " No space for Hosts requirement " , info: " \( requiredHostsVLSM. integerValue) hosts require / \( maskbits) Mask bits " )
966+ }
967+
962968 }
963969 viewVLSM. reloadData ( )
964970 }
@@ -1080,7 +1086,7 @@ class SubnetCalcAppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate,
10801086 self . calc ( sender)
10811087 }
10821088
1083- @IBAction func exportCSV ( _ sender: AnyObject )
1089+ @IBAction func exportSubnetsHosts ( _ sender: AnyObject )
10841090 {
10851091 if ( ipsc != nil ) {
10861092 let panel = NSSavePanel ( )
@@ -1119,6 +1125,97 @@ class SubnetCalcAppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate,
11191125 }
11201126 }
11211127
1128+ @IBAction func exportFLSM( _ sender: AnyObject )
1129+ {
1130+ if ( ipsc != nil ) {
1131+ if ( ipsc!. maskBits <= 29 ) {
1132+ let panel = NSSavePanel ( )
1133+ panel. allowedFileTypes = [ " csv " ]
1134+ panel. begin ( completionHandler: { ( result) in
1135+ if ( result == NSApplication . ModalResponse. OK && panel. url != nil ) {
1136+ var fileMgt : FileManager
1137+ if #available( OSX 10 . 14 , * ) {
1138+ fileMgt = FileManager ( authorization: NSWorkspace . Authorization ( ) )
1139+ } else {
1140+ // Fallback on earlier versions
1141+ fileMgt = FileManager . default
1142+ }
1143+ fileMgt. createFile ( atPath: panel. url!. path, contents: nil , attributes: nil )
1144+ //var cvsData = NSMutableData.init(capacity: Constants.BUFFER_LINES)
1145+ var cvsData = Data ( capacity: Constants . BUFFER_LINES)
1146+ let cvsFile = FileHandle ( forWritingAtPath: panel. url!. path)
1147+ if ( cvsFile != nil ) {
1148+ var cvsStr = " #;Subnet ID;Mask bits;Range;Broadcast \n "
1149+ let subnetid : UInt32 = ( ( IPSubnetCalc . numerize ( ipAddress: self . ipsc!. ipv4Address) & self . ipsc!. classMask ( ) ) >> ( 32 - self . ipsc!. maskBits) ) << ( 32 - self . ipsc!. maskBits)
1150+ for index in ( 0 ... ( Int ( truncating: NSDecimalNumber ( decimal: pow ( 2 , self . slideFLSM. integerValue) ) ) - 1 ) ) {
1151+ let ipaddr = ( subnetid >> ( 32 - ( self . ipsc!. maskBits + self . slideFLSM. integerValue) ) + UInt32( index) ) << ( 32 - ( self . ipsc!. maskBits + self . slideFLSM. integerValue) )
1152+ let ipsc_tmp = IPSubnetCalc ( ipAddress: IPSubnetCalc . digitize ( ipAddress: ipaddr) , maskbits: ( self . ipsc!. maskBits + self . slideFLSM. integerValue) )
1153+ if ( ipsc_tmp != nil ) {
1154+ cvsStr. append ( " \( index + 1 ) ; \( ipsc_tmp!. subnetId ( ) ) ; \( self . ipsc!. maskBits + self . slideFLSM. integerValue) ; \( ipsc_tmp!. subnetRange ( ) ) ; \( ipsc_tmp!. subnetBroadcast ( ) ) \n " )
1155+ }
1156+ }
1157+ cvsData. append ( cvsStr. data ( using: String . Encoding. ascii) !)
1158+ cvsFile!. write ( cvsData)
1159+ cvsFile!. synchronizeFile ( )
1160+ cvsFile!. closeFile ( )
1161+ }
1162+ }
1163+ }
1164+ )
1165+ }
1166+ else {
1167+ myAlert ( message: " Cannot not export FLSM Info " , info: " Mask bits \( ipsc!. maskBits) > 29 " )
1168+ }
1169+ }
1170+ }
1171+
1172+ @IBAction func exportVLSM( _ sender: AnyObject )
1173+ {
1174+ if ( ipsc != nil ) {
1175+ if ( subnetsVLSM. count != 0 ) {
1176+ let panel = NSSavePanel ( )
1177+ panel. allowedFileTypes = [ " csv " ]
1178+ panel. begin ( completionHandler: { ( result) in
1179+ if ( result == NSApplication . ModalResponse. OK && panel. url != nil ) {
1180+ var fileMgt : FileManager
1181+ if #available( OSX 10 . 14 , * ) {
1182+ fileMgt = FileManager ( authorization: NSWorkspace . Authorization ( ) )
1183+ } else {
1184+ // Fallback on earlier versions
1185+ fileMgt = FileManager . default
1186+ }
1187+ fileMgt. createFile ( atPath: panel. url!. path, contents: nil , attributes: nil )
1188+ //var cvsData = NSMutableData.init(capacity: Constants.BUFFER_LINES)
1189+ var cvsData = Data ( capacity: Constants . BUFFER_LINES)
1190+ let cvsFile = FileHandle ( forWritingAtPath: panel. url!. path)
1191+ if ( cvsFile != nil ) {
1192+ var cvsStr = " #;Subnet ID;Mask bits;Subnet Name;Used \n "
1193+ let subnetid = IPSubnetCalc . numerize ( ipAddress: self . ipsc!. subnetId ( ) )
1194+ for index in ( 0 ... ( self . subnetsVLSM. count - 1 ) ) {
1195+ var subnet = subnetid
1196+ if ( index > 0 ) {
1197+ for index2 in ( 0 ... ( index - 1 ) ) {
1198+ subnet = subnet + ~ IPSubnetCalc. numerize ( maskbits: self . subnetsVLSM [ index2] . 0 ) + 1
1199+ }
1200+ }
1201+ //print("VLSM: \(index + 1);\(IPSubnetCalc.digitize(ipAddress: subnet));\(self.subnetsVLSM[index].0);\(self.subnetsVLSM[index].1);\(self.subnetsVLSM[index].2)\n")
1202+ cvsStr. append ( " \( index + 1 ) ; \( IPSubnetCalc . digitize ( ipAddress: subnet) ) ; \( self . subnetsVLSM [ index] . 0 ) ; \( self . subnetsVLSM [ index] . 1 ) ; \( self . subnetsVLSM [ index] . 2 ) \n " )
1203+ }
1204+ cvsData. append ( cvsStr. data ( using: String . Encoding. ascii) !)
1205+ cvsFile!. write ( cvsData)
1206+ cvsFile!. synchronizeFile ( )
1207+ cvsFile!. closeFile ( )
1208+ }
1209+ }
1210+ }
1211+ )
1212+ }
1213+ else {
1214+ myAlert ( message: " Cannot not export VLSM Info " , info: " No subnet " )
1215+ }
1216+ }
1217+ }
1218+
11221219 @IBAction func exportClipboard( _ sender: AnyObject )
11231220 {
11241221 if ( ipsc != nil ) {
0 commit comments