aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2006-09-23 12:46:30 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2006-09-23 12:46:30 +0000
commita65a17700af53300b90a4dbfaeab972c1771e2ba (patch)
tree82fcccd697e45db4bf9ef9817521f61e45155117
parentfe76cd5a5c26793b67de07a424e3c2ef395a0440 (diff)
downloadbusybox-w32-a65a17700af53300b90a4dbfaeab972c1771e2ba.tar.gz
busybox-w32-a65a17700af53300b90a4dbfaeab972c1771e2ba.tar.bz2
busybox-w32-a65a17700af53300b90a4dbfaeab972c1771e2ba.zip
arping: fix bug (getopt_ulflags and optarg don't mix),
remove unreachable error path.
-rw-r--r--networking/arping.c40
1 files changed, 16 insertions, 24 deletions
diff --git a/networking/arping.c b/networking/arping.c
index 08b27273f..c63ec91af 100644
--- a/networking/arping.c
+++ b/networking/arping.c
@@ -260,35 +260,32 @@ int arping_main(int argc, char **argv)
260 char *target; 260 char *target;
261 261
262 s = xsocket(PF_PACKET, SOCK_DGRAM, 0); 262 s = xsocket(PF_PACKET, SOCK_DGRAM, 0);
263 ifindex = errno;
264 263
265 // Drop suid root privileges 264 // Drop suid root privileges
266 xsetuid(getuid()); 265 xsetuid(getuid());
267 266
268 { 267 {
269 unsigned long opt; 268 unsigned long opt;
270 char *_count, *_timeout, *_device; 269 char *_count, *_timeout;
271 270
272 /* Dad also sets quit_on_reply. 271 /* Dad also sets quit_on_reply.
273 * Advert also sets unsolicited. 272 * Advert also sets unsolicited.
274 */ 273 */
275 bb_opt_complementally = "Df:AU"; 274 bb_opt_complementally = "Df:AU";
276 opt = bb_getopt_ulflags(argc, argv, "DUAqfbc:w:i:s:", 275 opt = bb_getopt_ulflags(argc, argv, "DUAqfbc:w:i:s:",
277 &_count, &_timeout, &_device); 276 &_count, &_timeout, &device, &source);
278 cfg |= opt & 63; /* set respective flags */ 277 cfg |= opt & 0x3f; /* set respective flags */
279 if (opt & 64) /* count */ 278 if (opt & 0x40) /* -c: count */
280 count = atoi(_count); 279 count = atoi(_count);
281 if (opt & 128) /* timeout */ 280 if (opt & 0x80) /* -w: timeout */
282 timeout = atoi(_timeout); 281 timeout = atoi(_timeout);
283 if (opt & 256) { /* interface */ 282 if (opt & 0x100) { /* -i: interface */
284 if (strlen(_device) > IF_NAMESIZE) { 283 if (strlen(device) > IF_NAMESIZE) {
285 bb_error_msg_and_die("Interface name `%s' must be less than %d", 284 bb_error_msg_and_die("interface name '%s' is too long",
286 _device, IF_NAMESIZE); 285 device);
287 } 286 }
288 device = _device;
289 } 287 }
290 if (opt & 512) /* source */ 288 //if (opt & 0x200) /* -s: source */
291 source = optarg;
292 } 289 }
293 argc -= optind; 290 argc -= optind;
294 argv += optind; 291 argv += optind;
@@ -298,11 +295,6 @@ int arping_main(int argc, char **argv)
298 295
299 target = *argv; 296 target = *argv;
300 297
301
302 if (s < 0) {
303 bb_default_error_retval = ifindex;
304 bb_perror_msg_and_die("socket");
305 }
306 bb_default_error_retval = 2; 298 bb_default_error_retval = 2;
307 299
308 { 300 {
@@ -311,7 +303,7 @@ int arping_main(int argc, char **argv)
311 memset(&ifr, 0, sizeof(ifr)); 303 memset(&ifr, 0, sizeof(ifr));
312 strncpy(ifr.ifr_name, device, IFNAMSIZ - 1); 304 strncpy(ifr.ifr_name, device, IFNAMSIZ - 1);
313 if (ioctl(s, SIOCGIFINDEX, &ifr) < 0) { 305 if (ioctl(s, SIOCGIFINDEX, &ifr) < 0) {
314 bb_error_msg_and_die("Interface %s not found", device); 306 bb_error_msg_and_die("interface %s not found", device);
315 } 307 }
316 ifindex = ifr.ifr_ifindex; 308 ifindex = ifr.ifr_ifindex;
317 309
@@ -319,10 +311,10 @@ int arping_main(int argc, char **argv)
319 bb_error_msg_and_die("SIOCGIFFLAGS"); 311 bb_error_msg_and_die("SIOCGIFFLAGS");
320 } 312 }
321 if (!(ifr.ifr_flags & IFF_UP)) { 313 if (!(ifr.ifr_flags & IFF_UP)) {
322 bb_error_msg_and_die("Interface %s is down", device); 314 bb_error_msg_and_die("interface %s is down", device);
323 } 315 }
324 if (ifr.ifr_flags & (IFF_NOARP | IFF_LOOPBACK)) { 316 if (ifr.ifr_flags & (IFF_NOARP | IFF_LOOPBACK)) {
325 bb_error_msg("Interface %s is not ARPable", device); 317 bb_error_msg("interface %s is not ARPable", device);
326 exit(cfg&dad ? 0 : 2); 318 exit(cfg&dad ? 0 : 2);
327 } 319 }
328 } 320 }
@@ -352,7 +344,7 @@ int arping_main(int argc, char **argv)
352 if (setsockopt 344 if (setsockopt
353 (probe_fd, SOL_SOCKET, SO_BINDTODEVICE, device, 345 (probe_fd, SOL_SOCKET, SO_BINDTODEVICE, device,
354 strlen(device) + 1) == -1) 346 strlen(device) + 1) == -1)
355 bb_error_msg("WARNING: interface %s is ignored", device); 347 bb_error_msg("warning: interface %s is ignored", device);
356 } 348 }
357 memset(&saddr, 0, sizeof(saddr)); 349 memset(&saddr, 0, sizeof(saddr));
358 saddr.sin_family = AF_INET; 350 saddr.sin_family = AF_INET;
@@ -371,7 +363,7 @@ int arping_main(int argc, char **argv)
371 if (setsockopt 363 if (setsockopt
372 (probe_fd, SOL_SOCKET, SO_DONTROUTE, (char *) &on, 364 (probe_fd, SOL_SOCKET, SO_DONTROUTE, (char *) &on,
373 sizeof(on)) == -1) 365 sizeof(on)) == -1)
374 bb_perror_msg("WARNING: setsockopt(SO_DONTROUTE)"); 366 bb_perror_msg("warning: setsockopt(SO_DONTROUTE)");
375 if (connect(probe_fd, (struct sockaddr *) &saddr, sizeof(saddr)) 367 if (connect(probe_fd, (struct sockaddr *) &saddr, sizeof(saddr))
376 == -1) { 368 == -1) {
377 bb_error_msg_and_die("connect"); 369 bb_error_msg_and_die("connect");
@@ -440,7 +432,7 @@ int arping_main(int argc, char **argv)
440 432
441 if ((cc = recvfrom(s, packet, 4096, 0, 433 if ((cc = recvfrom(s, packet, 4096, 0,
442 (struct sockaddr *) &from, &alen)) < 0) { 434 (struct sockaddr *) &from, &alen)) < 0) {
443 perror("recvfrom"); 435 bb_perror_msg("recvfrom");
444 continue; 436 continue;
445 } 437 }
446 sigemptyset(&sset); 438 sigemptyset(&sset);