aboutsummaryrefslogtreecommitdiff
path: root/ipsvd/ipsvd_perhost.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-04-01 01:18:20 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-04-01 01:18:20 +0000
commit2856dab4770e521a87c18b04ae8ebc209a9b95f9 (patch)
treed4f6495339702c0b6d79816d0bb07ba4b6679ce8 /ipsvd/ipsvd_perhost.c
parentf443bffd3c24c4b7fcbc0472c75e747e26c24fef (diff)
downloadbusybox-2856dab4770e521a87c18b04ae8ebc209a9b95f9.tar.gz
tcpsvd: new applet
It's a GPL-ed 'clone' of Dan Bernstein's tcpserver. Author: Gerrit Pape <pape@smarden.org> http://smarden.sunsite.dk/ipsvd/ size tcpsvd.o text data bss dec hex filename 2571 4 16 2591 a1f tcpsvd.o
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 000000000..c6f7de339
--- /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);
+//}