I find the little C program included at the end useful.
Sam
> From firewalls-owner @
GreatCircle .
COM Mon Sep 30 22:03 PDT 1996
> X-Sender: pferguso @
lint .
cisco .
com
> Mime-Version: 1.0
> Date: Tue, 01 Oct 1996 00:29:49 -0400
> To: "Charles_Ragan @
ins .
com" <Charles_Ragan @
INS .
COM>
> From: Paul Ferguson <pferguso @
cisco .
com>
> Subject: Re: Subnetting Class C Network
> Cc: "Harry Feltsadas" <harry @
ns .
fdc .
nl>,
> jfjohnm @
ca-online .
com (John McColley @ J F Engineering),
> firewalls @
GreatCircle .
COM
>
> Also, it goes without saying that classful routing protocols have outlived
> their usefulness, and should be abandoned at one's earliest convenience.
>
> In fact, RIPv1 has been declared historical (or, rather, hysterical).
>
> - paul
>
> At 08:53 PM 9/30/96 -0500, Charles_Ragan @
ins .
com wrote:
>
> >One other note, rfc 1878's recommendation allows for the usage of the first
> >and last subnet. Routing protocols that carry subnet information in its
> >updates allow for this. Ones that don't (igrp, static, ripv1, etc.). The
> >practice I follow is to use them last, if needed.
> >
> >Charles
> >
>
> --
> Paul Ferguson || ||
> Consulting Engineering || ||
> Reston, Virginia USA |||| ||||
> tel: +1.703.716.9538 ..:||||||:..:||||||:..
> e-mail: pferguso @
cisco .
com c i s c o S y s t e m s
>
>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <ctype.h>
#define A 1
#define B 2
#define C 3
/* NOTE: Only class C is currently supported
*/
void dump_class_C(int b1, int b2, int b3, int b4, int sb)
{
int s, h, sd, hd;
sd = 2;
for (s = 1; s < sb; s++)
sd *= 2;
hd = 2;
for (h = 1; h < (8 - sb); h++)
hd *= 2;
printf("Network: %d.%d.%d.%d/%d\n", b1, b2, b3, b4, 24 + sb);
printf("Netmask: %d.%d.%d.%d\n", 255, 255, 255, (sd - 1) << (8 - sb));
for (s = 1; s < sd - 1; s++)
{
printf("\fSubnet: %d", s);
printf("\nNetwork: %d.%d.%d.%d/%d", b1, b2, b3, s << (8 - sb), 24 + sb);
printf("\nBroadcast: %d.%d.%d.%d\n\n", b1, b2, b3, (s << (8 - sb)) + (hd - 1));
for (h = 1; h < hd - 1; h++)
{
printf(" %d.%d.%d.%d\n", b1, b2, b3, (s << (8 - sb)) + h);
}
}
}
int main(int argc, char *argv[])
{
char address[256], *cp;
int class, sb, b1, b2, b3, b4;
if (argc != 3)
{
printf("Usage: subnet address subnet_bits\n\n");
printf("Example: subnet 197.34.16.0 3\n");
return 1;
}
strcpy(address, argv[1]);
cp = address;
b1 = atoi(cp);
while (isdigit(*cp))
++cp;
if (*cp == '.')
++cp;
else
{
printf("Bad address: %s\n", argv[1]);
return 1;
}
b2 = atoi(cp);
while (isdigit(*cp))
++cp;
if (*cp == '.')
++cp;
else
{
printf("Bad address: %s\n", argv[1]);
return 1;
}
b3 = atoi(cp);
while (isdigit(*cp))
++cp;
if (*cp == '.')
++cp;
else
{
printf("Bad address: %s\n", argv[1]);
return 1;
}
b4 = atoi(cp);
sb = atoi(argv[2]);
if (b1 < 128)
class = A;
else if (b1 < 192)
class = B;
else if (b1 < 224)
class = C;
else
{
printf("Bad address (class out of range): %s\n", argv[1]);
return 1;
}
switch (class)
{
case A:
if (sb > 24)
{
printf("Too many subnet bits\n");
return 1;
}
break;
case B:
if (sb > 16)
{
printf("Too many subnet bits\n");
return 1;
}
break;
case C:
if (sb > 8)
{
printf("Too many subnet bits\n");
return 1;
}
dump_class_C(b1, b2, b3, b4, sb);
break;
}
return 0;
}
|
|