Changeset 3621 in MondoRescue for branches/3.3/mindi-busybox/networking/traceroute.c
- Timestamp:
- Dec 20, 2016, 4:07:32 PM (7 years ago)
- Location:
- branches/3.3
- Files:
-
- 1 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/3.3/mindi-busybox/networking/traceroute.c
r3232 r3621 212 212 213 213 //usage:#define traceroute_trivial_usage 214 //usage: "[-"IF_TRACEROUTE6("46")"FIldnrv] [-f 1ST_TTL] [-m MAXTTL] [-p PORT] [-q PROBES]\n" 215 //usage: " [-s SRC_IP] [-t TOS] [-w WAIT_SEC] [-g GATEWAY] [-i IFACE]\n" 214 //usage: "[-"IF_TRACEROUTE6("46")"FIlnrv] [-f 1ST_TTL] [-m MAXTTL] [-q PROBES] [-p PORT]\n" 215 //usage: " [-t TOS] [-w WAIT_SEC]" 216 //usage: IF_FEATURE_TRACEROUTE_SOURCE_ROUTE(" [-g GATEWAY]")" [-s SRC_IP] [-i IFACE]\n" 216 217 //usage: " [-z PAUSE_MSEC] HOST [BYTES]" 217 218 //usage:#define traceroute_full_usage "\n\n" … … 220 221 //usage: "\n -4,-6 Force IP or IPv6 name resolution" 221 222 //usage: ) 222 //usage: "\n -F Set the don't fragment bit" 223 //usage: "\n -F Set don't fragment bit" 224 //usage: IF_FEATURE_TRACEROUTE_USE_ICMP( 223 225 //usage: "\n -I Use ICMP ECHO instead of UDP datagrams" 224 //usage: "\n -l Display the TTL value of the returned packet" 225 //usage: "\n -d Set SO_DEBUG options to socket" 226 //usage: ) 227 //usage: "\n -l Display TTL value of the returned packet" 228 //Currently disabled (TRACEROUTE_SO_DEBUG==0) 229 ////usage: "\n -d Set SO_DEBUG options to socket" 226 230 //usage: "\n -n Print numeric addresses" 227 231 //usage: "\n -r Bypass routing tables, send directly to HOST" 232 //usage: IF_FEATURE_TRACEROUTE_VERBOSE( 228 233 //usage: "\n -v Verbose" 229 //usage: "\n -m Max time-to-live (max number of hops)" 230 //usage: "\n -p Base UDP port number used in probes" 234 //usage: ) 235 //usage: "\n -f N First number of hops (default 1)" 236 //usage: "\n -m N Max number of hops" 237 //usage: "\n -q N Number of probes per hop (default 3)" 238 //usage: "\n -p N Base UDP port number used in probes" 231 239 //usage: "\n (default 33434)" 232 //usage: "\n - q Number of probes per TTL (default 3)"233 //usage: "\n - s IP address to use as the source address"234 //usage: "\n -t Type-of-service in probe packets (default 0)"235 //usage: "\n -w Time in secondsto wait for a response (default 3)"236 //usage: "\n -g Loose source route gateway (8 max)"240 //usage: "\n -s IP Source address" 241 //usage: "\n -i IFACE Source interface" 242 //usage: "\n -t N Type-of-service in probe packets (default 0)" 243 //usage: "\n -w SEC Time to wait for a response (default 3)" 244 //usage: "\n -g IP Loose source route gateway (8 max)" 237 245 //usage: 238 246 //usage:#define traceroute6_trivial_usage 239 //usage: "[- dnrv] [-m MAXTTL] [-p PORT] [-q PROBES]\n"240 //usage: " [- s SRC_IP] [-t TOS] [-w WAIT_SEC] [-i IFACE]\n"247 //usage: "[-nrv] [-m MAXTTL] [-q PROBES] [-p PORT]\n" 248 //usage: " [-t TOS] [-w WAIT_SEC] [-s SRC_IP] [-i IFACE]\n" 241 249 //usage: " HOST [BYTES]" 242 250 //usage:#define traceroute6_full_usage "\n\n" 243 251 //usage: "Trace the route to HOST\n" 244 //usage: "\n -d Set SO_DEBUG options to socket" 252 //Currently disabled (TRACEROUTE_SO_DEBUG==0) 253 ////usage: "\n -d Set SO_DEBUG options to socket" 245 254 //usage: "\n -n Print numeric addresses" 246 255 //usage: "\n -r Bypass routing tables, send directly to HOST" 256 //usage: IF_FEATURE_TRACEROUTE_VERBOSE( 247 257 //usage: "\n -v Verbose" 248 //usage: "\n -m Max time-to-live (max number of hops)" 249 //usage: "\n -p Base UDP port number used in probes" 250 //usage: "\n (default is 33434)" 251 //usage: "\n -q Number of probes per TTL (default 3)" 252 //usage: "\n -s IP address to use as the source address" 253 //usage: "\n -t Type-of-service in probe packets (default 0)" 254 //usage: "\n -w Time in seconds to wait for a response (default 3)" 258 //usage: ) 259 //usage: "\n -m N Max number of hops" 260 //usage: "\n -q N Number of probes per hop (default 3)" 261 //usage: "\n -p N Base UDP port number used in probes" 262 //usage: "\n (default 33434)" 263 //usage: "\n -s IP Source address" 264 //usage: "\n -i IFACE Source interface" 265 //usage: "\n -t N Type-of-service in probe packets (default 0)" 266 //usage: "\n -w SEC Time wait for a response (default 3)" 255 267 256 268 #define TRACEROUTE_SO_DEBUG 0 257 258 /* TODO: undefs were uncommented - ??! we have config system for that! */259 /* probably ok to remove altogether */260 //#undef CONFIG_FEATURE_TRACEROUTE_VERBOSE261 //#define CONFIG_FEATURE_TRACEROUTE_VERBOSE262 //#undef CONFIG_FEATURE_TRACEROUTE_SOURCE_ROUTE263 //#define CONFIG_FEATURE_TRACEROUTE_SOURCE_ROUTE264 //#undef CONFIG_FEATURE_TRACEROUTE_USE_ICMP265 //#define CONFIG_FEATURE_TRACEROUTE_USE_ICMP266 267 269 268 270 #include <net/if.h> … … 388 390 389 391 390 /* libbb candidate? tftp uses this idiom too */391 static len_and_sockaddr* dup_sockaddr(const len_and_sockaddr *lsa)392 {393 len_and_sockaddr *new_lsa = xzalloc(LSA_LEN_SIZE + lsa->len);394 memcpy(new_lsa, lsa, LSA_LEN_SIZE + lsa->len);395 return new_lsa;396 }397 398 399 392 static int 400 393 wait_for_reply(len_and_sockaddr *from_lsa, struct sockaddr *to, unsigned *timestamp_us, int *left_ms) … … 481 474 #if ENABLE_TRACEROUTE6 482 475 if (dest_lsa->u.sa.sa_family == AF_INET6) { 483 res = setsockopt (sndsock, SOL_IPV6, IPV6_UNICAST_HOPS, &ttl, sizeof(ttl));484 if (res <0)485 bb_perror_msg_and_die("setsockopt UNICAST_HOPS %d", ttl);476 res = setsockopt_int(sndsock, SOL_IPV6, IPV6_UNICAST_HOPS, ttl); 477 if (res != 0) 478 bb_perror_msg_and_die("setsockopt(%s) %d", "UNICAST_HOPS", ttl); 486 479 out = outip; 487 480 len = packlen; … … 490 483 { 491 484 #if defined IP_TTL 492 res = setsockopt (sndsock, IPPROTO_IP, IP_TTL, &ttl, sizeof(ttl));493 if (res <0)494 bb_perror_msg_and_die("setsockopt ttl %d", ttl);485 res = setsockopt_int(sndsock, IPPROTO_IP, IP_TTL, ttl); 486 if (res != 0) 487 bb_perror_msg_and_die("setsockopt(%s) %d", "TTL", ttl); 495 488 #endif 496 489 out = outicmp; … … 505 498 res = xsendto(sndsock, out, len, &dest_lsa->u.sa, dest_lsa->len); 506 499 if (res != len) 507 bb_ info_msg("sent %d octets, ret=%d", len, res);500 bb_error_msg("sent %d octets, ret=%d", len, res); 508 501 } 509 502 … … 792 785 { 793 786 int minpacket; 787 #ifdef IP_TOS 794 788 int tos = 0; 789 #endif 795 790 int max_ttl = 30; 796 791 int nprobes = 3; … … 806 801 char *pausemsecs_str; 807 802 char *first_ttl_str; 803 char *dest_str; 808 804 #if ENABLE_FEATURE_TRACEROUTE_SOURCE_ROUTE 809 805 llist_t *source_route_list = NULL; … … 838 834 bb_error_msg("warning: ip checksums disabled"); 839 835 #endif 836 #ifdef IP_TOS 840 837 if (op & OPT_TOS) 841 838 tos = xatou_range(tos_str, 0, 255); 839 #endif 842 840 if (op & OPT_MAX_TTL) 843 841 max_ttl = xatou_range(max_ttl_str, 1, 255); … … 905 903 xmove_fd(xsocket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6), rcvsock); 906 904 # ifdef IPV6_RECVPKTINFO 907 setsockopt(rcvsock, SOL_IPV6, IPV6_RECVPKTINFO, 908 &const_int_1, sizeof(const_int_1)); 909 setsockopt(rcvsock, SOL_IPV6, IPV6_2292PKTINFO, 910 &const_int_1, sizeof(const_int_1)); 905 setsockopt_1(rcvsock, SOL_IPV6, IPV6_RECVPKTINFO); 906 setsockopt_1(rcvsock, SOL_IPV6, IPV6_2292PKTINFO); 911 907 # else 912 setsockopt(rcvsock, SOL_IPV6, IPV6_PKTINFO, 913 &const_int_1, sizeof(const_int_1)); 908 setsockopt_1(rcvsock, SOL_IPV6, IPV6_PKTINFO); 914 909 # endif 915 910 } else … … 921 916 #if TRACEROUTE_SO_DEBUG 922 917 if (op & OPT_DEBUG) 923 setsockopt(rcvsock, SOL_SOCKET, SO_DEBUG, 924 &const_int_1, sizeof(const_int_1)); 918 setsockopt_SOL_SOCKET_1(rcvsock, SO_DEBUG); 925 919 #endif 926 920 if (op & OPT_BYPASS_ROUTE) 927 setsockopt(rcvsock, SOL_SOCKET, SO_DONTROUTE, 928 &const_int_1, sizeof(const_int_1)); 921 setsockopt_SOL_SOCKET_1(rcvsock, SO_DONTROUTE); 929 922 930 923 #if ENABLE_TRACEROUTE6 931 924 if (af == AF_INET6) { 932 static const int two = 2; 933 if (setsockopt(rcvsock, SOL_RAW, IPV6_CHECKSUM, &two, sizeof(two)) < 0) 934 bb_perror_msg_and_die("setsockopt RAW_CHECKSUM"); 925 if (setsockopt_int(rcvsock, SOL_RAW, IPV6_CHECKSUM, 2) != 0) 926 bb_perror_msg_and_die("setsockopt(%s)", "IPV6_CHECKSUM"); 935 927 xmove_fd(xsocket(af, SOCK_DGRAM, 0), sndsock); 936 928 } else … … 969 961 970 962 #ifdef SO_SNDBUF 971 if (setsockopt (sndsock, SOL_SOCKET, SO_SNDBUF, &packlen, sizeof(packlen)) <0) {972 bb_perror_msg_and_die(" SO_SNDBUF");963 if (setsockopt_SOL_SOCKET_int(sndsock, SO_SNDBUF, packlen) != 0) { 964 bb_perror_msg_and_die("setsockopt(%s)", "SO_SNDBUF"); 973 965 } 974 966 #endif 975 967 #ifdef IP_TOS 976 if ((op & OPT_TOS) && setsockopt (sndsock, IPPROTO_IP, IP_TOS, &tos, sizeof(tos)) <0) {977 bb_perror_msg_and_die("setsockopt tos %d", tos);968 if ((op & OPT_TOS) && setsockopt_int(sndsock, IPPROTO_IP, IP_TOS, tos) != 0) { 969 bb_perror_msg_and_die("setsockopt(%s) %d", "TOS", tos); 978 970 } 979 971 #endif 980 972 #ifdef IP_DONTFRAG 981 973 if (op & OPT_DONT_FRAGMNT) 982 setsockopt(sndsock, IPPROTO_IP, IP_DONTFRAG, 983 &const_int_1, sizeof(const_int_1)); 974 setsockopt_1(sndsock, IPPROTO_IP, IP_DONTFRAG); 984 975 #endif 985 976 #if TRACEROUTE_SO_DEBUG 986 977 if (op & OPT_DEBUG) 987 setsockopt(sndsock, SOL_SOCKET, SO_DEBUG, 988 &const_int_1, sizeof(const_int_1)); 978 setsockopt_SOL_SOCKET_1(sndsock, SO_DEBUG); 989 979 #endif 990 980 if (op & OPT_BYPASS_ROUTE) 991 setsockopt(sndsock, SOL_SOCKET, SO_DONTROUTE, 992 &const_int_1, sizeof(const_int_1)); 981 setsockopt_SOL_SOCKET_1(sndsock, SO_DONTROUTE); 993 982 994 983 outip = xzalloc(packlen); … … 1060 1049 xsetuid(getuid()); 1061 1050 1062 printf("traceroute to %s (%s)", argv[0], 1063 xmalloc_sockaddr2dotted_noport(&dest_lsa->u.sa)); 1051 dest_str = xmalloc_sockaddr2dotted_noport(&dest_lsa->u.sa); 1052 printf("traceroute to %s (%s)", argv[0], dest_str); 1053 if (ENABLE_FEATURE_CLEAN_UP) { 1054 free(dest_str); 1055 } 1056 1064 1057 if (op & OPT_SOURCE) 1065 1058 printf(" from %s", source); 1066 1059 printf(", %d hops max, %d byte packets\n", max_ttl, packlen); 1067 1060 1068 from_lsa = dup_sockaddr(dest_lsa);1061 from_lsa = xmemdup(dest_lsa, LSA_LEN_SIZE + dest_lsa->len); 1069 1062 lastaddr = xzalloc(dest_lsa->len); 1070 1063 to = xzalloc(dest_lsa->len); … … 1217 1210 } 1218 1211 1212 if (ENABLE_FEATURE_CLEAN_UP) { 1213 free(to); 1214 free(lastaddr); 1215 free(from_lsa); 1216 } 1217 1219 1218 return 0; 1220 1219 }
Note:
See TracChangeset
for help on using the changeset viewer.