- nchar= -1;
- sscanf(fnbuf," %u.%u.%u.%u/%u:%u,%u %n",
- &a1,&a2,&a3,&a4,&alen,&pmin,&pmax,&nchar);
- if (nchar != strlen(fnbuf) ||
- alen>32 || pmin&~0x0ffff || pmax&~0x0ffff ||
- a1&~0x0ff || a2&~0xff || a3&~0x0ff || a4&~0x0ff)
- continue;
-
+ unsigned int a1,a2,a3,a4, alen,pmin,pmax;
+ int nchar= -1;
+
+ if (af == AF_INET &&
+ (sscanf(fnbuf," %u.%u.%u.%u/%u: %u,%u %n",
+ &a1,&a2,&a3,&a4,&alen,&pmin,&pmax,&nchar),
+ nchar == strlen(fnbuf))) {
+
+ if (alen>32 || pmin&~0x0ffff || pmax&~0x0ffff ||
+ a1&~0x0ff || a2&~0xff || a3&~0x0ff || a4&~0x0ff)
+ continue;
+
+ unsigned long thaddr, thmask;
+ thaddr= (a1<<24)|(a2<<16)|(a3<<8)|(a4);
+ thmask= 0x0ffffffffUL<<(32-alen);
+ if ((haddr4&thmask) != thaddr) continue;
+
+ } else {
+
+ char *comma = strchr(fnbuf,',');
+ if (comma) continue;
+ *comma++ = '\0';
+
+ char *hyphen = strchr(fnbuf,'-');
+ const char *min, *max;
+ if (hyphen) {
+ *hyphen++ = '\0';
+ min = fnbuf;
+ max = hyphen;
+ } else {
+ min = fnbuf;
+ max = fnbuf;
+ }
+ unsigned char minaddr[addrlen_any];
+ unsigned char maxaddr[addrlen_any];
+ if (inet_pton(af,min,minaddr) != 1 ||
+ inet_pton(af,max,maxaddr) != 1)
+ continue;
+ if (memcmp(addr_any,minaddr,addrlen_any) < 0 ||
+ memcmp(addr_any,maxaddr,addrlen_any) > 0)
+ continue;
+
+ sscanf(comma," %u-%u %n",
+ &pmin,&pmax,&nchar);
+ if (nchar != strlen(comma))
+ continue;
+
+ }