aboutsummaryrefslogtreecommitdiff
path: root/ipsvd
diff options
context:
space:
mode:
authorBernhard Reutner-Fischer <rep.dot.nop@gmail.com>2008-01-29 10:33:34 +0000
committerBernhard Reutner-Fischer <rep.dot.nop@gmail.com>2008-01-29 10:33:34 +0000
commit8c69afd992d7cc6c2fc7dea59c3c2bd3f3c21f15 (patch)
tree998a337ecd57b737423a3793365519213f97da72 /ipsvd
parentc882f341cec8451ee87af6746abb7208272d5b1a (diff)
downloadbusybox-w32-8c69afd992d7cc6c2fc7dea59c3c2bd3f3c21f15.tar.gz
busybox-w32-8c69afd992d7cc6c2fc7dea59c3c2bd3f3c21f15.tar.bz2
busybox-w32-8c69afd992d7cc6c2fc7dea59c3c2bd3f3c21f15.zip
- be C99 friendly. Anonymous unions are a GNU extension. This change is
size-neutral WRT -std=gnu99 and fixes several compilation errors for strict C99 mode.
Diffstat (limited to 'ipsvd')
-rw-r--r--ipsvd/tcpudp.c38
1 files changed, 19 insertions, 19 deletions
diff --git a/ipsvd/tcpudp.c b/ipsvd/tcpudp.c
index 6187eb985..dc61d6f76 100644
--- a/ipsvd/tcpudp.c
+++ b/ipsvd/tcpudp.c
@@ -254,10 +254,10 @@ int tcpudpsvd_main(int argc, char **argv)
254 254
255 local_port = bb_lookup_port(argv[1], tcp ? "tcp" : "udp", 0); 255 local_port = bb_lookup_port(argv[1], tcp ? "tcp" : "udp", 0);
256 lsa = xhost2sockaddr(argv[0], local_port); 256 lsa = xhost2sockaddr(argv[0], local_port);
257 sock = xsocket(lsa->sa.sa_family, tcp ? SOCK_STREAM : SOCK_DGRAM, 0); 257 sock = xsocket(lsa->u.sa.sa_family, tcp ? SOCK_STREAM : SOCK_DGRAM, 0);
258 setsockopt_reuseaddr(sock); 258 setsockopt_reuseaddr(sock);
259 sa_len = lsa->len; /* I presume sockaddr len stays the same */ 259 sa_len = lsa->len; /* I presume sockaddr len stays the same */
260 xbind(sock, &lsa->sa, sa_len); 260 xbind(sock, &lsa->u.sa, sa_len);
261 if (tcp) 261 if (tcp)
262 xlisten(sock, backlog); 262 xlisten(sock, backlog);
263 else /* udp: needed for recv_from_to to work: */ 263 else /* udp: needed for recv_from_to to work: */
@@ -273,7 +273,7 @@ int tcpudpsvd_main(int argc, char **argv)
273#endif 273#endif
274 274
275 if (verbose) { 275 if (verbose) {
276 char *addr = xmalloc_sockaddr2dotted(&lsa->sa); 276 char *addr = xmalloc_sockaddr2dotted(&lsa->u.sa);
277 printf("%s: info: listening on %s", applet_name, addr); 277 printf("%s: info: listening on %s", applet_name, addr);
278 free(addr); 278 free(addr);
279#ifndef SSLSVD 279#ifndef SSLSVD
@@ -299,12 +299,12 @@ int tcpudpsvd_main(int argc, char **argv)
299 sig_unblock(SIGCHLD); 299 sig_unblock(SIGCHLD);
300 if (tcp) { 300 if (tcp) {
301 remote.len = sa_len; 301 remote.len = sa_len;
302 conn = accept(sock, &remote.sa, &remote.len); 302 conn = accept(sock, &remote.u.sa, &remote.len);
303 } else { 303 } else {
304 /* In case recv_from_to won't be able to recover local addr. 304 /* In case recv_from_to won't be able to recover local addr.
305 * Also sets port - recv_from_to is unable to do it. */ 305 * Also sets port - recv_from_to is unable to do it. */
306 local = *lsa; 306 local = *lsa;
307 conn = recv_from_to(sock, NULL, 0, MSG_PEEK, &remote.sa, &local.sa, sa_len); 307 conn = recv_from_to(sock, NULL, 0, MSG_PEEK, &remote.u.sa, &local.u.sa, sa_len);
308 } 308 }
309 sig_block(SIGCHLD); 309 sig_block(SIGCHLD);
310 if (conn < 0) { 310 if (conn < 0) {
@@ -317,7 +317,7 @@ int tcpudpsvd_main(int argc, char **argv)
317 if (max_per_host) { 317 if (max_per_host) {
318 /* Drop connection immediately if cur_per_host > max_per_host 318 /* Drop connection immediately if cur_per_host > max_per_host
319 * (minimizing load under SYN flood) */ 319 * (minimizing load under SYN flood) */
320 remote_ip = xmalloc_sockaddr2dotted_noport(&remote.sa); 320 remote_ip = xmalloc_sockaddr2dotted_noport(&remote.u.sa);
321 cur_per_host = ipsvd_perhost_add(remote_ip, max_per_host, &hccp); 321 cur_per_host = ipsvd_perhost_add(remote_ip, max_per_host, &hccp);
322 if (cur_per_host > max_per_host) { 322 if (cur_per_host > max_per_host) {
323 /* ipsvd_perhost_add detected that max is exceeded 323 /* ipsvd_perhost_add detected that max is exceeded
@@ -342,14 +342,14 @@ int tcpudpsvd_main(int argc, char **argv)
342 /* Make plain write/send work for this socket by supplying default 342 /* Make plain write/send work for this socket by supplying default
343 * destination address. This also restricts incoming packets 343 * destination address. This also restricts incoming packets
344 * to ones coming from this remote IP. */ 344 * to ones coming from this remote IP. */
345 xconnect(0, &remote.sa, sa_len); 345 xconnect(0, &remote.u.sa, sa_len);
346 /* hole? at this point we have no wildcard udp socket... 346 /* hole? at this point we have no wildcard udp socket...
347 * can this cause clients to get "port unreachable" icmp? 347 * can this cause clients to get "port unreachable" icmp?
348 * Yup, time window is very small, but it exists (is it?) */ 348 * Yup, time window is very small, but it exists (is it?) */
349 /* Open new non-connected UDP socket for further clients */ 349 /* Open new non-connected UDP socket for further clients */
350 sock = xsocket(lsa->sa.sa_family, tcp ? SOCK_STREAM : SOCK_DGRAM, 0); 350 sock = xsocket(lsa->u.sa.sa_family, tcp ? SOCK_STREAM : SOCK_DGRAM, 0);
351 setsockopt_reuseaddr(sock); 351 setsockopt_reuseaddr(sock);
352 xbind(sock, &lsa->sa, sa_len); 352 xbind(sock, &lsa->u.sa, sa_len);
353 socket_want_pktinfo(sock); 353 socket_want_pktinfo(sock);
354 354
355 /* Doesn't work: 355 /* Doesn't work:
@@ -358,16 +358,16 @@ int tcpudpsvd_main(int argc, char **argv)
358 * instead - it will "intercept" all following packets, but child 358 * instead - it will "intercept" all following packets, but child
359 * does not expect data coming *from fd #1*! */ 359 * does not expect data coming *from fd #1*! */
360#if 0 360#if 0
361 /* Make it so that local addr is fixed to localp->sa 361 /* Make it so that local addr is fixed to localp->u.sa
362 * and we don't accidentally accept packets to other local IPs. */ 362 * and we don't accidentally accept packets to other local IPs. */
363 /* NB: we possibly bind to the _very_ same_ address & port as the one 363 /* NB: we possibly bind to the _very_ same_ address & port as the one
364 * already bound in parent! This seems to work in Linux. 364 * already bound in parent! This seems to work in Linux.
365 * (otherwise we can move socket to fd #0 only if bind succeeds) */ 365 * (otherwise we can move socket to fd #0 only if bind succeeds) */
366 close(0); 366 close(0);
367 set_nport(localp, htons(local_port)); 367 set_nport(localp, htons(local_port));
368 xmove_fd(xsocket(localp->sa.sa_family, SOCK_DGRAM, 0), 0); 368 xmove_fd(xsocket(localp->u.sa.sa_family, SOCK_DGRAM, 0), 0);
369 setsockopt_reuseaddr(0); /* crucial */ 369 setsockopt_reuseaddr(0); /* crucial */
370 xbind(0, &localp->sa, localp->len); 370 xbind(0, &localp->u.sa, localp->len);
371#endif 371#endif
372 } 372 }
373 373
@@ -395,11 +395,11 @@ int tcpudpsvd_main(int argc, char **argv)
395 close(sock); 395 close(sock);
396 396
397 if (need_remote_ip) 397 if (need_remote_ip)
398 remote_addr = xmalloc_sockaddr2dotted(&remote.sa); 398 remote_addr = xmalloc_sockaddr2dotted(&remote.u.sa);
399 399
400 if (need_hostnames) { 400 if (need_hostnames) {
401 if (option_mask32 & OPT_h) { 401 if (option_mask32 & OPT_h) {
402 remote_hostname = xmalloc_sockaddr2host_noport(&remote.sa); 402 remote_hostname = xmalloc_sockaddr2host_noport(&remote.u.sa);
403 if (!remote_hostname) { 403 if (!remote_hostname) {
404 bb_error_msg("warning: cannot look up hostname for %s", remote_addr); 404 bb_error_msg("warning: cannot look up hostname for %s", remote_addr);
405 remote_hostname = (char*)""; 405 remote_hostname = (char*)"";
@@ -410,11 +410,11 @@ int tcpudpsvd_main(int argc, char **argv)
410 * which doesn't know local IP). */ 410 * which doesn't know local IP). */
411 if (tcp) { 411 if (tcp) {
412 local.len = sa_len; 412 local.len = sa_len;
413 getsockname(0, &local.sa, &local.len); 413 getsockname(0, &local.u.sa, &local.len);
414 } 414 }
415 local_addr = xmalloc_sockaddr2dotted(&local.sa); 415 local_addr = xmalloc_sockaddr2dotted(&local.u.sa);
416 if (!local_hostname) { 416 if (!local_hostname) {
417 local_hostname = xmalloc_sockaddr2host_noport(&local.sa); 417 local_hostname = xmalloc_sockaddr2host_noport(&local.u.sa);
418 if (!local_hostname) 418 if (!local_hostname)
419 bb_error_msg_and_die("warning: cannot look up hostname for %s"+9, local_addr); 419 bb_error_msg_and_die("warning: cannot look up hostname for %s"+9, local_addr);
420 } 420 }
@@ -440,8 +440,8 @@ int tcpudpsvd_main(int argc, char **argv)
440 * from Linux firewall. Useful when you redirect 440 * from Linux firewall. Useful when you redirect
441 * an outbond connection to local handler, and it needs 441 * an outbond connection to local handler, and it needs
442 * to know where it originally tried to connect */ 442 * to know where it originally tried to connect */
443 if (tcp && getsockopt(0, SOL_IP, SO_ORIGINAL_DST, &lsa->sa, &lsa->len) == 0) { 443 if (tcp && getsockopt(0, SOL_IP, SO_ORIGINAL_DST, &lsa->u.sa, &lsa->len) == 0) {
444 char *addr = xmalloc_sockaddr2dotted(&lsa->sa); 444 char *addr = xmalloc_sockaddr2dotted(&lsa->u.sa);
445 xsetenv("TCPORIGDSTADDR", addr); 445 xsetenv("TCPORIGDSTADDR", addr);
446 free(addr); 446 free(addr);
447 } 447 }