diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-04-01 05:18:20 +0400 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-04-01 05:18:20 +0400 |
commit | 2856dab4770e521a87c18b04ae8ebc209a9b95f9 (patch) | |
tree | d4f6495339702c0b6d79816d0bb07ba4b6679ce8 /ipsvd/ipsvd_perhost.c | |
parent | f443bffd3c24c4b7fcbc0472c75e747e26c24fef (diff) |
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.c | 55 |
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); +//} |