diff options
author | Andreas Eversberg <jolly@eversberg.eu> | 2010-07-13 13:50:39 +0200 |
---|---|---|
committer | Harald Welte <laforge@gnumonks.org> | 2010-07-13 13:50:39 +0200 |
commit | 33f0fc3c9565308044c934c9e0c1bb81c1a26311 (patch) | |
tree | 695fc928d31b5259df2a08a2c06e43632cce873a /src/vty | |
parent | 6eb7d6c88748a445dde56b697f9faa062658a301 (diff) |
[VTY] add support for numeric ranges with negative numbers
This enables us to do something like <-128-127> as a numeric range.
Diffstat (limited to 'src/vty')
-rw-r--r-- | src/vty/command.c | 98 |
1 files changed, 67 insertions, 31 deletions
diff --git a/src/vty/command.c b/src/vty/command.c index 21afa5c0..598e63cc 100644 --- a/src/vty/command.c +++ b/src/vty/command.c @@ -867,41 +867,77 @@ static int cmd_range_match(const char *range, const char *str) char *p; char buf[DECIMAL_STRLEN_MAX + 1]; char *endptr = NULL; - unsigned long min, max, val; if (str == NULL) return 1; - val = strtoul(str, &endptr, 10); - if (*endptr != '\0') - return 0; - - range++; - p = strchr(range, '-'); - if (p == NULL) - return 0; - if (p - range > DECIMAL_STRLEN_MAX) - return 0; - strncpy(buf, range, p - range); - buf[p - range] = '\0'; - min = strtoul(buf, &endptr, 10); - if (*endptr != '\0') - return 0; - - range = p + 1; - p = strchr(range, '>'); - if (p == NULL) - return 0; - if (p - range > DECIMAL_STRLEN_MAX) - return 0; - strncpy(buf, range, p - range); - buf[p - range] = '\0'; - max = strtoul(buf, &endptr, 10); - if (*endptr != '\0') - return 0; - - if (val < min || val > max) - return 0; + if (range[1] == '-') { + signed long min = 0, max = 0, val; + + val = strtol(str, &endptr, 10); + if (*endptr != '\0') + return 0; + + range += 2; + p = strchr(range, '-'); + if (p == NULL) + return 0; + if (p - range > DECIMAL_STRLEN_MAX) + return 0; + strncpy(buf, range, p - range); + buf[p - range] = '\0'; + min = -strtol(buf, &endptr, 10); + if (*endptr != '\0') + return 0; + + range = p + 1; + p = strchr(range, '>'); + if (p == NULL) + return 0; + if (p - range > DECIMAL_STRLEN_MAX) + return 0; + strncpy(buf, range, p - range); + buf[p - range] = '\0'; + max = strtol(buf, &endptr, 10); + if (*endptr != '\0') + return 0; + + if (val < min || val > max) + return 0; + } else { + unsigned long min, max, val; + + val = strtoul(str, &endptr, 10); + if (*endptr != '\0') + return 0; + + range++; + p = strchr(range, '-'); + if (p == NULL) + return 0; + if (p - range > DECIMAL_STRLEN_MAX) + return 0; + strncpy(buf, range, p - range); + buf[p - range] = '\0'; + min = strtoul(buf, &endptr, 10); + if (*endptr != '\0') + return 0; + + range = p + 1; + p = strchr(range, '>'); + if (p == NULL) + return 0; + if (p - range > DECIMAL_STRLEN_MAX) + return 0; + strncpy(buf, range, p - range); + buf[p - range] = '\0'; + max = strtoul(buf, &endptr, 10); + if (*endptr != '\0') + return 0; + + if (val < min || val > max) + return 0; + } return 1; } |