diff options
author | Denis Vlasenko | 2007-04-02 12:37:28 +0000 |
---|---|---|
committer | Denis Vlasenko | 2007-04-02 12:37:28 +0000 |
commit | 729bd9e0b0d5977e9c2c2a4eff7e2f0ca2ad4b9e (patch) | |
tree | d5cb1a1c7c41b2681ca867c57c3b4e473c0a56be /ipsvd | |
parent | b05a939bcc0249fe8bd94b9795db8f8d93c3921e (diff) | |
download | busybox-729bd9e0b0d5977e9c2c2a4eff7e2f0ca2ad4b9e.zip busybox-729bd9e0b0d5977e9c2c2a4eff7e2f0ca2ad4b9e.tar.gz |
test: comment out unused code
udpsvd: fake it compile
tcpsvd: more optimal memorizing of IP's for -C
Diffstat (limited to 'ipsvd')
-rw-r--r-- | ipsvd/ipsvd_perhost.c | 19 | ||||
-rw-r--r-- | ipsvd/ipsvd_perhost.h | 14 | ||||
-rw-r--r-- | ipsvd/tcpsvd.c | 6 | ||||
-rw-r--r-- | ipsvd/udpsvd.c | 9 |
4 files changed, 32 insertions, 16 deletions
diff --git a/ipsvd/ipsvd_perhost.c b/ipsvd/ipsvd_perhost.c index 1c5c12a..281f708 100644 --- a/ipsvd/ipsvd_perhost.c +++ b/ipsvd/ipsvd_perhost.c @@ -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; } diff --git a/ipsvd/ipsvd_perhost.h b/ipsvd/ipsvd_perhost.h index 26b4063..cf08000 100644 --- a/ipsvd/ipsvd_perhost.h +++ b/ipsvd/ipsvd_perhost.h @@ -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); diff --git a/ipsvd/tcpsvd.c b/ipsvd/tcpsvd.c index 197edca..98234a7 100644 --- a/ipsvd/tcpsvd.c +++ b/ipsvd/tcpsvd.c @@ -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) { diff --git a/ipsvd/udpsvd.c b/ipsvd/udpsvd.c index b3f6082..06c4f2e 100644 --- a/ipsvd/udpsvd.c +++ b/ipsvd/udpsvd.c @@ -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); |