Initial commit

This commit is contained in:
2014-03-07 10:45:29 +01:00
commit 2d0b19ccf1
4 changed files with 69 additions and 0 deletions
+16
View File
@@ -0,0 +1,16 @@
Copyright (C) 2014 Jack-Benny Persson <jack-benny@cyberinfo.se>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+5
View File
@@ -0,0 +1,5 @@
subnetcalc: subnetcalc.c
gcc subnetcalc.c -lm -o subnetcalc
clean: subnetcalc
rm subnetcalc
+10
View File
@@ -0,0 +1,10 @@
# subnetcalc #
A very simple subnet calculator written in C. It's nothing fancy at all,
just a small project of mine to get going with C.
Simply build it (make), run it (./subnetcalc) and enter the subnet
mask in slash notation but without the slash.
For example enter 24 for a 24-bit subnet mask and the
program will output the total number of addresses in the range aswell
as the total number of usable address for hosts.
+38
View File
@@ -0,0 +1,38 @@
/* A very simple subnet calculator in C, written by
* Jack-Benny Persson (jack-benny@cyberinfo.se).
* Released under GNU GPLv2.
*/
#include <stdio.h>
#include <math.h>
main()
{
int net;
double hosts;
double addr;
printf("Enter netmask in slash-notation without the slash: ");
scanf("%d", &net);
if (net >= 0 && net <= 32) // Sanity check the user input
{
printf("Netmask bit: %d\n\n", net);
addr = pow(2, 32-net); // Calculate number of addresses
printf("%.0lf total addresses\n", addr);
hosts = addr-2;
if (hosts < 0) // Check if number of usable hosts is a negative value
{
hosts = 0; // Set usable hosts to zero if it was negative
}
printf("%.0lf usable addresses for hosts\n", hosts);
return 0;
}
else // If the user entered anything else than 0-32
{
printf("Only values between 0-32 are accepted\n");
return 1;
}
return 1;
}