return msg;
}
+byte *
+cf_parse_ip(byte **p, u32 *varp)
+{
+ while (Cspace(**p))
+ (*p)++;
+ if (!**p)
+ return "Missing IP address";
+ uns x = 0;
+ if (**p == '0' && *(*p + 1) | 32 == 'X')
+ {
+ errno = 0;
+ x = strtoul(*p + 2, (char **)p, 16);
+ if (errno == ERANGE || x > 0xffffffff)
+ goto error;
+ }
+ else
+ for (uns i = 0; i < 4; i++)
+ {
+ if (i)
+ {
+ while (Cspace(**p))
+ (*p)++;
+ if (*(*p)++ != '.')
+ goto error;
+ }
+ while (Cspace(**p))
+ (*p)++;
+ errno = 0;
+ uns y = strtoul(*p, (char **)p, 10);
+ if (errno == ERANGE || y > 255)
+ goto error;
+ x = (x << 8) + y;
+ }
+ *varp = x;
+ return NULL;
+error:
+ return "Invalid IP address";
+}
+
byte *cf_set_item(byte *sect, byte *name, byte *value)
{
struct cfitem *item;
byte *cf_parse_u64(byte *value, u64 *varp);
byte *cf_parse_double(byte *value, double *varp);
+/*
+ * Some useful parsing functions.
+ */
+
+byte *cf_parse_ip(byte **value, u32 *varp);
+
/*
* When using cf_getopt, you must prefix your own short/long options by the
* CF_(SHORT|LONG)_OPTS.
return l;
}
-static byte *
-parse_ip(byte *x, u32 *a)
-{
- uns i, q;
- u32 z = 0;
-
- for(i=0; i<4; i++)
- {
- q = 0;
- while (Cdigit(*x))
- {
- q = q*10 + *x++ - '0';
- if (q > 255)
- return "Invalid IP address";
- }
- if (*x++ != ((i == 3) ? 0 : '.'))
- return "Invalid IP address";
- z = (z << 8) | q;
- }
- *a = z;
- return NULL;
-}
-
byte *
ipaccess_parse(struct ipaccess_list *l, byte *c, int is_allow)
{
- char *p = strchr(c, '/');
+ byte *p = strchr(c, '/');
char *q;
struct ipaccess_entry *a = cfg_malloc(sizeof(struct ipaccess_entry));
unsigned long pxlen;
if (pxlen != 32)
a->mask = ~(~0U >> (uns) pxlen);
}
- else if (q = parse_ip(p, &a->mask))
+ else if (q = cf_parse_ip(&p, &a->mask))
return q;
}
add_tail(&l->l, &a->n);
- return parse_ip(c, &a->addr);
+ return cf_parse_ip(&c, &a->addr);
}
int