diff options
author | ru <ru@FreeBSD.org> | 1999-06-11 09:43:53 +0000 |
---|---|---|
committer | ru <ru@FreeBSD.org> | 1999-06-11 09:43:53 +0000 |
commit | 3bb755ec02a13afa062b681129185b3df28ae0a4 (patch) | |
tree | cfaea9dae524940c1215bacd7acffc6d328d09d2 /sbin/ipfw | |
parent | 8c06ac7bd77ba3bb6fa9efe580b673733a0b5c63 (diff) | |
download | FreeBSD-src-3bb755ec02a13afa062b681129185b3df28ae0a4.zip FreeBSD-src-3bb755ec02a13afa062b681129185b3df28ae0a4.tar.gz |
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
Diffstat (limited to 'sbin/ipfw')
-rw-r--r-- | sbin/ipfw/ipfw.c | 35 |
1 files changed, 26 insertions, 9 deletions
diff --git a/sbin/ipfw/ipfw.c b/sbin/ipfw/ipfw.c index 81e8868..86a4eab 100644 --- a/sbin/ipfw/ipfw.c +++ b/sbin/ipfw/ipfw.c @@ -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) |