diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-04-02 12:37:28 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-04-02 12:37:28 +0000 |
commit | 729bd9e0b0d5977e9c2c2a4eff7e2f0ca2ad4b9e (patch) | |
tree | d5cb1a1c7c41b2681ca867c57c3b4e473c0a56be /ipsvd | |
parent | b05a939bcc0249fe8bd94b9795db8f8d93c3921e (diff) | |
download | busybox-w32-729bd9e0b0d5977e9c2c2a4eff7e2f0ca2ad4b9e.tar.gz busybox-w32-729bd9e0b0d5977e9c2c2a4eff7e2f0ca2ad4b9e.tar.bz2 busybox-w32-729bd9e0b0d5977e9c2c2a4eff7e2f0ca2ad4b9e.zip |
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 1c5c12af5..281f708b0 100644 --- a/ipsvd/ipsvd_perhost.c +++ b/ipsvd/ipsvd_perhost.c | |||
@@ -22,26 +22,26 @@ void ipsvd_perhost_init(unsigned c) | |||
22 | cclen = c; | 22 | cclen = c; |
23 | } | 23 | } |
24 | 24 | ||
25 | unsigned ipsvd_perhost_add(const char *ip, unsigned maxconn, struct hcc **hccpp) | 25 | unsigned ipsvd_perhost_add(char *ip, unsigned maxconn, struct hcc **hccpp) |
26 | { | 26 | { |
27 | unsigned i; | 27 | unsigned i; |
28 | unsigned conn = 1; | 28 | unsigned conn = 1; |
29 | int p = -1; | 29 | int freepos = -1; |
30 | 30 | ||
31 | for (i = 0; i < cclen; ++i) { | 31 | for (i = 0; i < cclen; ++i) { |
32 | if (cc[i].ip[0] == 0) { | 32 | if (!cc[i].ip) { |
33 | if (p == -1) p = i; | 33 | freepos = i; |
34 | continue; | 34 | continue; |
35 | } | 35 | } |
36 | if (strncmp(cc[i].ip, ip, sizeof(cc[i].ip)) == 0) { | 36 | if (strcmp(cc[i].ip, ip) == 0) { |
37 | conn++; | 37 | conn++; |
38 | continue; | 38 | continue; |
39 | } | 39 | } |
40 | } | 40 | } |
41 | if (p == -1) return 0; | 41 | if (freepos == -1) return 0; |
42 | if (conn <= maxconn) { | 42 | if (conn <= maxconn) { |
43 | strcpy(cc[p].ip, ip); | 43 | cc[freepos].ip = ip; |
44 | *hccpp = &cc[p]; | 44 | *hccpp = &cc[freepos]; |
45 | } | 45 | } |
46 | return conn; | 46 | return conn; |
47 | } | 47 | } |
@@ -51,7 +51,8 @@ void ipsvd_perhost_remove(int pid) | |||
51 | unsigned i; | 51 | unsigned i; |
52 | for (i = 0; i < cclen; ++i) { | 52 | for (i = 0; i < cclen; ++i) { |
53 | if (cc[i].pid == pid) { | 53 | if (cc[i].pid == pid) { |
54 | cc[i].ip[0] = 0; | 54 | free(cc[i].ip); |
55 | cc[i].ip = NULL; | ||
55 | cc[i].pid = 0; | 56 | cc[i].pid = 0; |
56 | return; | 57 | return; |
57 | } | 58 | } |
diff --git a/ipsvd/ipsvd_perhost.h b/ipsvd/ipsvd_perhost.h index 26b4063ea..cf08000e0 100644 --- a/ipsvd/ipsvd_perhost.h +++ b/ipsvd/ipsvd_perhost.h | |||
@@ -8,12 +8,22 @@ | |||
8 | */ | 8 | */ |
9 | 9 | ||
10 | struct hcc { | 10 | struct hcc { |
11 | char ip[32 - sizeof(int)]; | 11 | char *ip; |
12 | int pid; | 12 | int pid; |
13 | }; | 13 | }; |
14 | 14 | ||
15 | void ipsvd_perhost_init(unsigned); | 15 | void ipsvd_perhost_init(unsigned); |
16 | unsigned ipsvd_perhost_add(const char *ip, unsigned maxconn, struct hcc **hccpp); | 16 | |
17 | /* Returns number of already opened connects to this ips, including this one. | ||
18 | * ip should be a malloc'ed ptr. | ||
19 | * If return value is <= maxconn, ip is inserted into the table | ||
20 | * and pointer to table entry if stored in *hccpp | ||
21 | * (useful for storing pid later). | ||
22 | * Else ip is NOT inserted (you must take care of it - free() etc) */ | ||
23 | unsigned ipsvd_perhost_add(char *ip, unsigned maxconn, struct hcc **hccpp); | ||
24 | |||
25 | /* Finds and frees element with pid */ | ||
17 | void ipsvd_perhost_remove(int pid); | 26 | void ipsvd_perhost_remove(int pid); |
27 | |||
18 | //unsigned ipsvd_perhost_setpid(int pid); | 28 | //unsigned ipsvd_perhost_setpid(int pid); |
19 | //void ipsvd_perhost_free(void); | 29 | //void ipsvd_perhost_free(void); |
diff --git a/ipsvd/tcpsvd.c b/ipsvd/tcpsvd.c index 197edca4e..98234a78b 100644 --- a/ipsvd/tcpsvd.c +++ b/ipsvd/tcpsvd.c | |||
@@ -128,8 +128,8 @@ int tcpsvd_main(int argc, char **argv) | |||
128 | uint16_t remote_port; | 128 | uint16_t remote_port; |
129 | char *local_hostname = NULL; | 129 | char *local_hostname = NULL; |
130 | char *remote_hostname = (char*)""; /* "" used if no -h */ | 130 | char *remote_hostname = (char*)""; /* "" used if no -h */ |
131 | char *local_ip = local_ip; | 131 | char *local_ip = local_ip; /* gcc */ |
132 | char *remote_ip = NULL; | 132 | char *remote_ip = remote_ip; /* gcc */ |
133 | //unsigned iscdb = 0; /* = option_mask32 & OPT_x (TODO) */ | 133 | //unsigned iscdb = 0; /* = option_mask32 & OPT_x (TODO) */ |
134 | //unsigned long timeout = 0; | 134 | //unsigned long timeout = 0; |
135 | #ifndef SSLSVD | 135 | #ifndef SSLSVD |
@@ -271,10 +271,10 @@ int tcpsvd_main(int argc, char **argv) | |||
271 | if (max_per_host) { | 271 | if (max_per_host) { |
272 | /* we drop connection immediately if cur_per_host > max_per_host | 272 | /* we drop connection immediately if cur_per_host > max_per_host |
273 | * (minimizing load under SYN flood) */ | 273 | * (minimizing load under SYN flood) */ |
274 | free(remote_ip); | ||
275 | remote_ip = xmalloc_sockaddr2dotted_noport(&sock_adr.sa, sockadr_size); | 274 | remote_ip = xmalloc_sockaddr2dotted_noport(&sock_adr.sa, sockadr_size); |
276 | cur_per_host = ipsvd_perhost_add(remote_ip, max_per_host, &hccp); | 275 | cur_per_host = ipsvd_perhost_add(remote_ip, max_per_host, &hccp); |
277 | if (cur_per_host > max_per_host) { | 276 | if (cur_per_host > max_per_host) { |
277 | free(remote_ip); | ||
278 | /* ipsvd_perhost_add detected that max is exceeded | 278 | /* ipsvd_perhost_add detected that max is exceeded |
279 | * (and did not store us in connection table) */ | 279 | * (and did not store us in connection table) */ |
280 | if (msg_per_host) { | 280 | if (msg_per_host) { |
diff --git a/ipsvd/udpsvd.c b/ipsvd/udpsvd.c index b3f60823f..06c4f2e88 100644 --- a/ipsvd/udpsvd.c +++ b/ipsvd/udpsvd.c | |||
@@ -42,9 +42,9 @@ int udpsvd_main(int argc, char **argv) | |||
42 | // unsigned long timeout = 0; | 42 | // unsigned long timeout = 0; |
43 | 43 | ||
44 | char *remote_hostname; | 44 | char *remote_hostname; |
45 | char *local_hostname; | 45 | char *local_hostname = local_hostname; /* gcc */ |
46 | char *remote_ip; | 46 | char *remote_ip; |
47 | char *local_ip; | 47 | char *local_ip = local_ip; /* gcc */ |
48 | uint16_t local_port, remote_port; | 48 | uint16_t local_port, remote_port; |
49 | union { | 49 | union { |
50 | struct sockaddr sa; | 50 | struct sockaddr sa; |
@@ -145,6 +145,11 @@ int udpsvd_main(int argc, char **argv) | |||
145 | /* if (recvfrom(sock, 0, 0, MSG_PEEK, (struct sockaddr *)&sock_adr, &sockadr_size) == -1) | 145 | /* if (recvfrom(sock, 0, 0, MSG_PEEK, (struct sockaddr *)&sock_adr, &sockadr_size) == -1) |
146 | drop("unable to read from socket"); | 146 | drop("unable to read from socket"); |
147 | */ | 147 | */ |
148 | if (verbose) { | ||
149 | local_ip = argv[0]; // TODO: recv_from_to! | ||
150 | local_hostname = (char*)"localhost"; | ||
151 | } | ||
152 | |||
148 | remote_ip = xmalloc_sockaddr2dotted_noport(&sock_adr.sa, sockadr_size); | 153 | remote_ip = xmalloc_sockaddr2dotted_noport(&sock_adr.sa, sockadr_size); |
149 | remote_port = get_nport(&sock_adr.sa); | 154 | remote_port = get_nport(&sock_adr.sa); |
150 | remote_port = ntohs(remote_port); | 155 | remote_port = ntohs(remote_port); |