test: comment out unused code
udpsvd: fake it compile tcpsvd: more optimal memorizing of IP's for -C
This commit is contained in:
@@ -22,26 +22,26 @@ void ipsvd_perhost_init(unsigned c)
|
||||
cclen = c;
|
||||
}
|
||||
|
||||
unsigned ipsvd_perhost_add(const char *ip, unsigned maxconn, struct hcc **hccpp)
|
||||
unsigned ipsvd_perhost_add(char *ip, unsigned maxconn, struct hcc **hccpp)
|
||||
{
|
||||
unsigned i;
|
||||
unsigned conn = 1;
|
||||
int p = -1;
|
||||
int freepos = -1;
|
||||
|
||||
for (i = 0; i < cclen; ++i) {
|
||||
if (cc[i].ip[0] == 0) {
|
||||
if (p == -1) p = i;
|
||||
if (!cc[i].ip) {
|
||||
freepos = i;
|
||||
continue;
|
||||
}
|
||||
if (strncmp(cc[i].ip, ip, sizeof(cc[i].ip)) == 0) {
|
||||
if (strcmp(cc[i].ip, ip) == 0) {
|
||||
conn++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (p == -1) return 0;
|
||||
if (freepos == -1) return 0;
|
||||
if (conn <= maxconn) {
|
||||
strcpy(cc[p].ip, ip);
|
||||
*hccpp = &cc[p];
|
||||
cc[freepos].ip = ip;
|
||||
*hccpp = &cc[freepos];
|
||||
}
|
||||
return conn;
|
||||
}
|
||||
@@ -51,7 +51,8 @@ void ipsvd_perhost_remove(int pid)
|
||||
unsigned i;
|
||||
for (i = 0; i < cclen; ++i) {
|
||||
if (cc[i].pid == pid) {
|
||||
cc[i].ip[0] = 0;
|
||||
free(cc[i].ip);
|
||||
cc[i].ip = NULL;
|
||||
cc[i].pid = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -8,12 +8,22 @@
|
||||
*/
|
||||
|
||||
struct hcc {
|
||||
char ip[32 - sizeof(int)];
|
||||
char *ip;
|
||||
int pid;
|
||||
};
|
||||
|
||||
void ipsvd_perhost_init(unsigned);
|
||||
unsigned ipsvd_perhost_add(const char *ip, unsigned maxconn, struct hcc **hccpp);
|
||||
|
||||
/* Returns number of already opened connects to this ips, including this one.
|
||||
* ip should be a malloc'ed ptr.
|
||||
* If return value is <= maxconn, ip is inserted into the table
|
||||
* and pointer to table entry if stored in *hccpp
|
||||
* (useful for storing pid later).
|
||||
* Else ip is NOT inserted (you must take care of it - free() etc) */
|
||||
unsigned ipsvd_perhost_add(char *ip, unsigned maxconn, struct hcc **hccpp);
|
||||
|
||||
/* Finds and frees element with pid */
|
||||
void ipsvd_perhost_remove(int pid);
|
||||
|
||||
//unsigned ipsvd_perhost_setpid(int pid);
|
||||
//void ipsvd_perhost_free(void);
|
||||
|
||||
@@ -128,8 +128,8 @@ int tcpsvd_main(int argc, char **argv)
|
||||
uint16_t remote_port;
|
||||
char *local_hostname = NULL;
|
||||
char *remote_hostname = (char*)""; /* "" used if no -h */
|
||||
char *local_ip = local_ip;
|
||||
char *remote_ip = NULL;
|
||||
char *local_ip = local_ip; /* gcc */
|
||||
char *remote_ip = remote_ip; /* gcc */
|
||||
//unsigned iscdb = 0; /* = option_mask32 & OPT_x (TODO) */
|
||||
//unsigned long timeout = 0;
|
||||
#ifndef SSLSVD
|
||||
@@ -271,10 +271,10 @@ int tcpsvd_main(int argc, char **argv)
|
||||
if (max_per_host) {
|
||||
/* we drop connection immediately if cur_per_host > max_per_host
|
||||
* (minimizing load under SYN flood) */
|
||||
free(remote_ip);
|
||||
remote_ip = xmalloc_sockaddr2dotted_noport(&sock_adr.sa, sockadr_size);
|
||||
cur_per_host = ipsvd_perhost_add(remote_ip, max_per_host, &hccp);
|
||||
if (cur_per_host > max_per_host) {
|
||||
free(remote_ip);
|
||||
/* ipsvd_perhost_add detected that max is exceeded
|
||||
* (and did not store us in connection table) */
|
||||
if (msg_per_host) {
|
||||
|
||||
@@ -42,9 +42,9 @@ int udpsvd_main(int argc, char **argv)
|
||||
// unsigned long timeout = 0;
|
||||
|
||||
char *remote_hostname;
|
||||
char *local_hostname;
|
||||
char *local_hostname = local_hostname; /* gcc */
|
||||
char *remote_ip;
|
||||
char *local_ip;
|
||||
char *local_ip = local_ip; /* gcc */
|
||||
uint16_t local_port, remote_port;
|
||||
union {
|
||||
struct sockaddr sa;
|
||||
@@ -145,6 +145,11 @@ int udpsvd_main(int argc, char **argv)
|
||||
/* if (recvfrom(sock, 0, 0, MSG_PEEK, (struct sockaddr *)&sock_adr, &sockadr_size) == -1)
|
||||
drop("unable to read from socket");
|
||||
*/
|
||||
if (verbose) {
|
||||
local_ip = argv[0]; // TODO: recv_from_to!
|
||||
local_hostname = (char*)"localhost";
|
||||
}
|
||||
|
||||
remote_ip = xmalloc_sockaddr2dotted_noport(&sock_adr.sa, sockadr_size);
|
||||
remote_port = get_nport(&sock_adr.sa);
|
||||
remote_port = ntohs(remote_port);
|
||||
|
||||
Reference in New Issue
Block a user