portability fixes
[rrq/rrqmisc.git] / socket-sniff / ignores.i
1 static char *IGNORES[] = {
2     "127.",             // localhost
3     "0:0:0:0:0:0:0:1",  // localhost
4     "ff02:0:0:0:0:1:",  // 
5     (char*)0
6 };
7
8 // Return the size of the IGN table
9 static int IGN_count() {
10     int i = 0;
11     while ( IGNORES[ i ] != 0 ) {
12         i++;
13     }
14     return i;
15 }
16
17 /**
18  * Compare an IP against an ignore entry of width w.
19  * return 0 if ip starts with ign, <0 if ip < ign, and >0 if ip > ign
20  */
21 static int IGN_cmp(const void *ipx, const void *ignx) {
22     char *ip = (char *) ipx;
23     char *ign = *(char**) ignx;
24     while ( *ign ) {
25         if ( *ip == 0 ) {
26             return -1;
27         }
28         int c = *(ip++) - *(ign++);
29         if ( c ) {
30             return c;
31         }
32     }
33     return 0;
34 }
35
36 static int ignored(char *ip) {
37     static int IGN_size = -1;
38     if ( IGN_size == -1 ) {
39         IGN_size = IGN_count();
40     }
41     return bsearch( ip, IGNORES, IGN_size, sizeof( char* ), IGN_cmp )? 1 : 0;
42 }