Deleted Added
full compact
main.c (228871) main.c (229403)
1/*
2 * Copyright (c) 2002-2003,2010 Luigi Rizzo
3 * Copyright (c) 1996 Alex Nash, Paul Traina, Poul-Henning Kamp
4 * Copyright (c) 1994 Ugen J.S.Antsilevich
5 *
6 * Idea and grammar partially left from:
7 * Copyright (c) 1993 Daniel Boulet
8 *
9 * Redistribution and use in source forms, with and without modification,
10 * are permitted provided that this entire comment appears intact.
11 *
12 * Redistribution in binary form may occur without any restrictions.
13 * Obviously, it would be nice if you gave credit where credit is due
14 * but requiring it would be too onerous.
15 *
16 * This software is provided ``AS IS'' without any warranties of any kind.
17 *
18 * Command line interface for IP firewall facility
19 *
1/*
2 * Copyright (c) 2002-2003,2010 Luigi Rizzo
3 * Copyright (c) 1996 Alex Nash, Paul Traina, Poul-Henning Kamp
4 * Copyright (c) 1994 Ugen J.S.Antsilevich
5 *
6 * Idea and grammar partially left from:
7 * Copyright (c) 1993 Daniel Boulet
8 *
9 * Redistribution and use in source forms, with and without modification,
10 * are permitted provided that this entire comment appears intact.
11 *
12 * Redistribution in binary form may occur without any restrictions.
13 * Obviously, it would be nice if you gave credit where credit is due
14 * but requiring it would be too onerous.
15 *
16 * This software is provided ``AS IS'' without any warranties of any kind.
17 *
18 * Command line interface for IP firewall facility
19 *
20 * $FreeBSD: head/sbin/ipfw/main.c 228871 2011-12-24 22:37:27Z eadler $
20 * $FreeBSD: head/sbin/ipfw/main.c 229403 2012-01-03 18:51:58Z ed $
21 */
22
23#include <sys/wait.h>
24#include <ctype.h>
25#include <err.h>
26#include <errno.h>
27#include <signal.h>
28#include <stdio.h>

--- 88 unchanged lines hidden (view full) ---

117 int copy = 0; /* 1 if we need to copy, 0 otherwise */
118 int i, j;
119
120 for (i = j = 0; i < l; i++) {
121 if (arg[i] == '#') /* comment marker */
122 break;
123 if (copy) {
124 arg[j++] = arg[i];
21 */
22
23#include <sys/wait.h>
24#include <ctype.h>
25#include <err.h>
26#include <errno.h>
27#include <signal.h>
28#include <stdio.h>

--- 88 unchanged lines hidden (view full) ---

117 int copy = 0; /* 1 if we need to copy, 0 otherwise */
118 int i, j;
119
120 for (i = j = 0; i < l; i++) {
121 if (arg[i] == '#') /* comment marker */
122 break;
123 if (copy) {
124 arg[j++] = arg[i];
125 copy = !index("," WHITESP, arg[i]);
125 copy = !strchr("," WHITESP, arg[i]);
126 } else {
126 } else {
127 copy = !index(WHITESP, arg[i]);
127 copy = !strchr(WHITESP, arg[i]);
128 if (copy)
129 arg[j++] = arg[i];
130 }
131 }
132 if (!copy && j > 0) /* last char was a 'blank', remove it */
133 j--;
134 l = j; /* the new argument length */
135 arg[j++] = '\0';
136 if (l == 0) /* empty string! */
137 return 1;
138
139 /*
140 * First, count number of arguments. Because of the previous
141 * processing, this is just the number of blanks plus 1.
142 */
143 for (i = 0, ac = 1; i < l; i++)
128 if (copy)
129 arg[j++] = arg[i];
130 }
131 }
132 if (!copy && j > 0) /* last char was a 'blank', remove it */
133 j--;
134 l = j; /* the new argument length */
135 arg[j++] = '\0';
136 if (l == 0) /* empty string! */
137 return 1;
138
139 /*
140 * First, count number of arguments. Because of the previous
141 * processing, this is just the number of blanks plus 1.
142 */
143 for (i = 0, ac = 1; i < l; i++)
144 if (index(WHITESP, arg[i]) != NULL)
144 if (strchr(WHITESP, arg[i]) != NULL)
145 ac++;
146
147 /*
148 * Allocate the argument list structure as a single block
149 * of memory, containing pointers and the argument
150 * strings. We include one entry for the program name
151 * because getopt expects it, and a NULL at the end
152 * to simplify further parsing.

--- 4 unchanged lines hidden (view full) ---

157
158 /*
159 * Init the argument pointer to the end of the array
160 * and copy arguments from arg[] to av[]. For each one,
161 * j is the initial character, i is the one past the end.
162 */
163 av_p = (char *)&av[ac+1];
164 for (ac = 1, i = j = 0; i < l; i++) {
145 ac++;
146
147 /*
148 * Allocate the argument list structure as a single block
149 * of memory, containing pointers and the argument
150 * strings. We include one entry for the program name
151 * because getopt expects it, and a NULL at the end
152 * to simplify further parsing.

--- 4 unchanged lines hidden (view full) ---

157
158 /*
159 * Init the argument pointer to the end of the array
160 * and copy arguments from arg[] to av[]. For each one,
161 * j is the initial character, i is the one past the end.
162 */
163 av_p = (char *)&av[ac+1];
164 for (ac = 1, i = j = 0; i < l; i++) {
165 if (index(WHITESP, arg[i]) != NULL || i == l-1) {
165 if (strchr(WHITESP, arg[i]) != NULL || i == l-1) {
166 if (i == l-1)
167 i++;
168 bcopy(arg+j, av_p, i-j);
169 av[ac] = av_p;
170 av_p += i-j; /* the lenght of the string */
171 *av_p++ = '\0';
172 ac++;
173 j = i + 1;

--- 61 unchanged lines hidden (view full) ---

235 int i;
236
237 if (ac != 3) {
238 printf( "sysctl emulation usage:\n"
239 " ipfw sysctl name[=value]\n"
240 " ipfw sysctl -a\n");
241 return 0;
242 }
166 if (i == l-1)
167 i++;
168 bcopy(arg+j, av_p, i-j);
169 av[ac] = av_p;
170 av_p += i-j; /* the lenght of the string */
171 *av_p++ = '\0';
172 ac++;
173 j = i + 1;

--- 61 unchanged lines hidden (view full) ---

235 int i;
236
237 if (ac != 3) {
238 printf( "sysctl emulation usage:\n"
239 " ipfw sysctl name[=value]\n"
240 " ipfw sysctl -a\n");
241 return 0;
242 }
243 s = index(av[2], '=');
243 s = strchr(av[2], '=');
244 if (s == NULL) {
245 s = !strcmp(av[2], "-a") ? NULL : av[2];
246 sysctlbyname(s, NULL, NULL, NULL, 0);
247 } else { /* ipfw sysctl x.y.z=value */
248 /* assume an INT value, will extend later */
249 if (s[1] == '\0') {
250 printf("ipfw sysctl: missing value\n\n");
251 return 0;

--- 373 unchanged lines hidden ---
244 if (s == NULL) {
245 s = !strcmp(av[2], "-a") ? NULL : av[2];
246 sysctlbyname(s, NULL, NULL, NULL, 0);
247 } else { /* ipfw sysctl x.y.z=value */
248 /* assume an INT value, will extend later */
249 if (s[1] == '\0') {
250 printf("ipfw sysctl: missing value\n\n");
251 return 0;

--- 373 unchanged lines hidden ---