mirror of
https://github.com/sheumann/hush.git
synced 2025-01-03 00:31:16 +00:00
traceroute: simplify code a bit
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
6ccaa23f2b
commit
c14bf21332
@ -472,16 +472,14 @@ send_probe(int seq, int ttl)
|
|||||||
} else
|
} else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
#if defined(IP_TTL)
|
#if defined IP_TTL
|
||||||
if (setsockopt(sndsock, IPPROTO_IP, IP_TTL,
|
res = setsockopt(sndsock, IPPROTO_IP, IP_TTL, &ttl, sizeof(ttl));
|
||||||
(char *)&ttl, sizeof(ttl)) < 0) {
|
if (res < 0)
|
||||||
bb_perror_msg_and_die("setsockopt ttl %d", ttl);
|
bb_perror_msg_and_die("setsockopt ttl %d", ttl);
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
out = outicmp;
|
||||||
len = packlen - sizeof(*outip);
|
len = packlen - sizeof(*outip);
|
||||||
if (option_mask32 & OPT_USE_ICMP)
|
if (!(option_mask32 & OPT_USE_ICMP)) {
|
||||||
out = outicmp;
|
|
||||||
else {
|
|
||||||
out = outdata;
|
out = outdata;
|
||||||
len -= sizeof(*outudp);
|
len -= sizeof(*outudp);
|
||||||
set_nport(dest_lsa, htons(port + seq));
|
set_nport(dest_lsa, htons(port + seq));
|
||||||
@ -489,9 +487,8 @@ send_probe(int seq, int ttl)
|
|||||||
}
|
}
|
||||||
|
|
||||||
res = xsendto(sndsock, out, len, &dest_lsa->u.sa, dest_lsa->len);
|
res = xsendto(sndsock, out, len, &dest_lsa->u.sa, dest_lsa->len);
|
||||||
if (res != len) {
|
if (res != len)
|
||||||
bb_info_msg("sent %d octets, ret=%d", len, res);
|
bb_info_msg("sent %d octets, ret=%d", len, res);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if ENABLE_FEATURE_TRACEROUTE_VERBOSE
|
#if ENABLE_FEATURE_TRACEROUTE_VERBOSE
|
||||||
@ -797,7 +794,7 @@ common_traceroute_main(int op, char **argv)
|
|||||||
int lsrr = 0;
|
int lsrr = 0;
|
||||||
#endif
|
#endif
|
||||||
#if ENABLE_TRACEROUTE6
|
#if ENABLE_TRACEROUTE6
|
||||||
sa_family_t af = AF_UNSPEC;
|
sa_family_t af;
|
||||||
#else
|
#else
|
||||||
enum { af = AF_INET };
|
enum { af = AF_INET };
|
||||||
#endif
|
#endif
|
||||||
@ -863,31 +860,26 @@ common_traceroute_main(int op, char **argv)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Process destination and optional packet size */
|
||||||
|
minpacket = sizeof(*outip) + SIZEOF_ICMP_HDR + sizeof(*outdata) + optlen;
|
||||||
|
if (!(op & OPT_USE_ICMP))
|
||||||
|
minpacket += sizeof(*outudp) - SIZEOF_ICMP_HDR;
|
||||||
#if ENABLE_TRACEROUTE6
|
#if ENABLE_TRACEROUTE6
|
||||||
|
af = AF_UNSPEC;
|
||||||
if (op & OPT_IPV4)
|
if (op & OPT_IPV4)
|
||||||
af = AF_INET;
|
af = AF_INET;
|
||||||
if (op & OPT_IPV6) {
|
if (op & OPT_IPV6)
|
||||||
af = AF_INET6;
|
af = AF_INET6;
|
||||||
minpacket = sizeof(struct outdata6_t);
|
|
||||||
} else
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
minpacket = sizeof(*outip) + SIZEOF_ICMP_HDR
|
|
||||||
+ sizeof(*outdata) + optlen;
|
|
||||||
if (!(op & OPT_USE_ICMP))
|
|
||||||
minpacket += sizeof(*outudp) - SIZEOF_ICMP_HDR;
|
|
||||||
}
|
|
||||||
packlen = minpacket;
|
|
||||||
|
|
||||||
/* Process destination and optional packet size */
|
|
||||||
if (argv[1])
|
|
||||||
packlen = xatoul_range(argv[1], minpacket, 32 * 1024);
|
|
||||||
#if ENABLE_TRACEROUTE6
|
|
||||||
dest_lsa = xhost_and_af2sockaddr(argv[0], port, af);
|
dest_lsa = xhost_and_af2sockaddr(argv[0], port, af);
|
||||||
af = dest_lsa->u.sa.sa_family;
|
af = dest_lsa->u.sa.sa_family;
|
||||||
|
if (af == AF_INET6)
|
||||||
|
minpacket = sizeof(struct outdata6_t);
|
||||||
#else
|
#else
|
||||||
dest_lsa = xhost2sockaddr(argv[0], port);
|
dest_lsa = xhost2sockaddr(argv[0], port);
|
||||||
#endif
|
#endif
|
||||||
|
packlen = minpacket;
|
||||||
|
if (argv[1])
|
||||||
|
packlen = xatoul_range(argv[1], minpacket, 32 * 1024);
|
||||||
|
|
||||||
/* Ensure the socket fds won't be 0, 1 or 2 */
|
/* Ensure the socket fds won't be 0, 1 or 2 */
|
||||||
bb_sanitize_stdio();
|
bb_sanitize_stdio();
|
||||||
|
Loading…
Reference in New Issue
Block a user