Skip to content

Commit

Permalink
Merge pull request #2 from mulot/developpement
Browse files Browse the repository at this point in the history
Developpement
  • Loading branch information
mulot authored Nov 21, 2020
2 parents 2d789a4 + 0ccc88b commit 9a97e8b
Show file tree
Hide file tree
Showing 45 changed files with 2,320 additions and 4,880 deletions.
853 changes: 853 additions & 0 deletions Base.lproj/MainMenu.xib

Large diffs are not rendered by default.

4,544 changes: 0 additions & 4,544 deletions English.lproj/MainMenu.xib

This file was deleted.

9 changes: 6 additions & 3 deletions IPSubnetCalc.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,18 @@
unsigned int hostSubnetUbound;

unsigned int ciscoWildcard;
char bitMap[36];
char bitMap[36];
Boolean classless;
}

@property Boolean classless;

+ (NSString *)denumberize:(unsigned int)address;
+ (unsigned int)numberize:(const char *)address;
+ (int)countOnBits:(unsigned int)number;
- (void)initAddress:(const char *)address;
- (void)initAddressAndMask:(const char *)address:(unsigned int)addressMask;
- (void)initAddressAndMaskWithUnsignedInt:(unsigned int)address:(unsigned int)addressMask;
- (void)initAddressAndMask:(const char *)address mask:(unsigned int)addressMask;
- (void)initAddressAndMaskWithUnsignedInt:(unsigned int)address mask:(unsigned int)addressMask;
- (NSString *)subnetHostAddrRange;
- (NSString *)networkClass;
- (unsigned int)netBits;
Expand Down
108 changes: 65 additions & 43 deletions IPSubnetCalc.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,37 @@

@implementation IPSubnetCalc

@synthesize classless;

+ (unsigned int)numberize:(const char *)address
{
unsigned int sin_addr;

if ((inet_pton(AF_INET, address, &sin_addr)) <= 0)
return (-1);
return (ntohl(sin_addr));
if (address != NULL)
{
if ((inet_pton(AF_INET, address, &sin_addr)) <= 0)
return (-1);
return (ntohl(sin_addr));
}
return (0);
}

+ (NSString *)denumberize:(unsigned int)address
{
char *buffer;
unsigned int addr_nl;
NSString *nstr;

NSString *nstr;
addr_nl = htonl(address);
if (!(buffer = malloc(INET_ADDRSTRLEN * sizeof (char))))
return (NULL);
if (!inet_ntop(AF_INET, &addr_nl, buffer, INET_ADDRSTRLEN * sizeof (char)))
{
free(buffer);
return (NULL);
nstr = [NSString stringWithCString: buffer encoding: NSASCIIStringEncoding];
free(buffer);
}
nstr = [NSString stringWithCString: buffer encoding: NSASCIIStringEncoding];
free(buffer);
return (nstr);
}

Expand Down Expand Up @@ -73,7 +82,7 @@ - (IBAction)setBitMap
bitMap[DOT(2)] = '.';
bitMap[DOT(3)] = '.';
bitMap[35] = 0;
for (i = 0; i < 35; i++)
{
if (i == DOT(1) || i == DOT(2) || i == DOT(3))
Expand Down Expand Up @@ -135,37 +144,35 @@ - (char)getClass:(unsigned int)address
return ('d');
}

- (int)setClassInfo:(char)class:(const int)setDefaults
{
if (networkClass)
[networkClass release];
- (int)setClassInfo:(char)class defaults:(const int)setDefaults
{
switch (class)
{
case 'a' :
networkClass = [[NSString alloc] initWithString: @"A"];
networkClass = @"A";
netBits = 8;
netId = 0x01000000;
mask = 0xff000000;
break;
case 'b' :
networkClass = [[NSString alloc] initWithString: @"B"];
networkClass = @"B";
netBits = 16;
netId = 0x80000000;
mask = 0xffff0000;
break;
case 'c' :
networkClass = [[NSString alloc] initWithString: @"C"];
networkClass = @"C";
netBits = 24;
netId = 0xc0000000;
mask = 0xffffff00;
break;
case 'd' :
networkClass = [[NSString alloc] initWithString: @"D"];
break;
case 'd' :
networkClass = @"D";
break;
default :
return (-1);
}
if (setDefaults)
if (setDefaults)
hostAddr = netId + 1;
return (0);
}
Expand All @@ -177,17 +184,17 @@ - (void)initByAddr:(unsigned int)address
class = [self getClass:address];
subnetBits = 0;
hostAddr = address;
[self setClassInfo:class:0];
[self setClassInfo:class defaults:0];
[self initNetwork];
}

