aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2009-11-24 02:17:13 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2009-11-24 02:17:13 +0100
commitc14bf213320500ab733da5cd2b5dc1d16efa5051 (patch)
tree70c9608365c144794a06667a72ca192f20d2ba6c
parent6ccaa23f2be25b3e1ff4c6f5f9bef69a4cb36f8c (diff)
downloadbusybox-w32-c14bf213320500ab733da5cd2b5dc1d16efa5051.tar.gz
busybox-w32-c14bf213320500ab733da5cd2b5dc1d16efa5051.tar.bz2
busybox-w32-c14bf213320500ab733da5cd2b5dc1d16efa5051.zip
traceroute: simplify code a bit
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--networking/traceroute.c44
1 files changed, 18 insertions, 26 deletions
diff --git a/networking/traceroute.c b/networking/traceroute.c
index 18a8c25d4..0555c9b47 100644
--- a/networking/traceroute.c
+++ b/networking/traceroute.c
@@ -472,16 +472,14 @@ send_probe(int seq, int ttl)
472 } else 472 } else
473#endif 473#endif
474 { 474 {
475#if defined(IP_TTL) 475#if defined IP_TTL
476 if (setsockopt(sndsock, IPPROTO_IP, IP_TTL, 476 res = setsockopt(sndsock, IPPROTO_IP, IP_TTL, &ttl, sizeof(ttl));
477 (char *)&ttl, sizeof(ttl)) < 0) { 477 if (res < 0)
478 bb_perror_msg_and_die("setsockopt ttl %d", ttl); 478 bb_perror_msg_and_die("setsockopt ttl %d", ttl);
479 }
480#endif 479#endif
480 out = outicmp;
481 len = packlen - sizeof(*outip); 481 len = packlen - sizeof(*outip);
482 if (option_mask32 & OPT_USE_ICMP) 482 if (!(option_mask32 & OPT_USE_ICMP)) {
483 out = outicmp;
484 else {
485 out = outdata; 483 out = outdata;
486 len -= sizeof(*outudp); 484 len -= sizeof(*outudp);
487 set_nport(dest_lsa, htons(port + seq)); 485 set_nport(dest_lsa, htons(port + seq));
@@ -489,9 +487,8 @@ send_probe(int seq, int ttl)
489 } 487 }
490 488
491 res = xsendto(sndsock, out, len, &dest_lsa->u.sa, dest_lsa->len); 489 res = xsendto(sndsock, out, len, &dest_lsa->u.sa, dest_lsa->len);
492 if (res != len) { 490 if (res != len)
493 bb_info_msg("sent %d octets, ret=%d", len, res); 491 bb_info_msg("sent %d octets, ret=%d", len, res);
494 }
495} 492}
496 493
497#if ENABLE_FEATURE_TRACEROUTE_VERBOSE 494#if ENABLE_FEATURE_TRACEROUTE_VERBOSE
@@ -797,7 +794,7 @@ common_traceroute_main(int op, char **argv)
797 int lsrr = 0; 794 int lsrr = 0;
798#endif 795#endif
799#if ENABLE_TRACEROUTE6 796#if ENABLE_TRACEROUTE6
800 sa_family_t af = AF_UNSPEC; 797 sa_family_t af;
801#else 798#else
802 enum { af = AF_INET }; 799 enum { af = AF_INET };
803#endif 800#endif
@@ -863,31 +860,26 @@ common_traceroute_main(int op, char **argv)
863 } 860 }
864#endif 861#endif
865 862
863 /* Process destination and optional packet size */
864 minpacket = sizeof(*outip) + SIZEOF_ICMP_HDR + sizeof(*outdata) + optlen;
865 if (!(op & OPT_USE_ICMP))
866 minpacket += sizeof(*outudp) - SIZEOF_ICMP_HDR;
866#if ENABLE_TRACEROUTE6 867#if ENABLE_TRACEROUTE6
868 af = AF_UNSPEC;
867 if (op & OPT_IPV4) 869 if (op & OPT_IPV4)
868 af = AF_INET; 870 af = AF_INET;
869 if (op & OPT_IPV6) { 871 if (op & OPT_IPV6)
870 af = AF_INET6; 872 af = AF_INET6;
871 minpacket = sizeof(struct outdata6_t);
872 } else
873#endif
874 {
875 minpacket = sizeof(*outip) + SIZEOF_ICMP_HDR
876 + sizeof(*outdata) + optlen;
877 if (!(op & OPT_USE_ICMP))
878 minpacket += sizeof(*outudp) - SIZEOF_ICMP_HDR;
879 }
880 packlen = minpacket;
881
882 /* Process destination and optional packet size */
883 if (argv[1])
884 packlen = xatoul_range(argv[1], minpacket, 32 * 1024);
885#if ENABLE_TRACEROUTE6
886 dest_lsa = xhost_and_af2sockaddr(argv[0], port, af); 873 dest_lsa = xhost_and_af2sockaddr(argv[0], port, af);
887 af = dest_lsa->u.sa.sa_family; 874 af = dest_lsa->u.sa.sa_family;
875 if (af == AF_INET6)
876 minpacket = sizeof(struct outdata6_t);
888#else 877#else
889 dest_lsa = xhost2sockaddr(argv[0], port); 878 dest_lsa = xhost2sockaddr(argv[0], port);
890#endif 879#endif
880 packlen = minpacket;
881 if (argv[1])
882 packlen = xatoul_range(argv[1], minpacket, 32 * 1024);
891 883
892 /* Ensure the socket fds won't be 0, 1 or 2 */ 884 /* Ensure the socket fds won't be 0, 1 or 2 */
893 bb_sanitize_stdio(); 885 bb_sanitize_stdio();