aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277>2007-04-02 12:37:28 +0000
committervda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277>2007-04-02 12:37:28 +0000
commit163196507b7ca852a667608561f8ce2a42ae6f70 (patch)
treed5cb1a1c7c41b2681ca867c57c3b4e473c0a56be
parente076974fc1f9c841f5a689120bbeb667d76cd5b7 (diff)
downloadbusybox-w32-163196507b7ca852a667608561f8ce2a42ae6f70.tar.gz
busybox-w32-163196507b7ca852a667608561f8ce2a42ae6f70.tar.bz2
busybox-w32-163196507b7ca852a667608561f8ce2a42ae6f70.zip
test: comment out unused code
udpsvd: fake it compile tcpsvd: more optimal memorizing of IP's for -C git-svn-id: svn://busybox.net/trunk/busybox@18302 69ca8d6d-28ef-0310-b511-8ec308f3f277
-rw-r--r--coreutils/test.c4
-rw-r--r--include/libbb.h7
-rw-r--r--ipsvd/ipsvd_perhost.c19
-rw-r--r--ipsvd/ipsvd_perhost.h14
-rw-r--r--ipsvd/tcpsvd.c6
-rw-r--r--ipsvd/udpsvd.c9
-rw-r--r--libbb/xconnect.c28
7 files changed, 62 insertions, 25 deletions
diff --git a/coreutils/test.c b/coreutils/test.c
index 813cde47c..d5babefce 100644
--- a/coreutils/test.c
+++ b/coreutils/test.c
@@ -168,9 +168,11 @@ static int binop(void);
168static arith_t primary(enum token n); 168static arith_t primary(enum token n);
169static int filstat(char *nm, enum token mode); 169static int filstat(char *nm, enum token mode);
170static arith_t getn(const char *s); 170static arith_t getn(const char *s);
171/* UNUSED
171static int newerf(const char *f1, const char *f2); 172static int newerf(const char *f1, const char *f2);
172static int olderf(const char *f1, const char *f2); 173static int olderf(const char *f1, const char *f2);
173static int equalf(const char *f1, const char *f2); 174static int equalf(const char *f1, const char *f2);
175*/
174static int test_eaccess(char *path, int mode); 176static int test_eaccess(char *path, int mode);
175static int is_a_group_member(gid_t gid); 177static int is_a_group_member(gid_t gid);
176static void initialize_group_array(void); 178static void initialize_group_array(void);
@@ -490,6 +492,7 @@ static arith_t getn(const char *s)
490 return r; 492 return r;
491} 493}
492 494
495/* UNUSED
493static int newerf(const char *f1, const char *f2) 496static int newerf(const char *f1, const char *f2)
494{ 497{
495 struct stat b1, b2; 498 struct stat b1, b2;
@@ -514,6 +517,7 @@ static int equalf(const char *f1, const char *f2)
514 stat(f2, &b2) == 0 && 517 stat(f2, &b2) == 0 &&
515 b1.st_dev == b2.st_dev && b1.st_ino == b2.st_ino); 518 b1.st_dev == b2.st_dev && b1.st_ino == b2.st_ino);
516} 519}
520*/
517 521
518/* Do the same thing access(2) does, but use the effective uid and gid, 522/* Do the same thing access(2) does, but use the effective uid and gid,
519 and don't make the mistake of telling root that any file is 523 and don't make the mistake of telling root that any file is
diff --git a/include/libbb.h b/include/libbb.h
index 794049df9..b802e01d3 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -324,11 +324,12 @@ typedef struct len_and_sockaddr {
324/* Create stream socket, and allocated suitable lsa 324/* Create stream socket, and allocated suitable lsa
325 * (lsa of correct size and lsa->sa.sa_family (AF_INET/AF_INET6)) */ 325 * (lsa of correct size and lsa->sa.sa_family (AF_INET/AF_INET6)) */
326int xsocket_stream(len_and_sockaddr **lsap); 326int xsocket_stream(len_and_sockaddr **lsap);
327/* Create server TCP socket bound to bindaddr:port. bindaddr can be NULL, 327/* Create server socket bound to bindaddr:port. bindaddr can be NULL,
328 * numeric IP ("N.N.N.N") or numeric IPv6 address, 328 * numeric IP ("N.N.N.N") or numeric IPv6 address,
329 * and can have ":PORT" suffix (for IPv6 use "[X:X:...:X]:PORT"). 329 * and can have ":PORT" suffix (for IPv6 use "[X:X:...:X]:PORT").
330 * If there is no suffix, port argument is used */ 330 * If there is no suffix, port argument is used */
331int create_and_bind_stream_or_die(const char *bindaddr, int port); 331int create_and_bind_stream_or_die(const char *bindaddr, int port);
332int create_and_bind_dgram_or_die(const char *bindaddr, int port);
332/* Create client TCP socket connected to peer:port. Peer cannot be NULL. 333/* Create client TCP socket connected to peer:port. Peer cannot be NULL.
333 * Peer can be numeric IP ("N.N.N.N"), numeric IPv6 address or hostname, 334 * Peer can be numeric IP ("N.N.N.N"), numeric IPv6 address or hostname,
334 * and can have ":PORT" suffix (for IPv6 use "[X:X:...:X]:PORT"). 335 * and can have ":PORT" suffix (for IPv6 use "[X:X:...:X]:PORT").
@@ -370,9 +371,9 @@ char* xmalloc_sockaddr2hostonly_noport(const struct sockaddr *sa, socklen_t sale
370char* xmalloc_sockaddr2dotted(const struct sockaddr *sa, socklen_t salen); 371char* xmalloc_sockaddr2dotted(const struct sockaddr *sa, socklen_t salen);
371char* xmalloc_sockaddr2dotted_noport(const struct sockaddr *sa, socklen_t salen); 372char* xmalloc_sockaddr2dotted_noport(const struct sockaddr *sa, socklen_t salen);
372// "old" (ipv4 only) API 373// "old" (ipv4 only) API
373// users: traceroute.c hostname.c 374// users: traceroute.c hostname.c - use _list_ of all IPs
374struct hostent *xgethostbyname(const char *name); 375struct hostent *xgethostbyname(const char *name);
375// Also inetd.c and inetd.c are using gethostbyname(), 376// Also mount.c and inetd.c are using gethostbyname(),
376// + inet_common.c has additional IPv4-only stuff 377// + inet_common.c has additional IPv4-only stuff
377 378
378 379
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
25unsigned ipsvd_perhost_add(const char *ip, unsigned maxconn, struct hcc **hccpp) 25unsigned 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
10struct hcc { 10struct hcc {
11 char ip[32 - sizeof(int)]; 11 char *ip;
12 int pid; 12 int pid;
13}; 13};
14 14
15void ipsvd_perhost_init(unsigned); 15void ipsvd_perhost_init(unsigned);
16unsigned 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) */
23unsigned ipsvd_perhost_add(char *ip, unsigned maxconn, struct hcc **hccpp);
24
25/* Finds and frees element with pid */
17void ipsvd_perhost_remove(int pid); 26void 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);
diff --git a/libbb/xconnect.c b/libbb/xconnect.c
index a331e6bc4..3c1eec943 100644
--- a/libbb/xconnect.c
+++ b/libbb/xconnect.c
@@ -208,7 +208,7 @@ len_and_sockaddr* xdotted2sockaddr(const char *host, int port)
208 return str2sockaddr(host, port, AF_UNSPEC, AI_NUMERICHOST | DIE_ON_ERROR); 208 return str2sockaddr(host, port, AF_UNSPEC, AI_NUMERICHOST | DIE_ON_ERROR);
209} 209}
210 210
211int xsocket_stream(len_and_sockaddr **lsap) 211static int xsocket_type(len_and_sockaddr **lsap, int sock_type)
212{ 212{
213 len_and_sockaddr *lsa; 213 len_and_sockaddr *lsa;
214 int fd; 214 int fd;
@@ -216,14 +216,14 @@ int xsocket_stream(len_and_sockaddr **lsap)
216 int family = AF_INET; 216 int family = AF_INET;
217 217
218#if ENABLE_FEATURE_IPV6 218#if ENABLE_FEATURE_IPV6
219 fd = socket(AF_INET6, SOCK_STREAM, 0); 219 fd = socket(AF_INET6, sock_type, 0);
220 if (fd >= 0) { 220 if (fd >= 0) {
221 len = sizeof(struct sockaddr_in6); 221 len = sizeof(struct sockaddr_in6);
222 family = AF_INET6; 222 family = AF_INET6;
223 } else 223 } else
224#endif 224#endif
225 { 225 {
226 fd = xsocket(AF_INET, SOCK_STREAM, 0); 226 fd = xsocket(AF_INET, sock_type, 0);
227 } 227 }
228 lsa = xzalloc(offsetof(len_and_sockaddr, sa) + len); 228 lsa = xzalloc(offsetof(len_and_sockaddr, sa) + len);
229 lsa->len = len; 229 lsa->len = len;
@@ -232,7 +232,12 @@ int xsocket_stream(len_and_sockaddr **lsap)
232 return fd; 232 return fd;
233} 233}
234 234
235int create_and_bind_stream_or_die(const char *bindaddr, int port) 235int xsocket_stream(len_and_sockaddr **lsap)
236{
237 return xsocket_type(lsap, SOCK_STREAM);
238}
239
240static int create_and_bind_or_die(const char *bindaddr, int port, int sock_type)
236{ 241{
237 int fd; 242 int fd;
238 len_and_sockaddr *lsa; 243 len_and_sockaddr *lsa;
@@ -240,9 +245,9 @@ int create_and_bind_stream_or_die(const char *bindaddr, int port)
240 if (bindaddr && bindaddr[0]) { 245 if (bindaddr && bindaddr[0]) {
241 lsa = xdotted2sockaddr(bindaddr, port); 246 lsa = xdotted2sockaddr(bindaddr, port);
242 /* user specified bind addr dictates family */ 247 /* user specified bind addr dictates family */
243 fd = xsocket(lsa->sa.sa_family, SOCK_STREAM, 0); 248 fd = xsocket(lsa->sa.sa_family, sock_type, 0);
244 } else { 249 } else {
245 fd = xsocket_stream(&lsa); 250 fd = xsocket_type(&lsa, sock_type);
246 set_nport(lsa, htons(port)); 251 set_nport(lsa, htons(port));
247 } 252 }
248 setsockopt_reuseaddr(fd); 253 setsockopt_reuseaddr(fd);
@@ -251,6 +256,17 @@ int create_and_bind_stream_or_die(const char *bindaddr, int port)
251 return fd; 256 return fd;
252} 257}
253 258
259int create_and_bind_stream_or_die(const char *bindaddr, int port)
260{
261 return create_and_bind_or_die(bindaddr, port, SOCK_STREAM);
262}
263
264int create_and_bind_dgram_or_die(const char *bindaddr, int port)
265{
266 return create_and_bind_or_die(bindaddr, port, SOCK_DGRAM);
267}
268
269
254int create_and_connect_stream_or_die(const char *peer, int port) 270int create_and_connect_stream_or_die(const char *peer, int port)
255{ 271{
256 int fd; 272 int fd;