aboutsummaryrefslogtreecommitdiff
path: root/networking/tcpudp_perhost.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-03-17 09:17:27 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-03-17 09:17:27 +0000
commit4866e905d7e1f11d86374fad4e46aa2bd669c2ba (patch)
treea6a8e9521de92d658903ba9f54cd01e94a34c262 /networking/tcpudp_perhost.c
parent4ee7cd4f6f9f85871c8814bb524d3e691a2992a9 (diff)
downloadbusybox-w32-4866e905d7e1f11d86374fad4e46aa2bd669c2ba.tar.gz
busybox-w32-4866e905d7e1f11d86374fad4e46aa2bd669c2ba.tar.bz2
busybox-w32-4866e905d7e1f11d86374fad4e46aa2bd669c2ba.zip
svn add/svn rm to actually move tcp/udpsvd...
Diffstat (limited to 'networking/tcpudp_perhost.c')
-rw-r--r--networking/tcpudp_perhost.c65
1 files changed, 65 insertions, 0 deletions
diff --git a/networking/tcpudp_perhost.c b/networking/tcpudp_perhost.c
new file mode 100644
index 000000000..3005f12c0
--- /dev/null
+++ b/networking/tcpudp_perhost.c
@@ -0,0 +1,65 @@
1/* Based on ipsvd utilities written by Gerrit Pape <pape@smarden.org>
2 * which are released into public domain by the author.
3 * Homepage: http://smarden.sunsite.dk/ipsvd/
4 *
5 * Copyright (C) 2007 Denys Vlasenko.
6 *
7 * Licensed under GPLv2, see file LICENSE in this tarball for details.
8 */
9
10#include "libbb.h"
11#include "tcpudp_perhost.h"
12
13static struct hcc *cc;
14static unsigned cclen;
15
16/* to be optimized */
17
18void ipsvd_perhost_init(unsigned c)
19{
20// free(cc);
21 cc = xzalloc(c * sizeof(*cc));
22 cclen = c;
23}
24
25unsigned ipsvd_perhost_add(char *ip, unsigned maxconn, struct hcc **hccpp)
26{
27 unsigned i;
28 unsigned conn = 1;
29 int freepos = -1;
30
31 for (i = 0; i < cclen; ++i) {
32 if (!cc[i].ip) {
33 freepos = i;
34 continue;
35 }
36 if (strcmp(cc[i].ip, ip) == 0) {
37 conn++;
38 continue;
39 }
40 }
41 if (freepos == -1) return 0;
42 if (conn <= maxconn) {
43 cc[freepos].ip = ip;
44 *hccpp = &cc[freepos];
45 }
46 return conn;
47}
48
49void ipsvd_perhost_remove(int pid)
50{
51 unsigned i;
52 for (i = 0; i < cclen; ++i) {
53 if (cc[i].pid == pid) {
54 free(cc[i].ip);
55 cc[i].ip = NULL;
56 cc[i].pid = 0;
57 return;
58 }
59 }
60}
61
62//void ipsvd_perhost_free(void)
63//{
64// free(cc);
65//}