-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsubnetmask.c
64 lines (53 loc) · 1.01 KB
/
subnetmask.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
*Subnet Mask Calculator
*developed by Vahn Cagalawan
*/
#include<stdio.h>
#include<math.h>
int prefix(int host)
{
int ans = 0;
int x=1,y=2;
while(ans==0)
{
if(host >= (pow(2,x)-2) && host <= ((pow(2,y)-2)))
{
ans = 32 - y;
}
else{x++;y++;}
}
return ans;
}
void subnetmask(int x)
{
int ans = 0;
if(x >= 9 && x <=16)
{
ans = 256 - pow(2,(16 - x));
printf("\nSM: 255.%d.0.0",ans);
}
else if(x >= 17 && x <=24)
{
ans = 256 - pow(2,(24 - x));
printf("\nSM: 255.255.%d.0",ans);
}
else if(x >= 25 && x <=32)
{
ans = 256 - pow(2,(32 - x));
printf("\nSM: 255.255.255.%d",ans);
}
}
main()
{
int x, res;
printf("VLSM by v4hn\n");
do{
printf("\nHosts: ");
scanf("%d",&x);
printf("\nPN: /%d", prefix(x));
subnetmask(prefix(x));
printf("\n\nOptions..\n 1 = Restart\n 0 = End\nInput(1/0) = ");
scanf("%d", &res);
}while(res==1);
return 0;
}