SSID: Respect ASCII character Label.
[tomato.git] / release / src / router / busybox / networking / tcpudp_perhost.c
blob10541088379ac75de5efad89a88a060d6a33212e
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/
5 * Copyright (C) 2007 Denys Vlasenko.
7 * Licensed under GPLv2, see file LICENSE in this source tree.
8 */
10 #include "libbb.h"
11 #include "tcpudp_perhost.h"
13 static struct hcc *cc;
14 static unsigned cclen;
16 /* to be optimized */
18 void ipsvd_perhost_init(unsigned c)
20 // free(cc);
21 cc = xzalloc(c * sizeof(*cc));
22 cclen = c;
25 unsigned ipsvd_perhost_add(char *ip, unsigned maxconn, struct hcc **hccpp)
27 unsigned i;
28 unsigned conn = 1;
29 int freepos = -1;
31 for (i = 0; i < cclen; ++i) {
32 if (!cc[i].ip) {
33 freepos = i;
34 continue;
36 if (strcmp(cc[i].ip, ip) == 0) {
37 conn++;
38 continue;
41 if (freepos == -1) return 0;
42 if (conn <= maxconn) {
43 cc[freepos].ip = ip;
44 *hccpp = &cc[freepos];
46 return conn;
49 void ipsvd_perhost_remove(int pid)
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;
62 //void ipsvd_perhost_free(void)
63 //{
64 // free(cc);
65 //}