diff --git a/Makefile b/Makefile index e42377f..a9b3531 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,6 @@ subnetcalc: subnetcalc.c - gcc -Wall -pedantic subnetcalc.c -lm -static -o subnetcalc + gcc -std=c99 -Wall -pedantic subnetcalc.c -lm -static -o subnetcalc docker build . -t subnetcalc clean: subnetcalc rm subnetcalc - docker image rm subnetcalc diff --git a/subnetcalc b/subnetcalc index 80a20ad..6c8d5e7 100755 Binary files a/subnetcalc and b/subnetcalc differ diff --git a/subnetcalc.c b/subnetcalc.c index 68135c9..61623cc 100644 --- a/subnetcalc.c +++ b/subnetcalc.c @@ -9,26 +9,26 @@ int main(void) { int net; - double hosts; - double addr; + long int hosts, addr; printf("Enter netmask in slash-notation without the slash: "); scanf("%2d", &net); - if (net >= 0 && net <= 32) // Sanity check the user input + 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); + addr = pow(2, 32-net); /* Calculate number of addresses */ + printf("%ld total addresses\n", addr); - hosts = addr-2; - if (hosts < 0) // Check if number of usable hosts is a negative value + hosts = addr-2; + /* Check if number of usable hosts is a negative value */ + if (hosts < 0) { - hosts = 0; // Set usable hosts to zero if it was negative + hosts = 0; /* Set usable hosts to zero if it was negative */ } - printf("%.0lf usable addresses for hosts\n", hosts); + printf("%ld usable addresses for hosts\n", hosts); return 0; } - else // If the user entered anything else than 0-32 + else /* If the user entered anything else than 0-32 */ { printf("Only values between 0-32 are accepted\n"); return 1;