Fix address mask calculation when using ':' syntax. Allow a mask

of /0 to have the desired effect.  Normalize IP addresses that
won't match a given mask (i.e. 1.2.3.4/24 becomes 1.2.3.0/24).
Submitted by R. Bezuidenhout <rbezuide@mikom.csir.co.za>

Code formatting and "frag" display fixes.
This commit is contained in:
Alexander Langer 1996-06-23 20:47:51 +00:00
parent 356cbcce49
commit c06c129887
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=16643

View File

@ -16,7 +16,7 @@
*
* NEW command line interface for IP firewall facility
*
* $Id: ipfw.c,v 1.25 1996/06/09 23:46:22 alex Exp $
* $Id: ipfw.c,v 1.26 1996/06/18 01:46:34 alex Exp $
*
*/
@ -256,7 +256,7 @@ show_ipfw(chain)
}
if (chain->fw_flg & IP_FW_F_FRAG)
printf("frag ");
printf(" frag ");
if (chain->fw_ipopt || chain->fw_ipnopt) {
int _opt_printed = 0;
@ -408,12 +408,23 @@ fill_ip(ipno, mask, acp, avp)
if (lookup_host(*av,ipno) != 0)
show_usage("ip number\n");
if (md == ':' && !inet_aton(p,mask))
show_usage("ip number\n");
else if (md == '/')
mask->s_addr = htonl(0xffffffff << (32 - atoi(p)));
else
mask->s_addr = htonl(0xffffffff);
switch (md) {
case ':':
if (!inet_aton(p,mask))
show_usage("ip number\n");
break;
case '/':
if (atoi(p) == 0) {
mask->s_addr = 0;
} else {
mask->s_addr = htonl(0xffffffff << (32 - atoi(p)));
}
break;
default:
mask->s_addr = htonl(0xffffffff);
break;
}
ipno->s_addr &= mask->s_addr;
av++;
ac--;
}
@ -788,10 +799,9 @@ ipfw_main(ac,av)
break;
case 'N':
do_resolv=1;
break;
case '?':
default:
show_usage("Unrecognised switch");
break;
default:
show_usage("Unrecognised switch");
}
ac -= optind;
@ -818,7 +828,7 @@ ipfw_main(ac,av)
} else {
show_usage("Bad arguments");
}
return 0;
return 0;
}
int