diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2006-10-08 12:49:22 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2006-10-08 12:49:22 +0000 |
commit | 1385899416a4396385ad421ae1f532be7103738a (patch) | |
tree | fc4d14a910593d1235318bb36abe5e9f72d2039e /networking/traceroute.c | |
parent | 5625415085e68ac5e150f54e685417c866620d76 (diff) | |
download | busybox-w32-1385899416a4396385ad421ae1f532be7103738a.tar.gz busybox-w32-1385899416a4396385ad421ae1f532be7103738a.tar.bz2 busybox-w32-1385899416a4396385ad421ae1f532be7103738a.zip |
attempt to regularize atoi mess.
Diffstat (limited to 'networking/traceroute.c')
-rw-r--r-- | networking/traceroute.c | 74 |
1 files changed, 22 insertions, 52 deletions
diff --git a/networking/traceroute.c b/networking/traceroute.c index 4af523625..84ce8ae69 100644 --- a/networking/traceroute.c +++ b/networking/traceroute.c | |||
@@ -416,7 +416,7 @@ ifaddrlist(struct IFADDRLIST **ipaddrp) | |||
416 | ++al; | 416 | ++al; |
417 | ++nipaddr; | 417 | ++nipaddr; |
418 | } | 418 | } |
419 | if(nipaddr == 0) | 419 | if (nipaddr == 0) |
420 | bb_error_msg_and_die ("Can't find any network interfaces"); | 420 | bb_error_msg_and_die ("Can't find any network interfaces"); |
421 | (void)close(fd); | 421 | (void)close(fd); |
422 | 422 | ||
@@ -494,34 +494,6 @@ findsaddr(const struct sockaddr_in *to, struct sockaddr_in *from) | |||
494 | 494 | ||
495 | */ | 495 | */ |
496 | 496 | ||
497 | /* String to value with optional min and max. Handles decimal and hex. */ | ||
498 | static int | ||
499 | str2val(const char *str, const char *what, int mi, int ma) | ||
500 | { | ||
501 | const char *cp; | ||
502 | int val; | ||
503 | char *ep; | ||
504 | |||
505 | if (str[0] == '0' && (str[1] == 'x' || str[1] == 'X')) { | ||
506 | cp = str + 2; | ||
507 | val = (int)strtol(cp, &ep, 16); | ||
508 | } else | ||
509 | val = (int)strtol(str, &ep, 10); | ||
510 | if (*ep != '\0') { | ||
511 | bb_error_msg_and_die("\"%s\" bad value for %s", str, what); | ||
512 | } | ||
513 | if (val < mi && mi >= 0) { | ||
514 | if (mi == 0) | ||
515 | bb_error_msg_and_die("%s must be >= %d", what, mi); | ||
516 | else | ||
517 | bb_error_msg_and_die("%s must be > %d", what, mi - 1); | ||
518 | } | ||
519 | if (val > ma && ma >= 0) | ||
520 | bb_error_msg_and_die("%s must be <= %d", what, ma); | ||
521 | return val; | ||
522 | } | ||
523 | |||
524 | |||
525 | /* | 497 | /* |
526 | * Subtract 2 timeval structs: out = out - in. | 498 | * Subtract 2 timeval structs: out = out - in. |
527 | * Out is assumed to be >= in. | 499 | * Out is assumed to be >= in. |
@@ -828,7 +800,7 @@ inetname(struct sockaddr_in *from) | |||
828 | char name[257]; | 800 | char name[257]; |
829 | 801 | ||
830 | if (!nflag && from->sin_addr.s_addr != INADDR_ANY) { | 802 | if (!nflag && from->sin_addr.s_addr != INADDR_ANY) { |
831 | if(INET_rresolve(name, sizeof(name), from, 0x4000, 0xffffffff) >= 0) | 803 | if (INET_rresolve(name, sizeof(name), from, 0x4000, 0xffffffff) >= 0) |
832 | n = name; | 804 | n = name; |
833 | } | 805 | } |
834 | ina = inet_ntoa(from->sin_addr); | 806 | ina = inet_ntoa(from->sin_addr); |
@@ -974,7 +946,7 @@ traceroute_main(int argc, char *argv[]) | |||
974 | #endif | 946 | #endif |
975 | ); | 947 | ); |
976 | 948 | ||
977 | if(op & USAGE_OP_DONT_FRAGMNT) | 949 | if (op & USAGE_OP_DONT_FRAGMNT) |
978 | off = IP_DF; | 950 | off = IP_DF; |
979 | #ifdef CONFIG_FEATURE_TRACEROUTE_USE_ICMP | 951 | #ifdef CONFIG_FEATURE_TRACEROUTE_USE_ICMP |
980 | useicmp = op & USAGE_OP_USE_ICMP; | 952 | useicmp = op & USAGE_OP_USE_ICMP; |
@@ -983,34 +955,34 @@ traceroute_main(int argc, char *argv[]) | |||
983 | #ifdef CONFIG_FEATURE_TRACEROUTE_VERBOSE | 955 | #ifdef CONFIG_FEATURE_TRACEROUTE_VERBOSE |
984 | verbose = op & USAGE_OP_VERBOSE; | 956 | verbose = op & USAGE_OP_VERBOSE; |
985 | #endif | 957 | #endif |
986 | if(op & USAGE_OP_IP_CHKSUM) { | 958 | if (op & USAGE_OP_IP_CHKSUM) { |
987 | doipcksum = 0; | 959 | doipcksum = 0; |
988 | bb_error_msg("Warning: ip checksums disabled"); | 960 | bb_error_msg("warning: ip checksums disabled"); |
989 | } | 961 | } |
990 | if (tos_str) | 962 | if (tos_str) |
991 | tos = str2val(tos_str, "tos", 0, 255); | 963 | tos = xatoul_range(tos_str, 0, 255); |
992 | if(max_ttl_str) | 964 | if (max_ttl_str) |
993 | max_ttl = str2val(max_ttl_str, "max ttl", 1, 255); | 965 | max_ttl = xatoul_range(max_ttl_str, 1, 255); |
994 | if(port_str) | 966 | if (port_str) |
995 | port = (u_short)str2val(port_str, "port", 1, (1 << 16) - 1); | 967 | port = xatou16(port_str); |
996 | if(nprobes_str) | 968 | if (nprobes_str) |
997 | nprobes = str2val(nprobes_str, "nprobes", 1, -1); | 969 | nprobes = xatoul_range(nprobes_str, 1, INT_MAX); |
998 | if(source) { | 970 | if (source) { |
999 | /* | 971 | /* |
1000 | * set the ip source address of the outbound | 972 | * set the ip source address of the outbound |
1001 | * probe (e.g., on a multi-homed host). | 973 | * probe (e.g., on a multi-homed host). |
1002 | */ | 974 | */ |
1003 | if (getuid()) bb_error_msg_and_die("-s %s: permission denied", source); | 975 | if (getuid()) bb_error_msg_and_die("-s %s: permission denied", source); |
1004 | } | 976 | } |
1005 | if(waittime_str) | 977 | if (waittime_str) |
1006 | waittime = str2val(waittime_str, "wait time", 2, 24 * 60 * 60); | 978 | waittime = xatoul_range(waittime_str, 2, 24 * 60 * 60); |
1007 | if(pausemsecs_str) | 979 | if (pausemsecs_str) |
1008 | pausemsecs = str2val(pausemsecs_str, "pause msecs", 0, 60 * 60 * 1000); | 980 | pausemsecs = xatoul_range(pausemsecs_str, 0, 60 * 60 * 1000); |
1009 | if(first_ttl_str) | 981 | if (first_ttl_str) |
1010 | first_ttl = str2val(first_ttl_str, "first ttl", 1, 255); | 982 | first_ttl = xatoul_range(first_ttl_str, 1, 255); |
1011 | 983 | ||
1012 | #ifdef CONFIG_FEATURE_TRACEROUTE_SOURCE_ROUTE | 984 | #ifdef CONFIG_FEATURE_TRACEROUTE_SOURCE_ROUTE |
1013 | if(sourse_route_list) { | 985 | if (sourse_route_list) { |
1014 | llist_t *l_sr; | 986 | llist_t *l_sr; |
1015 | 987 | ||
1016 | for(l_sr = sourse_route_list; l_sr; ) { | 988 | for(l_sr = sourse_route_list; l_sr; ) { |
@@ -1046,8 +1018,7 @@ traceroute_main(int argc, char *argv[]) | |||
1046 | switch (argc - optind) { | 1018 | switch (argc - optind) { |
1047 | 1019 | ||
1048 | case 2: | 1020 | case 2: |
1049 | packlen = str2val(argv[optind + 1], | 1021 | packlen = xatoul_range(argv[optind + 1], minpacket, maxpacket); |
1050 | "packet length", minpacket, maxpacket); | ||
1051 | /* Fall through */ | 1022 | /* Fall through */ |
1052 | 1023 | ||
1053 | case 1: | 1024 | case 1: |
@@ -1055,8 +1026,7 @@ traceroute_main(int argc, char *argv[]) | |||
1055 | hi = gethostinfo(hostname); | 1026 | hi = gethostinfo(hostname); |
1056 | setsin(to, hi->addrs[0]); | 1027 | setsin(to, hi->addrs[0]); |
1057 | if (hi->n > 1) | 1028 | if (hi->n > 1) |
1058 | bb_error_msg( | 1029 | bb_error_msg("warning: %s has multiple addresses; using %s", |
1059 | "Warning: %s has multiple addresses; using %s", | ||
1060 | hostname, inet_ntoa(to->sin_addr)); | 1030 | hostname, inet_ntoa(to->sin_addr)); |
1061 | hostname = hi->name; | 1031 | hostname = hi->name; |
1062 | hi->name = NULL; | 1032 | hi->name = NULL; |