- for ($i = 0 ; $i < count($this->ipcl) ; $i++) {
- if ($this->ipcl[$i]->match($ip)) {
- fprintf(STDERR, "ban_list[%d] = %x (%x) MATCH\n", $i,
- $this->ipcl[$i]->addr, $this->ipcl[$i]->mask);
+ if (count($this->ipcl) == 0) {
+ return (FALSE);
+ }
+
+ if ($ip < $this->ipcl[0]->addr)
+ return (FALSE);
+
+ $imin = 0;
+ $imax = count($this->ipcl) - 1;
+
+ while ($imax >= $imin) {
+ $imid = intval($imin + (($imax - $imin) / 2));
+ // printf("X: %d M: %d N: %d | ", $arr[$imin], $arr[$imid], $arr[$imax]);
+ if ($this->ipcl[$imid]->addr == $ip) {
+ break;
+ }
+ else if ($this->ipcl[$imid]->addr > $ip) {
+ $imax = $imid - 1;
+ }
+ else {
+ $imin = $imid + 1;
+ }
+ }
+ if ($this->ipcl[$imid]->addr > $ip) {
+ if ($imid > 0) {
+ $imid--;
+ }
+ else {
+ $imid = -1;
+ }
+ }
+
+ if ($imid > -1) {
+ if ($this->ipcl[$imid]->match($ip)) {
+ fprintf(STDERR, "ban_list[%d] = %x (%x) MATCH\n", $imid,
+ $this->ipcl[$imid]->addr, $this->ipcl[$imid]->mask);