summaryrefslogtreecommitdiff
path: root/ipsvd/ipsvd_perhost.c
diff options
context:
space:
mode:
Diffstat (limited to 'ipsvd/ipsvd_perhost.c')
-rw-r--r--ipsvd/ipsvd_perhost.c55
1 files changed, 55 insertions, 0 deletions
diff --git a/ipsvd/ipsvd_perhost.c b/ipsvd/ipsvd_perhost.c
new file mode 100644
index 0000000..c6f7de3
--- /dev/null
+++ b/ipsvd/ipsvd_perhost.c
@@ -0,0 +1,55 @@
+#include "busybox.h"
+#include "ipsvd_perhost.h"
+
+static struct hcc *cc;
+static unsigned cclen;
+
+/* to be optimized */
+
+void ipsvd_perhost_init(unsigned c)
+{
+// free(cc);
+ cc = xzalloc(c * sizeof(*cc));
+ cclen = c;
+}
+
+unsigned ipsvd_perhost_add(const char *ip, unsigned maxconn, struct hcc **hccpp)
+{
+ unsigned i;
+ unsigned conn = 1;
+ int p = -1;
+
+ for (i = 0; i < cclen; ++i) {
+ if (cc[i].ip[0] == 0) {
+ if (p == -1) p = i;
+ continue;
+ }
+ if (strncmp(cc[i].ip, ip, sizeof(cc[i].ip)) == 0) {
+ conn++;
+ continue;
+ }
+ }
+ if (p == -1) return 0;
+ if (conn <= maxconn) {
+ strcpy(cc[p].ip, ip);
+ *hccpp = &cc[p];
+ }
+ return conn;
+}
+
+void ipsvd_perhost_remove(int pid)
+{
+ unsigned i;
+ for (i = 0; i < cclen; ++i) {
+ if (cc[i].pid == pid) {
+ cc[i].ip[0] = 0;
+ cc[i].pid = 0;
+ return;
+ }
+ }
+}
+
+//void ipsvd_perhost_free(void)
+//{
+// free(cc);
+//}