- struct subnet s;
- uint32_t a, b, c, d, n;
- uint32_t match;
-
- /* i is not guaranteed to be a string */
- if (i->type!=t_string) {
- cfgfatal(i->loc,desc,"expecting a string (subnet specification)\n");
- }
-
- /* We expect strings of the form "a.b.c.d[/n]", i.e. the dots are
- NOT optional. The subnet mask is optional; if missing it is assumed
- to be /32. */
- match=sscanf(i->data.string,"%u.%u.%u.%u/%u", &a, &b, &c, &d, &n);
- if (match<4) {
- cfgfatal(i->loc,desc,"\"%s\" is not a valid "
- "subnet specification\n",i->data.string);
- }
- if (match<5) {
- n=32;
- }
- if (a>255 || b>255 || c>255 || d>255 || n>32) {
- cfgfatal(i->loc,desc,"\"%s\": range error\n",i->data.string);
- }
- s.prefix=(a<<24)|(b<<16)|(c<<8)|(d);
- s.mask=(~0UL << (32-n));
- s.len=n;
- if (s.prefix & ~s.mask) {
- cfgfatal(i->loc,desc,"\"%s\": prefix not fully contained "
- "in mask\n",i->data.string);
- }
- return s;
-}
-
-uint32_t string_to_ipaddr(item_t *i, string_t desc)
-{
- uint32_t a, b, c, d;
- uint32_t match;
-
- /* i is not guaranteed to be a string */
- if (i->type!=t_string) {
- cfgfatal(i->loc,desc,"expecting a string (IP address)\n");
- }