From 0a81860b0b45bf4a280cd9df83ed5913f748f418 Mon Sep 17 00:00:00 2001 From: Ruslan Ermilov Date: Fri, 11 Jun 1999 09:43:53 +0000 Subject: [PATCH] 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 --- sbin/ipfw/ipfw.c | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/sbin/ipfw/ipfw.c b/sbin/ipfw/ipfw.c index 81e8868b2f60..86a4eab21ef7 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 #include @@ -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)