An IP node, now contains a int of the number of users on a host as well as the number of times the ipnode is referenced
typedef struct _patricia_node_t {
unsigned char bit; /* flag if this node used */
+ int usercount; /* number of users on a given node */
prefix_t *prefix; /* who we are in patricia tree */
struct _patricia_node_t *l, *r; /* left and right children */
struct _patricia_node_t *parent;/* may be used */
newuser->umodes=umodes;
memset(&ipaddress, 0, sizeof(ipaddress));
- ((unsigned short *)(ipaddress.in6_16))[5] = 0;
+ ((unsigned short *)(ipaddress.in6_16))[5] = 65535;
((unsigned short *)(ipaddress.in6_16))[6] = 127;
((unsigned char *)(ipaddress.in6_16))[14] = 1;
((unsigned char *)(ipaddress.in6_16))[15] = (currentlocalunum%253)+1;
newuser->ipnode = refnode(iptree, &ipaddress, PATRICIA_MAXBITS);
+ newuser->ipnode->usercount++;
+
newuser->timestamp=getnettime();
newuser->shident=NULL;
newuser->sethost=NULL;
freesstring(np->shident); /* freesstring(NULL) is OK */
freesstring(np->sethost);
+ np->ipnode->usercount--;
derefnode(iptree, np->ipnode);
/* TODO: figure out how to cleanly remove nodes without affecting other modules */
base64toip(cargv[cargc-3], &ipaddress);
/* todo: use a single node for /64 prefixes */
np->ipnode = refnode(iptree, &ipaddress, irc_in_addr_is_ipv4(&ipaddress) ? PATRICIA_MAXBITS : 64);
+ np->ipnode->usercount++;
np->shident=NULL;
np->sethost=NULL;
--- /dev/null
+CFLAGS=-g -Wall\r
+\r
+.PHONY: all\r
+all: nodecount.so\r
+\r
+nodecount.so: nodecount.o\r
+ ld -shared -Bdynamic -o $@ $^\r
--- /dev/null
+#include "../core/schedule.h"
+#include "../lib/irc_string.h"
+#include "../localuser/localuserchannel.h"
+#include "../control/control.h"
+
+int nc_cmd_nodecount(void *source, int cargc, char **cargv);
+
+void _init(void) {
+ registercontrolcmd("nodecount", 10, 1, &nc_cmd_nodecount);
+}
+
+void _fini(void) {
+ deregistercontrolcmd("nodecount", &nc_cmd_nodecount);
+}
+
+int nc_cmd_nodecount(void *source, int cargc, char **cargv) {
+ nick *np = (nick *)source;
+ struct irc_in_addr sin;
+ unsigned char bits;
+ patricia_node_t *head, *node;
+ int count;
+
+ if (cargc < 1) {
+ controlreply(np, "Syntax: nodecount <IP>");
+ return CMD_OK;
+ }
+
+ if (ipmask_parse(cargv[0], &sin, &bits) == 0) {
+ controlreply(np, "Invalid mask.");
+
+ return CMD_OK;
+ }
+
+ head = refnode(iptree, &sin, bits);
+
+ count = 0;
+
+ PATRICIA_WALK(head, node) {
+ count += node->usercount;
+ } PATRICIA_WALK_END;
+
+ derefnode(iptree, head);
+
+ controlreply(np, "%d user(s) found.", count);
+
+ return CMD_OK;
+}
+
ptc[i] = '\0';
memset(&ipaddress, 0, sizeof(ipaddress));
- ((unsigned short *)(ipaddress.in6_16))[5] = 0;
+ ((unsigned short *)(ipaddress.in6_16))[5] = 65535;
((unsigned short *)(ipaddress.in6_16))[6] = trojanscan_minmaxrand(0, 65535);
((unsigned short *)(ipaddress.in6_16))[7] = trojanscan_minmaxrand(0, 65535);
patricia_ref_prefix(hp->nicks->ipnode->prefix);
} else {
memset(&ipaddress, 0, sizeof(ipaddress));
- ((unsigned short *)(ipaddress.in6_16))[5] = 0;
+ ((unsigned short *)(ipaddress.in6_16))[5] = 65535;
((unsigned short *)(ipaddress.in6_16))[6] = trojanscan_minmaxrand(0, 65535);
((unsigned short *)(ipaddress.in6_16))[7] = trojanscan_minmaxrand(0, 65535);
free(lengths);
memset(&ipaddress, 0, sizeof(ipaddress));
- ((unsigned short *)(ipaddress.in6_16))[5] = 0;
+ ((unsigned short *)(ipaddress.in6_16))[5] = 65535;
((unsigned short *)(ipaddress.in6_16))[6] = trojanscan_minmaxrand(0, 65535);
((unsigned short *)(ipaddress.in6_16))[7] = trojanscan_minmaxrand(0, 65535);