17extern int rename(
const char *,
const char *);
34 logmsg(
WHO,111,FATAL,
"out of memory");
38 logmsg(
WHO,100,USAGE,
"tcprules rules.cdb rules.tmp");
43 logmsg(
WHO,101,SYNTAX,B(
"unable to parse this line: ",
line.s));
47 logmsg(
WHO,111,FATAL,B(
"unable to write to: ",
fntemp));
52 logmsg(
WHO,101,SYNTAX,B(
"invalid prefix length on line: ",
line.s));
57 logmsg(
WHO,101,SYNTAX,B(
"invalid address on line: ",
line.s));
61 logmsg(
WHO,101,SYNTAX,B(
"invalid IPv4 CIDR address on line: ",
line.s));
65 logmsg(
WHO,101,SYNTAX,B(
"invalid IPv6 address: on line: ",
line.s));
69 logmsg(
WHO,101,SYNTAX,B(
"invalid IPv6 CIDR address on line: ",
line.s));
72static char strnum[FMT_ULONG];
73static stralloc sanum = {0};
75void getnum(
char *buf,
int len,
unsigned long *u) {
76 if (!stralloc_copyb(&sanum,buf,len))
nomem();
77 if (!stralloc_0(&sanum))
nomem();
78 if (sanum.s[scan_ulong(sanum.s,u)])
die_bad();
91 stralloc ip6address = {0};
102 if (!stralloc_cats(&
key,
"@"))
nomem();
106 if (!stralloc_catb(&
key,ip6address.s,ip6address.len))
nomem();
125 case 0:
if (!stralloc_copys(&
key,
"_"))
nomem();
134 left = byte_rchr(
address.s,i,
'.');
135 if (left == i) left = 0;
else ++left;
142 if (top > 255) top = 255;
145 if (!stralloc_catb(&
key,strnum,fmt_ulong(strnum,bot)))
nomem();
161 case 0:
if (!stralloc_copys(&
key,
"^"))
nomem();
174 case 0:
if (cdb_make_add(&
c,ip6address.s,ip6address.len,
data.s,
data.len) == -1)
188int main(
int argc,
char *
const *argv) {
203 logmsg(
WHO,111,ERROR,B(
"unable to create: ",
fntemp));
207 if (getln(buffer_0,&
line,&
match,
'\n') == -1)
208 logmsg(
WHO,111,FATAL,
"unable to read input");
214 if (x[0] ==
'#')
continue;
215 if (x[0] ==
'\n')
continue;
219 if (ch !=
'\n')
if (ch !=
' ')
if (ch !=
'\t')
break;
226 i = byte_chr(x,len,
',');
227 colon = byte_rchr(x,i,
':');
229 if (colon == len)
continue;
234 x += colon + 1; len -= colon + 1;
236 if ((len >= 4) && byte_equal(x,4,
"deny")) {
237 if (!stralloc_catb(&
data,
"D",2))
nomem();
240 else if ((len >= 5) && byte_equal(x,5,
"allow")) {
248 case ',': i = byte_chr(x,len,
'=');
250 if (!stralloc_catb(&
data,
"+",1))
nomem();
251 if (!stralloc_catb(&
data,x + 1,i))
nomem();
252 x += i + 1; len -= i + 1;
256 i = byte_chr(x,len,ch);
260 x += i + 1; len -= i + 1;
272 logmsg(
WHO,111,ERROR,B(
"unable to move ",
fntemp,
" to: ",
fn));
int rename(const char *, const char *)
void getnum(char *buf, int len, unsigned long *u)
int ip6_bitstring(stralloc *ip6string, char *ip6addr, unsigned int prefix)
unsigned int ip6_fmt_str(stralloc *dest, char *src)
int ip4_bitstring(stralloc *ip4string, char *ip, unsigned int prefix)