diff options
author | vda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2006-10-08 12:49:22 +0000 |
---|---|---|
committer | vda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2006-10-08 12:49:22 +0000 |
commit | 87d25a2b8535dc627a02eb539fa3946be2a24647 (patch) | |
tree | fc4d14a910593d1235318bb36abe5e9f72d2039e /networking | |
parent | 81177b14907e73f11560f69e0b4ec34371f1a7d5 (diff) | |
download | busybox-w32-87d25a2b8535dc627a02eb539fa3946be2a24647.tar.gz busybox-w32-87d25a2b8535dc627a02eb539fa3946be2a24647.tar.bz2 busybox-w32-87d25a2b8535dc627a02eb539fa3946be2a24647.zip |
attempt to regularize atoi mess.
git-svn-id: svn://busybox.net/trunk/busybox@16342 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'networking')
-rw-r--r-- | networking/arping.c | 8 | ||||
-rw-r--r-- | networking/ftpgetput.c | 14 | ||||
-rw-r--r-- | networking/httpd.c | 2 | ||||
-rw-r--r-- | networking/ifconfig.c | 3 | ||||
-rw-r--r-- | networking/inetd.c | 29 | ||||
-rw-r--r-- | networking/interface.c | 2 | ||||
-rw-r--r-- | networking/ipcalc.c | 48 | ||||
-rw-r--r-- | networking/nc.c | 22 | ||||
-rw-r--r-- | networking/ping.c | 16 | ||||
-rw-r--r-- | networking/ping6.c | 16 | ||||
-rw-r--r-- | networking/route.c | 14 | ||||
-rw-r--r-- | networking/telnetd.c | 4 | ||||
-rw-r--r-- | networking/tftp.c | 4 | ||||
-rw-r--r-- | networking/traceroute.c | 74 | ||||
-rw-r--r-- | networking/udhcp/dhcpc.c | 4 | ||||
-rw-r--r-- | networking/udhcp/files.c | 8 | ||||
-rw-r--r-- | networking/vconfig.c | 10 | ||||
-rw-r--r-- | networking/wget.c | 10 |
18 files changed, 119 insertions, 169 deletions
diff --git a/networking/arping.c b/networking/arping.c index 1ff6f90be..b9605985c 100644 --- a/networking/arping.c +++ b/networking/arping.c | |||
@@ -41,8 +41,8 @@ enum cfg_e { | |||
41 | static int cfg; | 41 | static int cfg; |
42 | 42 | ||
43 | static int s; | 43 | static int s; |
44 | static int count = -1; | 44 | static unsigned count = UINT_MAX; |
45 | static int timeout; | 45 | static unsigned timeout; |
46 | static int sent; | 46 | static int sent; |
47 | static int brd_sent; | 47 | static int brd_sent; |
48 | static int received; | 48 | static int received; |
@@ -276,9 +276,9 @@ int arping_main(int argc, char **argv) | |||
276 | &_count, &_timeout, &device, &source); | 276 | &_count, &_timeout, &device, &source); |
277 | cfg |= opt & 0x3f; /* set respective flags */ | 277 | cfg |= opt & 0x3f; /* set respective flags */ |
278 | if (opt & 0x40) /* -c: count */ | 278 | if (opt & 0x40) /* -c: count */ |
279 | count = atoi(_count); | 279 | count = xatou(_count); |
280 | if (opt & 0x80) /* -w: timeout */ | 280 | if (opt & 0x80) /* -w: timeout */ |
281 | timeout = atoi(_timeout); | 281 | timeout = xatoul_range(_timeout, 0, INT_MAX/2000); |
282 | if (opt & 0x100) { /* -i: interface */ | 282 | if (opt & 0x100) { /* -i: interface */ |
283 | if (strlen(device) > IF_NAMESIZE) { | 283 | if (strlen(device) > IF_NAMESIZE) { |
284 | bb_error_msg_and_die("interface name '%s' is too long", | 284 | bb_error_msg_and_die("interface name '%s' is too long", |
diff --git a/networking/ftpgetput.c b/networking/ftpgetput.c index 492854153..902528f93 100644 --- a/networking/ftpgetput.c +++ b/networking/ftpgetput.c | |||
@@ -42,15 +42,15 @@ static int ftpcmd(const char *s1, const char *s2, FILE *stream, char *buf) | |||
42 | char *buf_ptr; | 42 | char *buf_ptr; |
43 | 43 | ||
44 | if (fgets(buf, 510, stream) == NULL) { | 44 | if (fgets(buf, 510, stream) == NULL) { |
45 | bb_perror_msg_and_die("fgets()"); | 45 | bb_perror_msg_and_die("fgets"); |
46 | } | 46 | } |
47 | buf_ptr = strstr(buf, "\r\n"); | 47 | buf_ptr = strstr(buf, "\r\n"); |
48 | if (buf_ptr) { | 48 | if (buf_ptr) { |
49 | *buf_ptr = '\0'; | 49 | *buf_ptr = '\0'; |
50 | } | 50 | } |
51 | } while (! isdigit(buf[0]) || buf[3] != ' '); | 51 | } while (!isdigit(buf[0]) || buf[3] != ' '); |
52 | 52 | ||
53 | return atoi(buf); | 53 | return xatou(buf); |
54 | } | 54 | } |
55 | 55 | ||
56 | static int xconnect_ftpdata(ftp_host_info_t *server, const char *buf) | 56 | static int xconnect_ftpdata(ftp_host_info_t *server, const char *buf) |
@@ -60,14 +60,14 @@ static int xconnect_ftpdata(ftp_host_info_t *server, const char *buf) | |||
60 | 60 | ||
61 | buf_ptr = strrchr(buf, ','); | 61 | buf_ptr = strrchr(buf, ','); |
62 | *buf_ptr = '\0'; | 62 | *buf_ptr = '\0'; |
63 | port_num = atoi(buf_ptr + 1); | 63 | port_num = xatoul_range(buf_ptr + 1, 0, 255); |
64 | 64 | ||
65 | buf_ptr = strrchr(buf, ','); | 65 | buf_ptr = strrchr(buf, ','); |
66 | *buf_ptr = '\0'; | 66 | *buf_ptr = '\0'; |
67 | port_num += atoi(buf_ptr + 1) * 256; | 67 | port_num += xatoul_range(buf_ptr + 1, 0, 255) * 256; |
68 | 68 | ||
69 | server->s_in->sin_port=htons(port_num); | 69 | server->s_in->sin_port = htons(port_num); |
70 | return(xconnect(server->s_in)); | 70 | return xconnect(server->s_in); |
71 | } | 71 | } |
72 | 72 | ||
73 | static FILE *ftp_login(ftp_host_info_t *server) | 73 | static FILE *ftp_login(ftp_host_info_t *server) |
diff --git a/networking/httpd.c b/networking/httpd.c index 0e471ba58..f3fe49cae 100644 --- a/networking/httpd.c +++ b/networking/httpd.c | |||
@@ -1951,7 +1951,7 @@ int httpd_main(int argc, char *argv[]) | |||
1951 | #endif | 1951 | #endif |
1952 | #if ENABLE_FEATURE_HTTPD_WITHOUT_INETD | 1952 | #if ENABLE_FEATURE_HTTPD_WITHOUT_INETD |
1953 | if (opt & OPT_PORT) | 1953 | if (opt & OPT_PORT) |
1954 | config->port = bb_xgetlarg(s_port, 10, 1, 0xffff); | 1954 | config->port = xatou16(s_port); |
1955 | #if ENABLE_FEATURE_HTTPD_SETUID | 1955 | #if ENABLE_FEATURE_HTTPD_SETUID |
1956 | if (opt & OPT_SETUID) { | 1956 | if (opt & OPT_SETUID) { |
1957 | char *e; | 1957 | char *e; |
diff --git a/networking/ifconfig.c b/networking/ifconfig.c index 4d346c47f..59b6f0acc 100644 --- a/networking/ifconfig.c +++ b/networking/ifconfig.c | |||
@@ -379,7 +379,8 @@ int ifconfig_main(int argc, char **argv) | |||
379 | 379 | ||
380 | safe_strncpy(host, *argv, (sizeof host)); | 380 | safe_strncpy(host, *argv, (sizeof host)); |
381 | #ifdef CONFIG_FEATURE_IPV6 | 381 | #ifdef CONFIG_FEATURE_IPV6 |
382 | if ((prefix = strchr(host, '/'))) { | 382 | prefix = strchr(host, '/'); |
383 | if (prefix) { | ||
383 | if (safe_strtoi(prefix + 1, &prefix_len) || | 384 | if (safe_strtoi(prefix + 1, &prefix_len) || |
384 | (prefix_len < 0) || (prefix_len > 128)) | 385 | (prefix_len < 0) || (prefix_len > 128)) |
385 | { | 386 | { |
diff --git a/networking/inetd.c b/networking/inetd.c index e22115a5c..966425385 100644 --- a/networking/inetd.c +++ b/networking/inetd.c | |||
@@ -149,8 +149,6 @@ | |||
149 | #define _PATH_INETDPID "/var/run/inetd.pid" | 149 | #define _PATH_INETDPID "/var/run/inetd.pid" |
150 | 150 | ||
151 | 151 | ||
152 | #define TOOMANY 0 /* don't start more than TOOMANY */ | ||
153 | |||
154 | #define CNT_INTVL 60 /* servers in CNT_INTVL sec. */ | 152 | #define CNT_INTVL 60 /* servers in CNT_INTVL sec. */ |
155 | #define RETRYTIME (60*10) /* retry after bind or server fail */ | 153 | #define RETRYTIME (60*10) /* retry after bind or server fail */ |
156 | 154 | ||
@@ -297,7 +295,7 @@ static const struct builtin builtins[] = { | |||
297 | static int global_queuelen = 128; | 295 | static int global_queuelen = 128; |
298 | static int nsock, maxsock; | 296 | static int nsock, maxsock; |
299 | static fd_set allsock; | 297 | static fd_set allsock; |
300 | static int toomany = TOOMANY; | 298 | static int toomany; |
301 | static int timingout; | 299 | static int timingout; |
302 | static struct servent *sp; | 300 | static struct servent *sp; |
303 | static uid_t uid; | 301 | static uid_t uid; |
@@ -588,10 +586,10 @@ static servtab_t *getconfigent(void) | |||
588 | sep = new_servtab(); | 586 | sep = new_servtab(); |
589 | 587 | ||
590 | /* memset(sep, 0, sizeof *sep); */ | 588 | /* memset(sep, 0, sizeof *sep); */ |
591 | more: | 589 | more: |
592 | /* freeconfig(sep); */ | 590 | /* freeconfig(sep); */ |
593 | 591 | ||
594 | while ((cp = nextline()) && *cp == '#'); | 592 | while ((cp = nextline()) && *cp == '#') /* skip comment line */; |
595 | if (cp == NULL) { | 593 | if (cp == NULL) { |
596 | /* free(sep); */ | 594 | /* free(sep); */ |
597 | return NULL; | 595 | return NULL; |
@@ -680,7 +678,7 @@ more: | |||
680 | } else if (*ccp != '\0') | 678 | } else if (*ccp != '\0') |
681 | goto badafterall; | 679 | goto badafterall; |
682 | #else | 680 | #else |
683 | bb_error_msg("%s: rpc services not supported", sep->se_service); | 681 | bb_error_msg("%s: rpc services not supported", sep->se_service); |
684 | #endif | 682 | #endif |
685 | } | 683 | } |
686 | } | 684 | } |
@@ -692,7 +690,7 @@ more: | |||
692 | char *s = strchr(arg, '.'); | 690 | char *s = strchr(arg, '.'); |
693 | if (s) { | 691 | if (s) { |
694 | *s++ = '\0'; | 692 | *s++ = '\0'; |
695 | sep->se_max = atoi(s); | 693 | sep->se_max = xatoi(s); |
696 | } else | 694 | } else |
697 | sep->se_max = toomany; | 695 | sep->se_max = toomany; |
698 | } | 696 | } |
@@ -928,7 +926,7 @@ static void config(int sig ATTRIBUTE_UNUSED) | |||
928 | */ | 926 | */ |
929 | if ( | 927 | if ( |
930 | #ifdef INETD_FEATURE_ENABLED | 928 | #ifdef INETD_FEATURE_ENABLED |
931 | cp->se_bi == 0 && | 929 | cp->se_bi == 0 && |
932 | #endif | 930 | #endif |
933 | (sep->se_wait == 1 || cp->se_wait == 0)) | 931 | (sep->se_wait == 1 || cp->se_wait == 0)) |
934 | sep->se_wait = cp->se_wait; | 932 | sep->se_wait = cp->se_wait; |
@@ -974,7 +972,7 @@ static void config(int sig ATTRIBUTE_UNUSED) | |||
974 | #ifdef CONFIG_FEATURE_INETD_RPC | 972 | #ifdef CONFIG_FEATURE_INETD_RPC |
975 | if (isrpcservice(sep)) { | 973 | if (isrpcservice(sep)) { |
976 | struct rpcent *rp; | 974 | struct rpcent *rp; |
977 | 975 | // FIXME: atoi_or_else(str, 0) would be handy here | |
978 | sep->se_rpcprog = atoi(sep->se_service); | 976 | sep->se_rpcprog = atoi(sep->se_service); |
979 | if (sep->se_rpcprog == 0) { | 977 | if (sep->se_rpcprog == 0) { |
980 | rp = getrpcbyname(sep->se_service); | 978 | rp = getrpcbyname(sep->se_service); |
@@ -990,9 +988,9 @@ static void config(int sig ATTRIBUTE_UNUSED) | |||
990 | register_rpc(sep); | 988 | register_rpc(sep); |
991 | } else | 989 | } else |
992 | #endif | 990 | #endif |
993 | { | 991 | { |
994 | u_short port = htons(atoi(sep->se_service)); | 992 | u_short port = htons(atoi(sep->se_service)); |
995 | 993 | // FIXME: atoi_or_else(str, 0) would be handy here | |
996 | if (!port) { | 994 | if (!port) { |
997 | /*XXX*/ strncpy(protoname, sep->se_proto, sizeof(protoname)); | 995 | /*XXX*/ strncpy(protoname, sep->se_proto, sizeof(protoname)); |
998 | if (isdigit(protoname[strlen(protoname) - 1])) | 996 | if (isdigit(protoname[strlen(protoname) - 1])) |
@@ -1255,13 +1253,7 @@ inetd_main(int argc, char *argv[]) | |||
1255 | 1253 | ||
1256 | opt = getopt32(argc, argv, "R:f", &stoomany); | 1254 | opt = getopt32(argc, argv, "R:f", &stoomany); |
1257 | if(opt & 1) { | 1255 | if(opt & 1) { |
1258 | char *e; | 1256 | toomany = xatoi_u(stoomany); |
1259 | |||
1260 | toomany = strtoul(stoomany, &e, 0); | ||
1261 | if (!(toomany >= 0 && *e == '\0')) { | ||
1262 | toomany = TOOMANY; | ||
1263 | bb_perror_msg("-R %s: bad value for service invocation rate", stoomany); | ||
1264 | } | ||
1265 | } | 1257 | } |
1266 | argc -= optind; | 1258 | argc -= optind; |
1267 | argv += optind; | 1259 | argv += optind; |
@@ -1317,7 +1309,6 @@ inetd_main(int argc, char *argv[]) | |||
1317 | sigaddset(&sa.sa_mask, SIGHUP); | 1309 | sigaddset(&sa.sa_mask, SIGHUP); |
1318 | sa.sa_handler = retry; | 1310 | sa.sa_handler = retry; |
1319 | sigaction(SIGALRM, &sa, NULL); | 1311 | sigaction(SIGALRM, &sa, NULL); |
1320 | /* doconfig(); */ | ||
1321 | config(SIGHUP); | 1312 | config(SIGHUP); |
1322 | sa.sa_handler = config; | 1313 | sa.sa_handler = config; |
1323 | sigaction(SIGHUP, &sa, NULL); | 1314 | sigaction(SIGHUP, &sa, NULL); |
diff --git a/networking/interface.c b/networking/interface.c index c3cc7c0bc..8e2498d27 100644 --- a/networking/interface.c +++ b/networking/interface.c | |||
@@ -363,7 +363,7 @@ static int nstrcmp(const char *a, const char *b) | |||
363 | } | 363 | } |
364 | 364 | ||
365 | if (isdigit(*a) && isdigit(*b)) { | 365 | if (isdigit(*a) && isdigit(*b)) { |
366 | return atoi(a_ptr) > atoi(b_ptr) ? 1 : -1; | 366 | return xatoul(a_ptr) > xatoul(b_ptr) ? 1 : -1; |
367 | } | 367 | } |
368 | return *a - *b; | 368 | return *a - *b; |
369 | } | 369 | } |
diff --git a/networking/ipcalc.c b/networking/ipcalc.c index 576dfc853..909373cbb 100644 --- a/networking/ipcalc.c +++ b/networking/ipcalc.c | |||
@@ -18,8 +18,6 @@ | |||
18 | #include <sys/socket.h> | 18 | #include <sys/socket.h> |
19 | #include <arpa/inet.h> | 19 | #include <arpa/inet.h> |
20 | 20 | ||
21 | #define IPCALC_MSG(CMD,ALTCMD) if (mode & SILENT) {ALTCMD;} else {CMD;} | ||
22 | |||
23 | #define CLASS_A_NETMASK ntohl(0xFF000000) | 21 | #define CLASS_A_NETMASK ntohl(0xFF000000) |
24 | #define CLASS_B_NETMASK ntohl(0xFFFF0000) | 22 | #define CLASS_B_NETMASK ntohl(0xFFFF0000) |
25 | #define CLASS_C_NETMASK ntohl(0xFFFFFF00) | 23 | #define CLASS_C_NETMASK ntohl(0xFFFFFF00) |
@@ -56,6 +54,7 @@ static int get_prefix(unsigned long netmask) | |||
56 | int get_prefix(unsigned long netmask); | 54 | int get_prefix(unsigned long netmask); |
57 | #endif | 55 | #endif |
58 | 56 | ||
57 | |||
59 | #define NETMASK 0x01 | 58 | #define NETMASK 0x01 |
60 | #define BROADCAST 0x02 | 59 | #define BROADCAST 0x02 |
61 | #define NETWORK 0x04 | 60 | #define NETWORK 0x04 |
@@ -78,12 +77,9 @@ int get_prefix(unsigned long netmask); | |||
78 | #else | 77 | #else |
79 | #define long_options 0 | 78 | #define long_options 0 |
80 | #endif | 79 | #endif |
81 | |||
82 | |||
83 | |||
84 | int ipcalc_main(int argc, char **argv) | 80 | int ipcalc_main(int argc, char **argv) |
85 | { | 81 | { |
86 | unsigned long mode; | 82 | unsigned opt; |
87 | int have_netmask = 0; | 83 | int have_netmask = 0; |
88 | in_addr_t netmask, broadcast, network, ipaddr; | 84 | in_addr_t netmask, broadcast, network, ipaddr; |
89 | struct in_addr a; | 85 | struct in_addr a; |
@@ -92,17 +88,18 @@ int ipcalc_main(int argc, char **argv) | |||
92 | if (ENABLE_FEATURE_IPCALC_LONG_OPTIONS) | 88 | if (ENABLE_FEATURE_IPCALC_LONG_OPTIONS) |
93 | applet_long_options = long_options; | 89 | applet_long_options = long_options; |
94 | 90 | ||
95 | mode = getopt32(argc, argv, "mbn" USE_FEATURE_IPCALC_FANCY("phs")); | 91 | opt = getopt32(argc, argv, "mbn" USE_FEATURE_IPCALC_FANCY("phs")); |
96 | |||
97 | argc -= optind; | 92 | argc -= optind; |
98 | argv += optind; | 93 | argv += optind; |
99 | if (mode & (BROADCAST | NETWORK | NETPREFIX)) { | 94 | if (opt & (BROADCAST | NETWORK | NETPREFIX)) { |
100 | if (argc > 2 || argc <= 0) | 95 | if (argc > 2 || argc <= 0) |
101 | bb_show_usage(); | 96 | bb_show_usage(); |
102 | } else { | 97 | } else { |
103 | if (argc != 1) | 98 | if (argc != 1) |
104 | bb_show_usage(); | 99 | bb_show_usage(); |
105 | } | 100 | } |
101 | if (opt & SILENT) | ||
102 | logmode = LOGMODE_NONE; /* Suppress error_msg() output */ | ||
106 | 103 | ||
107 | ipstr = argv[0]; | 104 | ipstr = argv[0]; |
108 | if (ENABLE_FEATURE_IPCALC_FANCY) { | 105 | if (ENABLE_FEATURE_IPCALC_FANCY) { |
@@ -111,17 +108,13 @@ int ipcalc_main(int argc, char **argv) | |||
111 | 108 | ||
112 | prefixstr = ipstr; | 109 | prefixstr = ipstr; |
113 | 110 | ||
114 | while(*prefixstr) { | 111 | while (*prefixstr) { |
115 | if (*prefixstr == '/') { | 112 | if (*prefixstr == '/') { |
116 | *prefixstr = (char)0; | 113 | *prefixstr = (char)0; |
117 | prefixstr++; | 114 | prefixstr++; |
118 | if (*prefixstr) { | 115 | if (*prefixstr) { |
119 | unsigned int msk; | 116 | unsigned msk; |
120 | 117 | netprefix = xatoul_range(prefixstr, 0, 32); | |
121 | if (safe_strtoul(prefixstr, &netprefix) || netprefix > 32) { | ||
122 | IPCALC_MSG(bb_error_msg_and_die("bad IP prefix: %s", prefixstr), | ||
123 | exit(EXIT_FAILURE)); | ||
124 | } | ||
125 | netmask = 0; | 118 | netmask = 0; |
126 | msk = 0x80000000; | 119 | msk = 0x80000000; |
127 | while (netprefix > 0) { | 120 | while (netprefix > 0) { |
@@ -142,21 +135,18 @@ int ipcalc_main(int argc, char **argv) | |||
142 | ipaddr = inet_aton(ipstr, &a); | 135 | ipaddr = inet_aton(ipstr, &a); |
143 | 136 | ||
144 | if (ipaddr == 0) { | 137 | if (ipaddr == 0) { |
145 | IPCALC_MSG(bb_error_msg_and_die("bad IP address: %s", argv[0]), | 138 | bb_error_msg_and_die("bad IP address: %s", argv[0]); |
146 | exit(EXIT_FAILURE)); | ||
147 | } | 139 | } |
148 | ipaddr = a.s_addr; | 140 | ipaddr = a.s_addr; |
149 | 141 | ||
150 | if (argc == 2) { | 142 | if (argc == 2) { |
151 | if (ENABLE_FEATURE_IPCALC_FANCY && have_netmask) { | 143 | if (ENABLE_FEATURE_IPCALC_FANCY && have_netmask) { |
152 | IPCALC_MSG(bb_error_msg_and_die("Use prefix or netmask, not both"), | 144 | bb_error_msg_and_die("use prefix or netmask, not both"); |
153 | exit(EXIT_FAILURE)); | ||
154 | } | 145 | } |
155 | 146 | ||
156 | netmask = inet_aton(argv[1], &a); | 147 | netmask = inet_aton(argv[1], &a); |
157 | if (netmask == 0) { | 148 | if (netmask == 0) { |
158 | IPCALC_MSG(bb_error_msg_and_die("bad netmask: %s", argv[1]), | 149 | bb_error_msg_and_die("bad netmask: %s", argv[1]); |
159 | exit(EXIT_FAILURE)); | ||
160 | } | 150 | } |
161 | netmask = a.s_addr; | 151 | netmask = a.s_addr; |
162 | } else { | 152 | } else { |
@@ -166,34 +156,32 @@ int ipcalc_main(int argc, char **argv) | |||
166 | netmask = get_netmask(ipaddr); | 156 | netmask = get_netmask(ipaddr); |
167 | } | 157 | } |
168 | 158 | ||
169 | if (mode & NETMASK) { | 159 | if (opt & NETMASK) { |
170 | printf("NETMASK=%s\n", inet_ntoa((*(struct in_addr *) &netmask))); | 160 | printf("NETMASK=%s\n", inet_ntoa((*(struct in_addr *) &netmask))); |
171 | } | 161 | } |
172 | 162 | ||
173 | if (mode & BROADCAST) { | 163 | if (opt & BROADCAST) { |
174 | broadcast = (ipaddr & netmask) | ~netmask; | 164 | broadcast = (ipaddr & netmask) | ~netmask; |
175 | printf("BROADCAST=%s\n", inet_ntoa((*(struct in_addr *) &broadcast))); | 165 | printf("BROADCAST=%s\n", inet_ntoa((*(struct in_addr *) &broadcast))); |
176 | } | 166 | } |
177 | 167 | ||
178 | if (mode & NETWORK) { | 168 | if (opt & NETWORK) { |
179 | network = ipaddr & netmask; | 169 | network = ipaddr & netmask; |
180 | printf("NETWORK=%s\n", inet_ntoa((*(struct in_addr *) &network))); | 170 | printf("NETWORK=%s\n", inet_ntoa((*(struct in_addr *) &network))); |
181 | } | 171 | } |
182 | 172 | ||
183 | if (ENABLE_FEATURE_IPCALC_FANCY) { | 173 | if (ENABLE_FEATURE_IPCALC_FANCY) { |
184 | if (mode & NETPREFIX) { | 174 | if (opt & NETPREFIX) { |
185 | printf("PREFIX=%i\n", get_prefix(netmask)); | 175 | printf("PREFIX=%i\n", get_prefix(netmask)); |
186 | } | 176 | } |
187 | 177 | ||
188 | if (mode & HOSTNAME) { | 178 | if (opt & HOSTNAME) { |
189 | struct hostent *hostinfo; | 179 | struct hostent *hostinfo; |
190 | int x; | 180 | int x; |
191 | 181 | ||
192 | hostinfo = gethostbyaddr((char *) &ipaddr, sizeof(ipaddr), AF_INET); | 182 | hostinfo = gethostbyaddr((char *) &ipaddr, sizeof(ipaddr), AF_INET); |
193 | if (!hostinfo) { | 183 | if (!hostinfo) { |
194 | IPCALC_MSG(bb_herror_msg_and_die( | 184 | bb_herror_msg_and_die("cannot find hostname for %s", argv[0]); |
195 | "cannot find hostname for %s", argv[0]),); | ||
196 | exit(EXIT_FAILURE); | ||
197 | } | 185 | } |
198 | for (x = 0; hostinfo->h_name[x]; x++) { | 186 | for (x = 0; hostinfo->h_name[x]; x++) { |
199 | hostinfo->h_name[x] = tolower(hostinfo->h_name[x]); | 187 | hostinfo->h_name[x] = tolower(hostinfo->h_name[x]); |
diff --git a/networking/nc.c b/networking/nc.c index f8b3fb2dd..bde5e6600 100644 --- a/networking/nc.c +++ b/networking/nc.c | |||
@@ -11,13 +11,15 @@ | |||
11 | 11 | ||
12 | static void timeout(int signum) | 12 | static void timeout(int signum) |
13 | { | 13 | { |
14 | bb_error_msg_and_die("Timed out"); | 14 | bb_error_msg_and_die("timed out"); |
15 | } | 15 | } |
16 | 16 | ||
17 | int nc_main(int argc, char **argv) | 17 | int nc_main(int argc, char **argv) |
18 | { | 18 | { |
19 | int do_listen = 0, lport = 0, delay = 0, wsecs = 0, execflag = 0, opt, | 19 | int sfd = 0, cfd; |
20 | sfd = 0, cfd; | 20 | unsigned opt; |
21 | unsigned lport = 0, wsecs = 0, delay = 0; | ||
22 | unsigned do_listen = 0, execflag = 0; | ||
21 | struct sockaddr_in address; | 23 | struct sockaddr_in address; |
22 | struct hostent *hostinfo; | 24 | struct hostent *hostinfo; |
23 | fd_set readfds, testfds; | 25 | fd_set readfds, testfds; |
@@ -30,8 +32,8 @@ int nc_main(int argc, char **argv) | |||
30 | if (ENABLE_NC_SERVER && opt=='l') do_listen++; | 32 | if (ENABLE_NC_SERVER && opt=='l') do_listen++; |
31 | else if (ENABLE_NC_SERVER && opt=='p') | 33 | else if (ENABLE_NC_SERVER && opt=='p') |
32 | lport = bb_lookup_port(optarg, "tcp", 0); | 34 | lport = bb_lookup_port(optarg, "tcp", 0); |
33 | else if (ENABLE_NC_EXTRA && opt=='w') wsecs = atoi(optarg); | 35 | else if (ENABLE_NC_EXTRA && opt=='w') wsecs = xatou(optarg); |
34 | else if (ENABLE_NC_EXTRA && opt=='i') delay = atoi(optarg); | 36 | else if (ENABLE_NC_EXTRA && opt=='i') delay = xatou(optarg); |
35 | else if (ENABLE_NC_EXTRA && opt=='f') infile = optarg; | 37 | else if (ENABLE_NC_EXTRA && opt=='f') infile = optarg; |
36 | else if (ENABLE_NC_EXTRA && opt=='e' && optind!=argc) { | 38 | else if (ENABLE_NC_EXTRA && opt=='e' && optind!=argc) { |
37 | execflag++; | 39 | execflag++; |
@@ -40,11 +42,10 @@ int nc_main(int argc, char **argv) | |||
40 | } | 42 | } |
41 | } | 43 | } |
42 | 44 | ||
43 | |||
44 | // For listen or file we need zero arguments, dialout is 2. | 45 | // For listen or file we need zero arguments, dialout is 2. |
45 | // For exec we need at least one more argument at the end, more ok | 46 | // For exec we need at least one more argument at the end, more ok |
46 | 47 | ||
47 | opt = (do_listen || infile) ? 0 : 2 + execflag; | 48 | opt = (do_listen || infile) ? 0 : 2 + execflag; |
48 | if (execflag ? argc-optind < opt : argc-optind!=opt || | 49 | if (execflag ? argc-optind < opt : argc-optind!=opt || |
49 | (infile && do_listen)) | 50 | (infile && do_listen)) |
50 | bb_show_usage(); | 51 | bb_show_usage(); |
@@ -66,7 +67,6 @@ int nc_main(int argc, char **argv) | |||
66 | 67 | ||
67 | if (lport != 0) { | 68 | if (lport != 0) { |
68 | address.sin_port = lport; | 69 | address.sin_port = lport; |
69 | |||
70 | xbind(sfd, (struct sockaddr *) &address, sizeof(address)); | 70 | xbind(sfd, (struct sockaddr *) &address, sizeof(address)); |
71 | } | 71 | } |
72 | 72 | ||
@@ -83,7 +83,8 @@ int nc_main(int argc, char **argv) | |||
83 | fdprintf(2, "%d\n", SWAP_BE16(address.sin_port)); | 83 | fdprintf(2, "%d\n", SWAP_BE16(address.sin_port)); |
84 | } | 84 | } |
85 | repeatyness: | 85 | repeatyness: |
86 | if ((cfd = accept(sfd, (struct sockaddr *) &address, &addrlen)) < 0) | 86 | cfd = accept(sfd, (struct sockaddr *) &address, &addrlen); |
87 | if (cfd < 0) | ||
87 | bb_perror_msg_and_die("accept"); | 88 | bb_perror_msg_and_die("accept"); |
88 | 89 | ||
89 | if (!execflag) close(sfd); | 90 | if (!execflag) close(sfd); |
@@ -116,10 +117,11 @@ repeatyness: | |||
116 | 117 | ||
117 | // With more than one -l, repeatedly act as server. | 118 | // With more than one -l, repeatedly act as server. |
118 | 119 | ||
119 | if (do_listen>1 && vfork()) { | 120 | if (do_listen > 1 && vfork()) { |
120 | // This is a bit weird as cleanup goes, since we wind up with no | 121 | // This is a bit weird as cleanup goes, since we wind up with no |
121 | // stdin/stdout/stderr. But it's small and shouldn't hurt anything. | 122 | // stdin/stdout/stderr. But it's small and shouldn't hurt anything. |
122 | // We check for cfd == 0 above. | 123 | // We check for cfd == 0 above. |
124 | logmode = LOGMODE_NONE; | ||
123 | close(0); | 125 | close(0); |
124 | close(1); | 126 | close(1); |
125 | close(2); | 127 | close(2); |
diff --git a/networking/ping.c b/networking/ping.c index a81472f96..8ca8be9b9 100644 --- a/networking/ping.c +++ b/networking/ping.c | |||
@@ -157,9 +157,9 @@ int ping_main(int argc, char **argv) | |||
157 | static struct sockaddr_in pingaddr; | 157 | static struct sockaddr_in pingaddr; |
158 | static struct sockaddr_in sourceaddr; | 158 | static struct sockaddr_in sourceaddr; |
159 | static int pingsock = -1; | 159 | static int pingsock = -1; |
160 | static int datalen; /* intentionally uninitialized to work around gcc bug */ | 160 | static unsigned datalen; /* intentionally uninitialized to work around gcc bug */ |
161 | 161 | ||
162 | static long ntransmitted, nreceived, nrepeats, pingcount; | 162 | static unsigned long ntransmitted, nreceived, nrepeats, pingcount; |
163 | static int myid, options; | 163 | static int myid, options; |
164 | static unsigned long tmin = ULONG_MAX, tmax, tsum; | 164 | static unsigned long tmin = ULONG_MAX, tmax, tsum; |
165 | static char rcvd_tbl[MAX_DUP_CHK / 8]; | 165 | static char rcvd_tbl[MAX_DUP_CHK / 8]; |
@@ -179,12 +179,12 @@ static void pingstats(int junk) | |||
179 | signal(SIGINT, SIG_IGN); | 179 | signal(SIGINT, SIG_IGN); |
180 | 180 | ||
181 | printf("\n--- %s ping statistics ---\n", hostent->h_name); | 181 | printf("\n--- %s ping statistics ---\n", hostent->h_name); |
182 | printf("%ld packets transmitted, ", ntransmitted); | 182 | printf("%lu packets transmitted, ", ntransmitted); |
183 | printf("%ld packets received, ", nreceived); | 183 | printf("%lu packets received, ", nreceived); |
184 | if (nrepeats) | 184 | if (nrepeats) |
185 | printf("%ld duplicates, ", nrepeats); | 185 | printf("%lu duplicates, ", nrepeats); |
186 | if (ntransmitted) | 186 | if (ntransmitted) |
187 | printf("%ld%% packet loss\n", | 187 | printf("%lu%% packet loss\n", |
188 | (ntransmitted - nreceived) * 100 / ntransmitted); | 188 | (ntransmitted - nreceived) * 100 / ntransmitted); |
189 | if (nreceived) | 189 | if (nreceived) |
190 | printf("round-trip min/avg/max = %lu.%lu/%lu.%lu/%lu.%lu ms\n", | 190 | printf("round-trip min/avg/max = %lu.%lu/%lu.%lu/%lu.%lu ms\n", |
@@ -427,13 +427,13 @@ int ping_main(int argc, char **argv) | |||
427 | if (--argc <= 0) | 427 | if (--argc <= 0) |
428 | bb_show_usage(); | 428 | bb_show_usage(); |
429 | argv++; | 429 | argv++; |
430 | pingcount = atoi(*argv); | 430 | pingcount = xatoul(*argv); |
431 | break; | 431 | break; |
432 | case 's': | 432 | case 's': |
433 | if (--argc <= 0) | 433 | if (--argc <= 0) |
434 | bb_show_usage(); | 434 | bb_show_usage(); |
435 | argv++; | 435 | argv++; |
436 | datalen = atoi(*argv); | 436 | datalen = xatou16(*argv); |
437 | break; | 437 | break; |
438 | case 'I': | 438 | case 'I': |
439 | if (--argc <= 0) | 439 | if (--argc <= 0) |
diff --git a/networking/ping6.c b/networking/ping6.c index 6079c40d9..0d6a739bf 100644 --- a/networking/ping6.c +++ b/networking/ping6.c | |||
@@ -145,10 +145,10 @@ int ping6_main(int argc, char **argv) | |||
145 | /* full(er) version */ | 145 | /* full(er) version */ |
146 | static struct sockaddr_in6 pingaddr; | 146 | static struct sockaddr_in6 pingaddr; |
147 | static int pingsock = -1; | 147 | static int pingsock = -1; |
148 | static int datalen; /* intentionally uninitialized to work around gcc bug */ | 148 | static unsigned datalen; /* intentionally uninitialized to work around gcc bug */ |
149 | static int if_index; | 149 | static int if_index; |
150 | 150 | ||
151 | static long ntransmitted, nreceived, nrepeats, pingcount; | 151 | static unsigned long ntransmitted, nreceived, nrepeats, pingcount; |
152 | static int myid, options; | 152 | static int myid, options; |
153 | static unsigned long tmin = ULONG_MAX, tmax, tsum; | 153 | static unsigned long tmin = ULONG_MAX, tmax, tsum; |
154 | static char rcvd_tbl[MAX_DUP_CHK / 8]; | 154 | static char rcvd_tbl[MAX_DUP_CHK / 8]; |
@@ -168,12 +168,12 @@ static void pingstats(int junk) | |||
168 | signal(SIGINT, SIG_IGN); | 168 | signal(SIGINT, SIG_IGN); |
169 | 169 | ||
170 | printf("\n--- %s ping statistics ---\n", hostent->h_name); | 170 | printf("\n--- %s ping statistics ---\n", hostent->h_name); |
171 | printf("%ld packets transmitted, ", ntransmitted); | 171 | printf("%lu packets transmitted, ", ntransmitted); |
172 | printf("%ld packets received, ", nreceived); | 172 | printf("%lu packets received, ", nreceived); |
173 | if (nrepeats) | 173 | if (nrepeats) |
174 | printf("%ld duplicates, ", nrepeats); | 174 | printf("%lu duplicates, ", nrepeats); |
175 | if (ntransmitted) | 175 | if (ntransmitted) |
176 | printf("%ld%% packet loss\n", | 176 | printf("%lu%% packet loss\n", |
177 | (ntransmitted - nreceived) * 100 / ntransmitted); | 177 | (ntransmitted - nreceived) * 100 / ntransmitted); |
178 | if (nreceived) | 178 | if (nreceived) |
179 | printf("round-trip min/avg/max = %lu.%lu/%lu.%lu/%lu.%lu ms\n", | 179 | printf("round-trip min/avg/max = %lu.%lu/%lu.%lu/%lu.%lu ms\n", |
@@ -439,13 +439,13 @@ int ping6_main(int argc, char **argv) | |||
439 | if (--argc <= 0) | 439 | if (--argc <= 0) |
440 | bb_show_usage(); | 440 | bb_show_usage(); |
441 | argv++; | 441 | argv++; |
442 | pingcount = atoi(*argv); | 442 | pingcount = xatoul(*argv); |
443 | break; | 443 | break; |
444 | case 's': | 444 | case 's': |
445 | if (--argc <= 0) | 445 | if (--argc <= 0) |
446 | bb_show_usage(); | 446 | bb_show_usage(); |
447 | argv++; | 447 | argv++; |
448 | datalen = atoi(*argv); | 448 | datalen = xatou16(*argv); |
449 | break; | 449 | break; |
450 | case 'I': | 450 | case 'I': |
451 | if (--argc <= 0) | 451 | if (--argc <= 0) |
diff --git a/networking/route.c b/networking/route.c index 2e6e017b6..65b40fcd6 100644 --- a/networking/route.c +++ b/networking/route.c | |||
@@ -178,7 +178,7 @@ static void INET_setroute(int action, char **args) | |||
178 | if(prefix) { | 178 | if(prefix) { |
179 | int prefix_len; | 179 | int prefix_len; |
180 | 180 | ||
181 | prefix_len = bb_xgetularg10_bnd(prefix+1, 0, 32); | 181 | prefix_len = xatoul_range(prefix+1, 0, 32); |
182 | mask_in_addr(rt) = htonl( ~ (0xffffffffUL >> prefix_len)); | 182 | mask_in_addr(rt) = htonl( ~ (0xffffffffUL >> prefix_len)); |
183 | *prefix = '\0'; | 183 | *prefix = '\0'; |
184 | #if HAVE_NEW_ADDRT | 184 | #if HAVE_NEW_ADDRT |
@@ -218,7 +218,7 @@ static void INET_setroute(int action, char **args) | |||
218 | 218 | ||
219 | #if HAVE_NEW_ADDRT | 219 | #if HAVE_NEW_ADDRT |
220 | if (k == KW_IPVx_METRIC) { | 220 | if (k == KW_IPVx_METRIC) { |
221 | rt.rt_metric = bb_xgetularg10(args_m1) + 1; | 221 | rt.rt_metric = xatoul(args_m1) + 1; |
222 | continue; | 222 | continue; |
223 | } | 223 | } |
224 | #endif | 224 | #endif |
@@ -259,20 +259,20 @@ static void INET_setroute(int action, char **args) | |||
259 | 259 | ||
260 | if (k == KW_IPVx_MSS) { /* Check valid MSS bounds. */ | 260 | if (k == KW_IPVx_MSS) { /* Check valid MSS bounds. */ |
261 | rt.rt_flags |= RTF_MSS; | 261 | rt.rt_flags |= RTF_MSS; |
262 | rt.rt_mss = bb_xgetularg10_bnd(args_m1, 64, 32768); | 262 | rt.rt_mss = xatoul_range(args_m1, 64, 32768); |
263 | continue; | 263 | continue; |
264 | } | 264 | } |
265 | 265 | ||
266 | if (k == KW_IPVx_WINDOW) { /* Check valid window bounds. */ | 266 | if (k == KW_IPVx_WINDOW) { /* Check valid window bounds. */ |
267 | rt.rt_flags |= RTF_WINDOW; | 267 | rt.rt_flags |= RTF_WINDOW; |
268 | rt.rt_window = bb_xgetularg10_bnd(args_m1, 128, INT_MAX); | 268 | rt.rt_window = xatoul_range(args_m1, 128, INT_MAX); |
269 | continue; | 269 | continue; |
270 | } | 270 | } |
271 | 271 | ||
272 | #ifdef RTF_IRTT | 272 | #ifdef RTF_IRTT |
273 | if (k == KW_IPVx_IRTT) { | 273 | if (k == KW_IPVx_IRTT) { |
274 | rt.rt_flags |= RTF_IRTT; | 274 | rt.rt_flags |= RTF_IRTT; |
275 | rt.rt_irtt = bb_xgetularg10(args_m1); | 275 | rt.rt_irtt = xatoul(args_m1); |
276 | rt.rt_irtt *= (sysconf(_SC_CLK_TCK) / 100); /* FIXME */ | 276 | rt.rt_irtt *= (sysconf(_SC_CLK_TCK) / 100); /* FIXME */ |
277 | #if 0 /* FIXME: do we need to check anything of this? */ | 277 | #if 0 /* FIXME: do we need to check anything of this? */ |
278 | if (rt.rt_irtt < 1 || rt.rt_irtt > (120 * HZ)) { | 278 | if (rt.rt_irtt < 1 || rt.rt_irtt > (120 * HZ)) { |
@@ -353,7 +353,7 @@ static void INET6_setroute(int action, char **args) | |||
353 | char *cp; | 353 | char *cp; |
354 | if ((cp = strchr(target, '/'))) { /* Yes... const to non is ok. */ | 354 | if ((cp = strchr(target, '/'))) { /* Yes... const to non is ok. */ |
355 | *cp = 0; | 355 | *cp = 0; |
356 | prefix_len = bb_xgetularg10_bnd(cp+1, 0, 128); | 356 | prefix_len = xatoul_range(cp+1, 0, 128); |
357 | } else { | 357 | } else { |
358 | prefix_len = 128; | 358 | prefix_len = 128; |
359 | } | 359 | } |
@@ -384,7 +384,7 @@ static void INET6_setroute(int action, char **args) | |||
384 | } | 384 | } |
385 | 385 | ||
386 | if (k == KW_IPVx_METRIC) { | 386 | if (k == KW_IPVx_METRIC) { |
387 | rt.rtmsg_metric = bb_xgetularg10(args_m1); | 387 | rt.rtmsg_metric = xatoul(args_m1); |
388 | continue; | 388 | continue; |
389 | } | 389 | } |
390 | 390 | ||
diff --git a/networking/telnetd.c b/networking/telnetd.c index 1c4dede39..c6789e19c 100644 --- a/networking/telnetd.c +++ b/networking/telnetd.c | |||
@@ -369,7 +369,7 @@ telnetd_main(int argc, char **argv) | |||
369 | sockaddr_type sa; | 369 | sockaddr_type sa; |
370 | int master_fd; | 370 | int master_fd; |
371 | int on = 1; | 371 | int on = 1; |
372 | int portnbr = 23; | 372 | unsigned portnbr = 23; |
373 | struct in_addr bind_addr = { .s_addr = 0x0 }; | 373 | struct in_addr bind_addr = { .s_addr = 0x0 }; |
374 | char *opt_portnbr, *opt_bindaddr; | 374 | char *opt_portnbr, *opt_bindaddr; |
375 | #endif /* CONFIG_FEATURE_TELNETD_INETD */ | 375 | #endif /* CONFIG_FEATURE_TELNETD_INETD */ |
@@ -393,7 +393,7 @@ telnetd_main(int argc, char **argv) | |||
393 | //if (opt & 1) // -f | 393 | //if (opt & 1) // -f |
394 | //if (opt & 2) // -l | 394 | //if (opt & 2) // -l |
395 | #ifndef CONFIG_FEATURE_TELNETD_INETD | 395 | #ifndef CONFIG_FEATURE_TELNETD_INETD |
396 | if (opt & 4) portnbr = atoi(opt_portnbr); // -p | 396 | if (opt & 4) portnbr = xatou16(opt_portnbr); // -p |
397 | if (opt & 8) // -b | 397 | if (opt & 8) // -b |
398 | if (inet_aton(opt_bindaddr, &bind_addr) == 0) bb_show_usage(); | 398 | if (inet_aton(opt_bindaddr, &bind_addr) == 0) bb_show_usage(); |
399 | #endif /* CONFIG_FEATURE_TELNETD_INETD */ | 399 | #endif /* CONFIG_FEATURE_TELNETD_INETD */ |
diff --git a/networking/tftp.c b/networking/tftp.c index bfe94aca2..6213d6622 100644 --- a/networking/tftp.c +++ b/networking/tftp.c | |||
@@ -373,7 +373,7 @@ static int tftp(const int cmd, const struct hostent *host, | |||
373 | res = tftp_option_get(&buf[2], len - 2, OPTION_BLOCKSIZE); | 373 | res = tftp_option_get(&buf[2], len - 2, OPTION_BLOCKSIZE); |
374 | 374 | ||
375 | if (res) { | 375 | if (res) { |
376 | int blksize = atoi(res); | 376 | int blksize = xatoi_u(res); |
377 | 377 | ||
378 | if (tftp_blocksize_check(blksize, tftp_bufsize - 4)) { | 378 | if (tftp_blocksize_check(blksize, tftp_bufsize - 4)) { |
379 | 379 | ||
@@ -516,7 +516,7 @@ int tftp_main(int argc, char **argv) | |||
516 | 516 | ||
517 | #ifdef CONFIG_FEATURE_TFTP_BLOCKSIZE | 517 | #ifdef CONFIG_FEATURE_TFTP_BLOCKSIZE |
518 | if (sblocksize) { | 518 | if (sblocksize) { |
519 | blocksize = atoi(sblocksize); | 519 | blocksize = xatoi_u(sblocksize); |
520 | if (!tftp_blocksize_check(blocksize, 0)) { | 520 | if (!tftp_blocksize_check(blocksize, 0)) { |
521 | return EXIT_FAILURE; | 521 | return EXIT_FAILURE; |
522 | } | 522 | } |
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; |
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c index 9ab6aee8c..f2cf82f05 100644 --- a/networking/udhcp/dhcpc.c +++ b/networking/udhcp/dhcpc.c | |||
@@ -262,10 +262,10 @@ int udhcpc_main(int argc, char *argv[]) | |||
262 | client_config.script = optarg; | 262 | client_config.script = optarg; |
263 | break; | 263 | break; |
264 | case 'T': | 264 | case 'T': |
265 | client_config.timeout = atoi(optarg); | 265 | client_config.timeout = xatoi_u(optarg); |
266 | break; | 266 | break; |
267 | case 't': | 267 | case 't': |
268 | client_config.retries = atoi(optarg); | 268 | client_config.retries = xatoi_u(optarg); |
269 | break; | 269 | break; |
270 | case 'v': | 270 | case 'v': |
271 | printf("version %s\n\n", BB_VER); | 271 | printf("version %s\n\n", BB_VER); |
diff --git a/networking/udhcp/files.c b/networking/udhcp/files.c index d9dfb8965..52d383869 100644 --- a/networking/udhcp/files.c +++ b/networking/udhcp/files.c | |||
@@ -35,7 +35,8 @@ static int read_ip(const char *line, void *arg) | |||
35 | int retval = 1; | 35 | int retval = 1; |
36 | 36 | ||
37 | if (!inet_aton(line, addr)) { | 37 | if (!inet_aton(line, addr)) { |
38 | if ((host = gethostbyname(line))) | 38 | host = gethostbyname(line); |
39 | if (host) | ||
39 | addr->s_addr = *((unsigned long *) host->h_addr_list[0]); | 40 | addr->s_addr = *((unsigned long *) host->h_addr_list[0]); |
40 | else retval = 0; | 41 | else retval = 0; |
41 | } | 42 | } |
@@ -72,10 +73,7 @@ static int read_str(const char *line, void *arg) | |||
72 | 73 | ||
73 | static int read_u32(const char *line, void *arg) | 74 | static int read_u32(const char *line, void *arg) |
74 | { | 75 | { |
75 | uint32_t *dest = arg; | 76 | return safe_strtou32(line, (uint32_t*)arg) == 0; |
76 | char *endptr; | ||
77 | *dest = strtoul(line, &endptr, 0); | ||
78 | return endptr[0] == '\0'; | ||
79 | } | 77 | } |
80 | 78 | ||
81 | 79 | ||
diff --git a/networking/vconfig.c b/networking/vconfig.c index 6c808eb2f..003c1a8f7 100644 --- a/networking/vconfig.c +++ b/networking/vconfig.c | |||
@@ -144,14 +144,14 @@ int vconfig_main(int argc, char **argv) | |||
144 | * doing so wouldn't save that much space and would also make maintainence | 144 | * doing so wouldn't save that much space and would also make maintainence |
145 | * more of a pain. */ | 145 | * more of a pain. */ |
146 | if (ifr.cmd == SET_VLAN_FLAG_CMD) { /* set_flag */ | 146 | if (ifr.cmd == SET_VLAN_FLAG_CMD) { /* set_flag */ |
147 | ifr.u.flag = bb_xgetularg10_bnd(p, 0, 1); | 147 | ifr.u.flag = xatoul_range(p, 0, 1); |
148 | /* DM: in order to set reorder header, qos must be set */ | 148 | /* DM: in order to set reorder header, qos must be set */ |
149 | ifr.vlan_qos = bb_xgetularg10_bnd(argv[3], 0, 7); | 149 | ifr.vlan_qos = xatoul_range(argv[3], 0, 7); |
150 | } else if (ifr.cmd == ADD_VLAN_CMD) { /* add */ | 150 | } else if (ifr.cmd == ADD_VLAN_CMD) { /* add */ |
151 | ifr.u.VID = bb_xgetularg10_bnd(p, 0, VLAN_GROUP_ARRAY_LEN-1); | 151 | ifr.u.VID = xatoul_range(p, 0, VLAN_GROUP_ARRAY_LEN-1); |
152 | } else if (ifr.cmd != DEL_VLAN_CMD) { /* set_{egress|ingress}_map */ | 152 | } else if (ifr.cmd != DEL_VLAN_CMD) { /* set_{egress|ingress}_map */ |
153 | ifr.u.skb_priority = bb_xgetularg10_bnd(p, 0, ULONG_MAX); | 153 | ifr.u.skb_priority = xatou(p); |
154 | ifr.vlan_qos = bb_xgetularg10_bnd(argv[3], 0, 7); | 154 | ifr.vlan_qos = xatoul_range(argv[3], 0, 7); |
155 | } | 155 | } |
156 | } | 156 | } |
157 | 157 | ||
diff --git a/networking/wget.c b/networking/wget.c index eda0bb87c..e7b19f2ef 100644 --- a/networking/wget.c +++ b/networking/wget.c | |||
@@ -297,7 +297,7 @@ read_response: | |||
297 | s = buf; | 297 | s = buf; |
298 | while (*s != '\0' && !isspace(*s)) ++s; | 298 | while (*s != '\0' && !isspace(*s)) ++s; |
299 | while (isspace(*s)) ++s; | 299 | while (isspace(*s)) ++s; |
300 | switch (status = atoi(s)) { | 300 | switch (status = xatoi(s)) { |
301 | case 0: | 301 | case 0: |
302 | case 100: | 302 | case 100: |
303 | while (gethdr(buf, sizeof(buf), sfp, &n) != NULL) | 303 | while (gethdr(buf, sizeof(buf), sfp, &n) != NULL) |
@@ -406,9 +406,9 @@ read_response: | |||
406 | bb_error_msg_and_die("PASV: %s", buf+4); | 406 | bb_error_msg_and_die("PASV: %s", buf+4); |
407 | s = strrchr(buf, ','); | 407 | s = strrchr(buf, ','); |
408 | *s = 0; | 408 | *s = 0; |
409 | port = atoi(s+1); | 409 | port = xatol_range(s+1, 0, 255); |
410 | s = strrchr(buf, ','); | 410 | s = strrchr(buf, ','); |
411 | port += atoi(s+1) * 256; | 411 | port += xatol_range(s+1, 0, 255) * 256; |
412 | s_in.sin_port = htons(port); | 412 | s_in.sin_port = htons(port); |
413 | dfp = open_socket(&s_in); | 413 | dfp = open_socket(&s_in); |
414 | 414 | ||
@@ -562,7 +562,7 @@ static void parse_url(char *src_url, struct host_info *h) | |||
562 | cp = strchr(pp, ':'); | 562 | cp = strchr(pp, ':'); |
563 | if (cp != NULL) { | 563 | if (cp != NULL) { |
564 | *cp++ = '\0'; | 564 | *cp++ = '\0'; |
565 | h->port = htons(atoi(cp)); | 565 | h->port = htons(xatou16(cp)); |
566 | } | 566 | } |
567 | } | 567 | } |
568 | 568 | ||
@@ -646,7 +646,7 @@ static int ftpcmd(char *s1, char *s2, FILE *fp, char *buf) | |||
646 | } | 646 | } |
647 | } while (!isdigit(buf[0]) || buf[3] != ' '); | 647 | } while (!isdigit(buf[0]) || buf[3] != ' '); |
648 | 648 | ||
649 | return atoi(buf); | 649 | return xatoi(buf); |
650 | } | 650 | } |
651 | 651 | ||
652 | #ifdef CONFIG_FEATURE_WGET_STATUSBAR | 652 | #ifdef CONFIG_FEATURE_WGET_STATUSBAR |