mirror of
https://git.FreeBSD.org/src.git
synced 2024-12-02 08:42:48 +00:00
Workaround the problem that the first (and only first) port name
can't have a dash character (it is treated as a ``range'' operator). One could now use such a name by escaping the ``-'' characters. For example: # ipfw add 1 count tcp from any to any "ms\-sql\-s" # ipfw add 2 count tcp from any ftp\\-data-ftp to any PR: 7101
This commit is contained in:
parent
eb90c9c86a
commit
0a81860b0b
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=47874
@ -20,9 +20,9 @@
|
||||
|
||||
#ifndef lint
|
||||
static const char rcsid[] =
|
||||
"$Id: ipfw.c,v 1.68 1999/06/02 05:59:48 ru Exp $";
|
||||
"$Id: ipfw.c,v 1.69 1999/06/04 11:20:59 ru Exp $";
|
||||
#endif /* not lint */
|
||||
|
||||
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
@ -708,9 +708,21 @@ lookup_port(const char *arg, int test, int nodash)
|
||||
int val;
|
||||
char *earg, buf[32];
|
||||
struct servent *s;
|
||||
char *p, *q;
|
||||
|
||||
snprintf(buf, sizeof(buf), "%s", arg);
|
||||
buf[strcspn(arg, nodash ? "-," : ",")] = 0;
|
||||
|
||||
for (p = q = buf; *p; *q++ = *p++) {
|
||||
if (*p == '\\') {
|
||||
if (*(p+1))
|
||||
p++;
|
||||
} else {
|
||||
if (*p == ',' || (nodash && *p == '-'))
|
||||
break;
|
||||
}
|
||||
}
|
||||
*q = '\0';
|
||||
|
||||
val = (int) strtoul(buf, &earg, 0);
|
||||
if (!*buf || *earg) {
|
||||
setservent(1);
|
||||
@ -718,14 +730,14 @@ lookup_port(const char *arg, int test, int nodash)
|
||||
val = htons(s->s_port);
|
||||
} else {
|
||||
if (!test) {
|
||||
errx(EX_DATAERR, "unknown port ``%s''", arg);
|
||||
errx(EX_DATAERR, "unknown port ``%s''", buf);
|
||||
}
|
||||
val = -1;
|
||||
}
|
||||
} else {
|
||||
if (val < 0 || val > 0xffff) {
|
||||
if (!test) {
|
||||
errx(EX_DATAERR, "port ``%s'' out of range", arg);
|
||||
errx(EX_DATAERR, "port ``%s'' out of range", buf);
|
||||
}
|
||||
val = -1;
|
||||
}
|
||||
@ -741,7 +753,10 @@ fill_port(cnt, ptr, off, arg)
|
||||
char *s;
|
||||
int initial_range = 0;
|
||||
|
||||
s = arg + strcspn(arg, "-,"); /* first port name can't have a dash */
|
||||
for (s = arg; *s && *s != ',' && *s != '-'; s++) {
|
||||
if (*s == '\\' && *(s+1))
|
||||
s++;
|
||||
}
|
||||
if (*s == '-') {
|
||||
*s++ = '\0';
|
||||
if (strchr(arg, ','))
|
||||
@ -1092,9 +1107,11 @@ add(ac,av)
|
||||
if(pp != NULL)
|
||||
{
|
||||
*(pp++) = '\0';
|
||||
rule.fw_fwd_ip.sin_port = lookup_port(pp, 1, 1);
|
||||
if(rule.fw_fwd_ip.sin_port == (unsigned int)-1)
|
||||
show_usage("illegal forwarding port");
|
||||
i = lookup_port(pp, 1, 0);
|
||||
if (i == -1)
|
||||
show_usage("illegal forwarding port ``%s''", pp);
|
||||
else
|
||||
rule.fw_fwd_ip.sin_port = (u_short)i;
|
||||
}
|
||||
fill_ip(&(rule.fw_fwd_ip.sin_addr), &dummyip, &ac, &av);
|
||||
if (rule.fw_fwd_ip.sin_addr.s_addr == 0)
|
||||
|
Loading…
Reference in New Issue
Block a user