static u_int8_t
parse_level(const char *level)
{
- int lev;
+ unsigned int lev;
- lev = string_to_number(level, 0, 7);
- if (lev == -1) {
+ if (string_to_number(level, 0, 7, lev) == -1) {
unsigned int i = 0;
for (i = 0;
} else {
char *slash;
char buffer[strlen(icmpv6type) + 1];
- int number;
+ unsigned int number;
strcpy(buffer, icmpv6type);
slash = strchr(buffer, '/');
if (slash)
*slash = '\0';
- number = string_to_number(buffer, 0, 255);
- if (number == -1)
+ if (string_to_number(buffer, 0, 255, &number) == -1)
exit_error(PARAMETER_PROBLEM,
"Invalid ICMPv6 type `%s'\n", buffer);
*type = number;
if (slash) {
- number = string_to_number(slash+1, 0, 255);
- if (number == -1)
+ if (string_to_number(slash+1, 0, 255, &number) == -1)
exit_error(PARAMETER_PROBLEM,
"Invalid ICMPv6 code `%s'\n",
slash+1);
struct ip6t_entry_match **match)
{
struct ip6t_rateinfo *r = (struct ip6t_rateinfo *)(*match)->data;
- int num;
+ unsigned int num;
switch(c) {
case '%':
exit_error(PARAMETER_PROBLEM,
"Unexpected `!' after --limit-burst");
- num = string_to_number(optarg, 0, 10000);
- if (num <= 0)
+ if (string_to_number(optarg, 0, 10000, &num) <= 0)
exit_error(PARAMETER_PROBLEM,
"bad --limit-burst `%s'", optarg);
r->burst = num;
static u_int16_t
parse_port(const char *port, const char *proto)
{
- int portnum;
- if ((portnum = string_to_number(port, 0, 65535)) != -1 ||
+ unsigned int portnum;
+
+ if ((string_to_number(port, 0, 65535, &portnum)) != -1 ||
(portnum = service_to_port(port, proto)) != -1)
return (u_int16_t)portnum;
static u_int16_t
parse_tcp_port(const char *port)
{
- int portnum;
+ unsigned int portnum;
- if ((portnum = string_to_number(port, 0, 65535)) != -1 ||
+ if (string_to_number(port, 0, 65535, &portnum) != -1 ||
(portnum = service_to_port(port)) != -1)
return (u_int16_t)portnum;
static void
parse_tcp_option(const char *option, u_int8_t *result)
{
- int ret;
+ unsigned int ret;
- ret = string_to_number(option, 1, 255);
- if (ret == -1)
+ if (string_to_number(option, 1, 266, &ret) == -1)
exit_error(PARAMETER_PROBLEM, "Bad TCP option `%s'", option);
*result = (u_int8_t)ret;
static u_int16_t
parse_udp_port(const char *port)
{
- int portnum;
+ unsigned int portnum;
- if ((portnum = string_to_number(port, 0, 65535)) != -1 ||
+ if (string_to_number(port, 0, 65535, &portnum) != -1 ||
(portnum = service_to_port(port)) != -1)
return (u_int16_t)portnum;
static void
parse_ftos(const unsigned char *s, struct ipt_FTOS_info *finfo)
{
- int ftos = string_to_number(s, 0, 255);
+ unsigned int ftos;
+
+ string_to_number(s, 0, 255, &ftos);
finfo->ftos = (u_int8_t )ftos;
return;
}
static u_int8_t
parse_level(const char *level)
{
- int lev;
+ unsigned int lev;
- lev = string_to_number(level, 0, 7);
- if (lev == -1) {
+ if (string_to_number(level, 0, 7, &lev) == -1) {
unsigned int i = 0;
for (i = 0;
char *slash;
struct in_addr *ip;
u_int32_t netmask;
- int bits;
+ unsigned int bits;
range->flags |= IP_NAT_RANGE_MAP_IPS;
slash = strchr(arg, '/');
netmask = ip->s_addr;
}
else {
- if ((bits = string_to_number(slash+1, 0, 32)) == -1)
+ if (string_to_number(slash+1, 0, 32, &bits) == -1)
exit_error(PARAMETER_PROBLEM, "Bad netmask `%s'\n",
slash+1);
netmask = bits2netmask(bits);
= (struct ipt_tcpmss_info *)(*target)->data;
switch (c) {
- int mssval;
+ unsigned int mssval;
case '1':
if (*flags)
exit_error(PARAMETER_PROBLEM,
"TCPMSS target: Only one option may be specified");
- if ((mssval = string_to_number(optarg, 0, 65535 - 40)) == -1)
+ if (string_to_number(optarg, 0, 65535 - 40, &mssval) == -1)
exit_error(PARAMETER_PROBLEM, "Bad TCPMSS value `%s'", optarg);
mssinfo->mss = mssval;
static void
parse_tos(const unsigned char *s, struct ipt_tos_target_info *info)
{
- unsigned int i;
- int tos = string_to_number(s, 0, 255);
+ unsigned int i, tos;
- if (tos != -1) {
+ if (string_to_number(s, 0, 255,tos) != -1) {
if (tos == IPTOS_LOWDELAY
|| tos == IPTOS_THROUGHPUT
|| tos == IPTOS_RELIABILITY
} else {
char *slash;
char buffer[strlen(icmptype) + 1];
- int number;
+ unsigned int number;
strcpy(buffer, icmptype);
slash = strchr(buffer, '/');
if (slash)
*slash = '\0';
- number = string_to_number(buffer, 0, 255);
- if (number == -1)
+ if (string_to_number(buffer, 0, 255, &number) == -1)
exit_error(PARAMETER_PROBLEM,
"Invalid ICMP type `%s'\n", buffer);
*type = number;
if (slash) {
- number = string_to_number(slash+1, 0, 255);
- if (number == -1)
+ if (string_to_number(slash+1, 0, 255, &number) == -1)
exit_error(PARAMETER_PROBLEM,
"Invalid ICMP code `%s'\n",
slash+1);
static u_int16_t
parse_length(const char *s)
{
- int len;
+ unsigned int len;
- len = string_to_number(s, 0, 0xFFFF);
-
- if (len == -1)
+ if (string_to_number(s, 0, 0xFFFF, &len) == -1)
exit_error(PARAMETER_PROBLEM, "length invalid: `%s'\n", s);
else
return (u_int16_t )len;
struct ipt_entry_match **match)
{
struct ipt_rateinfo *r = (struct ipt_rateinfo *)(*match)->data;
- int num;
+ unsigned int num;
switch(c) {
case '%':
exit_error(PARAMETER_PROBLEM,
"Unexpected `!' after --limit-burst");
- num = string_to_number(optarg, 0, 10000);
- if (num <= 0)
+ if (string_to_number(optarg, 0, 10000, &num) <= 0)
exit_error(PARAMETER_PROBLEM,
"bad --limit-burst `%s'", optarg);
r->burst = num;
static u_int16_t
parse_port(const char *port, const char *proto)
{
- int portnum;
- if ((portnum = string_to_number(port, 0, 65535)) != -1 ||
+ unsigned int portnum;
+
+ if (portnum = string_to_number(port, 0, 65535, &portnum) != -1 ||
(portnum = service_to_port(port, proto)) != -1)
return (u_int16_t)portnum;
static u_int16_t
parse_port(const char *port, const char *proto)
{
- int portnum;
- if ((portnum = string_to_number(port, 0, 65535)) != -1 ||
+ unsigned int portnum;
+
+ if (string_to_number(port, 0, 65535, &portnum) != -1 ||
(portnum = service_to_port(port, proto)) != -1)
return (u_int16_t)portnum;
struct ipt_entry_match **match)
{
struct ipt_nth_info *nthinfo = (struct ipt_nth_info *)(*match)->data;
- int num;
+ unsigned int num;
switch (c) {
case '1':
/* Remember, this function will interpret a leading 0 to be
Octal, a leading 0x to be hexdecimal... */
- num = string_to_number(optarg, 2, 100);
- if (num < 2)
+ if (string_to_number(optarg, 2, 100, &num) == -1 || num < 2)
exit_error(PARAMETER_PROBLEM,
"bad --every `%s', must be between 2 and 100", optarg);
if (*flags & IPT_NTH_OPT_START)
exit_error(PARAMETER_PROBLEM,
"Can't specify --start twice");
- num = string_to_number(optarg, 0, nthinfo->every);
- if (num < 0)
+ if (string_to_number(optarg, 0, nthinfo->every, &num) == -1)
exit_error(PARAMETER_PROBLEM,
"bad --start `%s', must between 0 and %u", optarg, nthinfo->every);
*flags |= IPT_NTH_OPT_START;
struct ipt_entry_match **match)
{
struct ipt_psd_info *psdinfo = (struct ipt_psd_info *)(*match)->data;
- int num;
+ unsigned int num;
switch (c) {
/* PSD-weight-threshold */
exit_error(PARAMETER_PROBLEM,
"Can't specify --psd-weight-threshold "
"twice");
- num = string_to_number(optarg, 0, 10000);
- if (num <= 0)
+ if (string_to_number(optarg, 0, 10000, &num) == -1)
exit_error(PARAMETER_PROBLEM,
"bad --psd-weight-threshold `%s'", optarg);
psdinfo->weight_threshold = num;
if (*flags & IPT_PSD_OPT_DTRESH)
exit_error(PARAMETER_PROBLEM,
"Can't specify --psd-delay-threshold twice");
- num = string_to_number(optarg, 0, 10000);
- if (num <= 0)
+ if (string_to_number(optarg, 0, 10000, &num) == -1)
exit_error(PARAMETER_PROBLEM,
"bad --psd-delay-threshold `%s'", optarg);
psdinfo->delay_threshold = num;
if (*flags & IPT_PSD_OPT_LPWEIGHT)
exit_error(PARAMETER_PROBLEM,
"Can't specify --psd-lo-ports-weight twice");
- num = string_to_number(optarg, 0, 10000);
- if (num <= 0)
+ if (string_to_number(optarg, 0, 10000, &num) == -1)
exit_error(PARAMETER_PROBLEM,
"bad --psd-lo-ports-weight `%s'", optarg);
psdinfo->lo_ports_weight = num;
if (*flags & IPT_PSD_OPT_HPWEIGHT)
exit_error(PARAMETER_PROBLEM,
"Can't specify --psd-hi-ports-weight twice");
- num = string_to_number(optarg, 0, 10000);
- if (num <= 0)
+ if (string_to_number(optarg, 0, 10000, &num) == -1)
exit_error(PARAMETER_PROBLEM,
"bad --psd-hi-ports-weight `%s'", optarg);
psdinfo->hi_ports_weight = num;
static u_int16_t
parse_tcp_port(const char *port)
{
- int portnum;
+ unsigned int portnum;
- if ((portnum = string_to_number(port, 0, 65535)) != -1 ||
+ if (string_to_number(port, 0, 65535, &portnum) != -1 ||
(portnum = service_to_port(port)) != -1)
return (u_int16_t)portnum;
static void
parse_tcp_option(const char *option, u_int8_t *result)
{
- int ret;
+ unsigned int ret;
- ret = string_to_number(option, 1, 255);
- if (ret == -1)
+ if (string_to_number(option, 1, 255, &ret) == -1)
exit_error(PARAMETER_PROBLEM, "Bad TCP option `%s'", option);
*result = (u_int8_t)ret;
static u_int16_t
parse_tcp_mssvalue(const char *mssvalue)
{
- int mssvaluenum;
+ unsigned int mssvaluenum;
- if ((mssvaluenum = string_to_number(mssvalue, 0, 65535)) != -1)
+ if (string_to_number(mssvalue, 0, 65535, &mssvaluenum) != -1)
return (u_int16_t)mssvaluenum;
exit_error(PARAMETER_PROBLEM,
}
static void
-parse_time_string(int *hour, int *minute, const char *time)
+parse_time_string(unsigned int *hour, unsigned int *minute, const char *time)
{
char *hours;
char *minutes;
hours[0] = ' ';
if (minutes[0] == '0')
minutes[0] = ' ';
- *hour = string_to_number(hours, 0, 23);
- *minute = string_to_number(minutes, 0, 59);
+
+ /* FIXME: error checking */
+ string_to_number(hours, 0, 23, hour);
+ string_to_number(minutes, 0, 59, minute);
}
if ((*hour != (-1)) && (*minute != (-1))) {
free(hours);
parse_tos(const unsigned char *s, struct ipt_tos_info *info)
{
unsigned int i;
- int tos = string_to_number(s, 0, 255);
+ unsigned int tos;
- if (tos != -1) {
+ if (string_to_number(s, 0, 255, &tos) != -1) {
if (tos == IPTOS_LOWDELAY
|| tos == IPTOS_THROUGHPUT
|| tos == IPTOS_RELIABILITY
static u_int16_t
parse_udp_port(const char *port)
{
- int portnum;
+ unsigned int portnum;
- if ((portnum = string_to_number(port, 0, 65535)) != -1 ||
+ if (string_to_number(port, 0, 65535, &portnum) != -1 ||
(portnum = service_to_port(port)) != -1)
return (u_int16_t)portnum;