- (void)initByAddrAndMask:(unsigned int)address:(unsigned int)addressMask
- (void)initByAddrAndMask:(unsigned int)address mask:(unsigned int)addressMask
{
char class;

class = [self getClass:address];
hostAddr = address;
[self setClassInfo:class:0];
[self setClassInfo:class defaults:0];
if (mask > addressMask)
{
mask = addressMask;
Expand All @@ -204,35 +211,41 @@ - (void)initByAddrAndMask:(unsigned int)address:(unsigned int)addressMask

- (void)initAddress:(const char *)address
{
[self initByAddr:[IPSubnetCalc numberize:address]];
if (address)
{
[self initByAddr:[IPSubnetCalc numberize:address]];
}

}

- (void)initAddressAndMask:(const char *)address:(unsigned int)addressMask
- (void)initAddressAndMask:(const char *)address mask:(unsigned int)addressMask
{
[self initByAddrAndMask:[IPSubnetCalc numberize:address]:addressMask];
if (address)
{
[self initByAddrAndMask:[IPSubnetCalc numberize:address] mask:addressMask];
}

}

- (void)initAddressAndMaskWithUnsignedInt:(unsigned int)address:(unsigned int)addressMask
- (void)initAddressAndMaskWithUnsignedInt:(unsigned int)address mask:(unsigned int)addressMask
{
[self initByAddrAndMask:address:addressMask];
[self initByAddrAndMask:address mask:addressMask];

}
- (NSString *)subnetHostAddrRange
{
NSString *strRange;
unsigned int tmpmask;

strRange = [[[NSString alloc] initWithString: [IPSubnetCalc denumberize: ((hostAddr & (mask | subnetMask)) + 1)]] autorelease];
strRange = [[NSString alloc] initWithString: [IPSubnetCalc denumberize: ((hostAddr & (mask | subnetMask)) + 1)]];
tmpmask = -1;
tmpmask >>= maskBits;
return ([strRange stringByAppendingFormat: @" - %@", [IPSubnetCalc denumberize: ((hostAddr | tmpmask) - 1)]]);
}

- (NSString *)bitMap
{
return ([NSString stringWithCString: bitMap encoding: NSASCIIStringEncoding]);
return ([NSString stringWithCString: bitMap encoding: NSASCIIStringEncoding]);
}

- (NSString *)binMap
Expand All @@ -241,8 +254,8 @@ - (NSString *)binMap
unsigned int address;
unsigned int mask_tmp = 1;
int i;

str_binmap = [[[NSString alloc] init] autorelease];
str_binmap = [[NSString alloc] init];
address = hostAddr;
mask_tmp <<= 31;
for (i = 0; i < 32; i++)
Expand All @@ -251,7 +264,7 @@ - (NSString *)binMap
str_binmap = [str_binmap stringByAppendingString: @"1"];
else
str_binmap = [str_binmap stringByAppendingString: @"0"];
address <<= 1;
address <<= 1;
if (i != 31 && ((i + 1) % 8 == 0))
str_binmap = [str_binmap stringByAppendingString: @"."];
}
Expand All @@ -263,14 +276,14 @@ - (NSString *)hexMap
NSString *str_hexmap;
unsigned int address;
int i;
str_hexmap = [[[NSString alloc] init] autorelease];

str_hexmap = [[NSString alloc] init];
address = hostAddr;
for (i = 0; i < 4; i++)
{
str_hexmap = [str_hexmap stringByAppendingFormat: @"%.2X", ((address << (8 * i)) >> 24)];
if (i != 3)
str_hexmap = [str_hexmap stringByAppendingString: @"."];
str_hexmap = [str_hexmap stringByAppendingString: @"."];
}
return (str_hexmap);
}
Expand Down Expand Up @@ -312,7 +325,7 @@ - (NSString *)netId

- (unsigned int)netIdIntValue
{
return (netId);
return (netId);
}

- (NSString *)subnetMask
Expand All @@ -322,7 +335,7 @@ - (NSString *)subnetMask

- (unsigned int)subnetMaskIntValue
{
return (mask | subnetMask);
return (mask | subnetMask);
}

- (NSString *)subnetBroadcast
Expand All @@ -347,27 +360,36 @@ - (NSString *)networkClass

- (unsigned int)netBits
{
return (netBits);
return (netBits);
}

- (NSString *)supernetRoute:(int)supernetMaskBits
{
unsigned int tmpmask = -1;
unsigned int tmpmask = -1;

tmpmask <<= (32 - supernetMaskBits);
tmpmask <<= (32 - supernetMaskBits);
return ([IPSubnetCalc denumberize: (hostAddr & tmpmask)]);
}

- (NSString *)supernetAddrRange:(int)supernetMaskBits
{
NSString *strRange;
NSString *strRange;
unsigned int tmpmask = -1;

tmpmask <<= (32 - supernetMaskBits);
strRange = [[[NSString alloc] initWithString: [IPSubnetCalc denumberize: (hostAddr & tmpmask)]] autorelease];
tmpmask <<= (32 - supernetMaskBits);
strRange = [[NSString alloc] initWithString: [IPSubnetCalc denumberize: (hostAddr & tmpmask)]];
tmpmask = -1;
tmpmask >>= supernetMaskBits;
return ([strRange stringByAppendingFormat: @" - %@", [IPSubnetCalc denumberize: (hostAddr | tmpmask)]]);
}

- (id)init
{
self = [super init];
if (self) {
[self setClassless: NO];
}
return self;
}

@end
2 changes: 1 addition & 1 deletion License.txt
Original file line number Diff line number Diff line change
Expand Up @@ -277,4 +277,4 @@ YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.

END OF TERMS AND CONDITIONS
END OF TERMS AND CONDITIONS
21 changes: 21 additions & 0 deletions PrintView.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// PrintView.h
// SubnetCalc
//
// Created by Julien Mulot on 02/02/11.
// Copyright 2011 mulot.net. All rights reserved.
//

#import <Cocoa/Cocoa.h>


@interface PrintView : NSView {
NSTableView *subnetsTable;
long entryPerPage; // how many entry per pages
long pages; //how many pages
float rectHeight; //how much vertical space
}

-initWithSubnet:(NSTableView *)table printInfo:(NSPrintInfo *)pi;
- (NSRect)rectForSubnet:(int)index;
@end
Loading

0 comments on commit 9a97e8b

Please sign in to comment.