2007-04-01 10:59:33 +00:00
|
|
|
/* Based on ipsvd utilities written by Gerrit Pape <pape@smarden.org>
|
|
|
|
* which are released into public domain by the author.
|
|
|
|
* Homepage: http://smarden.sunsite.dk/ipsvd/
|
|
|
|
*
|
2008-03-02 12:53:15 +00:00
|
|
|
* Copyright (C) 2007 Denys Vlasenko.
|
2007-04-01 10:59:33 +00:00
|
|
|
*
|
2010-08-16 20:14:46 +02:00
|
|
|
* Licensed under GPLv2, see file LICENSE in this source tree.
|
2007-04-01 10:59:33 +00:00
|
|
|
*/
|
|
|
|
|
2007-05-26 19:00:18 +00:00
|
|
|
#include "libbb.h"
|
2008-03-17 09:17:27 +00:00
|
|
|
#include "tcpudp_perhost.h"
|
2007-04-01 01:18:20 +00:00
|
|
|
|
2018-02-27 13:03:44 +01:00
|
|
|
struct hcc* FAST_FUNC ipsvd_perhost_init(unsigned c)
|
2007-04-01 01:18:20 +00:00
|
|
|
{
|
|
|
|
// free(cc);
|
2018-02-27 13:03:44 +01:00
|
|
|
struct hcc *cc = xzalloc((c + 1) * sizeof(*cc));
|
|
|
|
cc[c].pid = -1; /* "end" marker */
|
|
|
|
return cc;
|
2007-04-01 01:18:20 +00:00
|
|
|
}
|
|
|
|
|
2018-02-27 13:03:44 +01:00
|
|
|
unsigned FAST_FUNC ipsvd_perhost_add(struct hcc *cc, char *ip, unsigned maxconn, struct hcc **hccpp)
|
2007-04-01 01:18:20 +00:00
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
unsigned conn = 1;
|
2007-04-02 12:37:28 +00:00
|
|
|
int freepos = -1;
|
2007-04-01 01:18:20 +00:00
|
|
|
|
2018-02-27 13:03:44 +01:00
|
|
|
for (i = 0; cc[i].pid >= 0; ++i) {
|
2007-04-02 12:37:28 +00:00
|
|
|
if (!cc[i].ip) {
|
|
|
|
freepos = i;
|
2007-05-30 00:29:55 +00:00
|
|
|
continue;
|
2007-04-01 01:18:20 +00:00
|
|
|
}
|
2007-04-02 12:37:28 +00:00
|
|
|
if (strcmp(cc[i].ip, ip) == 0) {
|
2007-04-01 01:18:20 +00:00
|
|
|
conn++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2007-04-02 12:37:28 +00:00
|
|
|
if (freepos == -1) return 0;
|
2007-04-01 01:18:20 +00:00
|
|
|
if (conn <= maxconn) {
|
2007-04-02 12:37:28 +00:00
|
|
|
cc[freepos].ip = ip;
|
|
|
|
*hccpp = &cc[freepos];
|
2007-04-01 01:18:20 +00:00
|
|
|
}
|
|
|
|
return conn;
|
|
|
|
}
|
|
|
|
|
2018-02-27 13:03:44 +01:00
|
|
|
void FAST_FUNC ipsvd_perhost_remove(struct hcc *cc, int pid)
|
2007-04-01 01:18:20 +00:00
|
|
|
{
|
|
|
|
unsigned i;
|
2018-02-27 13:03:44 +01:00
|
|
|
for (i = 0; cc[i].pid >= 0; ++i) {
|
2007-04-01 01:18:20 +00:00
|
|
|
if (cc[i].pid == pid) {
|
2007-04-02 12:37:28 +00:00
|
|
|
free(cc[i].ip);
|
|
|
|
cc[i].ip = NULL;
|
2007-04-01 01:18:20 +00:00
|
|
|
cc[i].pid = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-27 13:03:44 +01:00
|
|
|
//void ipsvd_perhost_free(struct hcc *cc)
|
2007-04-01 01:18:20 +00:00
|
|
|
//{
|
|
|
|
// free(cc);
|
|
|
|
//}
|