]>
jfr.im git - irc/quakenet/newserv.git/blob - newsearch/ns-cidr.c
11 #include "../irc/irc_config.h"
12 #include "../lib/irc_string.h"
13 #include "../lib/irc_ipv6.h"
15 struct cidr_localdata
{
16 struct irc_in_addr ip
;
20 void *cidr_exe(searchCtx
*ctx
, struct searchNode
*thenode
, void *theinput
);
21 void cidr_free(searchCtx
*ctx
, struct searchNode
*thenode
);
23 struct searchNode
*cidr_parse(searchCtx
*ctx
, int argc
, char **argv
) {
24 struct searchNode
*thenode
, *convsn
;
25 struct cidr_localdata
*c
;
26 struct irc_in_addr ip
;
32 parseError
= "usage: cidr ip/mask";
36 if (!(convsn
=argtoconststr("cidr", ctx
, argv
[0], &p
)))
39 ret
= ipmask_parse(p
, &ip
, &bits
);
40 convsn
->free(ctx
, convsn
);
43 parseError
= "usage: cidr ip/mask";
47 if (!(thenode
=(struct searchNode
*)malloc(sizeof (struct searchNode
)))) {
48 parseError
= "malloc: could not allocate memory for this search.";
52 thenode
->returntype
= RETURNTYPE_BOOL
;
53 if (!(c
= malloc(sizeof(struct cidr_localdata
)))) {
54 /* couldn't malloc() memory for thenode->localdata, so free thenode to avoid leakage */
55 parseError
= "malloc: could not allocate memory for this search.";
60 memcpy(&c
->ip
, &ip
, sizeof(struct irc_in_addr
));
63 thenode
->localdata
= (void *)c
;
64 thenode
->free
= cidr_free
;
65 thenode
->exe
= cidr_exe
;
70 void *cidr_exe(searchCtx
*ctx
, struct searchNode
*thenode
, void *theinput
) {
71 nick
*np
= (nick
*)theinput
;
72 struct cidr_localdata
*c
= thenode
->localdata
;
74 if(!ipmask_check(&np
->p_ipaddr
, &c
->ip
, c
->bits
))
80 void cidr_free(searchCtx
*ctx
, struct searchNode
*thenode
) {
81 free(thenode
->localdata
);