/*
- * Sherlock Library -- IP address access lists
+ * UCW Library -- IP address access lists
*
* (c) 1997--2001 Martin Mares <mj@ucw.cz>
*
#include "lib/ipaccess.h"
#include <string.h>
+#include <stdlib.h>
struct ipaccess_list {
list l;
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)
{
byte *p = strchr(c, '/');
- byte *q;
+ char *q;
struct ipaccess_entry *a = cfg_malloc(sizeof(struct ipaccess_entry));
+ unsigned long pxlen;
a->allow = is_allow;
+ a->mask = ~0U;
if (p)
{
*p++ = 0;
- if (q = parse_ip(p, &a->mask))
+ pxlen = strtoul(p, &q, 10);
+ if ((!q || !*q) && pxlen <= 32)
+ {
+ if (pxlen != 32)
+ a->mask = ~(~0U >> (uns) pxlen);
+ }
+ else if (q = cf_parse_ip(&p, &a->mask))
return q;
}
- else
- a->mask = ~0;
add_tail(&l->l, &a->n);
- return parse_ip(c, &a->addr);
+ return cf_parse_ip(&c, &a->addr);
}
int