aboutsummaryrefslogtreecommitdiff
path: root/networking/arp.c
diff options
context:
space:
mode:
Diffstat (limited to 'networking/arp.c')
-rw-r--r--networking/arp.c53
1 files changed, 25 insertions, 28 deletions
diff --git a/networking/arp.c b/networking/arp.c
index 696c402e0..40d244116 100644
--- a/networking/arp.c
+++ b/networking/arp.c
@@ -22,12 +22,12 @@
22//usage:#define arp_full_usage "\n\n" 22//usage:#define arp_full_usage "\n\n"
23//usage: "Manipulate ARP cache\n" 23//usage: "Manipulate ARP cache\n"
24//usage: "\n -a Display (all) hosts" 24//usage: "\n -a Display (all) hosts"
25//usage: "\n -s Set new ARP entry" 25//usage: "\n -d Delete ARP entry"
26//usage: "\n -d Delete a specified entry" 26//usage: "\n -s Set new entry"
27//usage: "\n -v Verbose" 27//usage: "\n -v Verbose"
28//usage: "\n -n Don't resolve names" 28//usage: "\n -n Don't resolve names"
29//usage: "\n -i IF Network interface" 29//usage: "\n -i IF Network interface"
30//usage: "\n -D Read <hwaddr> from given device" 30//usage: "\n -D Read HWADDR from IFACE"
31//usage: "\n -A,-p AF Protocol family" 31//usage: "\n -A,-p AF Protocol family"
32//usage: "\n -H HWTYPE Hardware address type" 32//usage: "\n -H HWTYPE Hardware address type"
33 33
@@ -213,16 +213,15 @@ static int arp_del(char **args)
213} 213}
214 214
215/* Get the hardware address to a specified interface name */ 215/* Get the hardware address to a specified interface name */
216static void arp_getdevhw(char *ifname, struct sockaddr *sa, 216static void arp_getdevhw(char *ifname, struct sockaddr *sa)
217 const struct hwtype *hwt)
218{ 217{
219 struct ifreq ifr; 218 struct ifreq ifr;
220 const struct hwtype *xhw; 219 const struct hwtype *xhw;
221 220
222 strcpy(ifr.ifr_name, ifname); 221 strcpy(ifr.ifr_name, ifname);
223 ioctl_or_perror_and_die(sockfd, SIOCGIFHWADDR, &ifr, 222 ioctl_or_perror_and_die(sockfd, SIOCGIFHWADDR, &ifr,
224 "cant get HW-Address for '%s'", ifname); 223 "can't get HW-Address for '%s'", ifname);
225 if (hwt && (ifr.ifr_hwaddr.sa_family != hw->type)) { 224 if (hw_set && (ifr.ifr_hwaddr.sa_family != hw->type)) {
226 bb_error_msg_and_die("protocol type mismatch"); 225 bb_error_msg_and_die("protocol type mismatch");
227 } 226 }
228 memcpy(sa, &(ifr.ifr_hwaddr), sizeof(struct sockaddr)); 227 memcpy(sa, &(ifr.ifr_hwaddr), sizeof(struct sockaddr));
@@ -233,8 +232,8 @@ static void arp_getdevhw(char *ifname, struct sockaddr *sa,
233 xhw = get_hwntype(-1); 232 xhw = get_hwntype(-1);
234 } 233 }
235 bb_error_msg("device '%s' has HW address %s '%s'", 234 bb_error_msg("device '%s' has HW address %s '%s'",
236 ifname, xhw->name, 235 ifname, xhw->name,
237 xhw->print((unsigned char *) &ifr.ifr_hwaddr.sa_data)); 236 xhw->print((unsigned char *) &ifr.ifr_hwaddr.sa_data));
238 } 237 }
239} 238}
240 239
@@ -261,7 +260,7 @@ static int arp_set(char **args)
261 bb_error_msg_and_die("need hardware address"); 260 bb_error_msg_and_die("need hardware address");
262 } 261 }
263 if (option_mask32 & ARP_OPT_D) { 262 if (option_mask32 & ARP_OPT_D) {
264 arp_getdevhw(*args++, &req.arp_ha, hw_set ? hw : NULL); 263 arp_getdevhw(*args++, &req.arp_ha);
265 } else { 264 } else {
266 if (hw->input(*args++, &req.arp_ha) < 0) { 265 if (hw->input(*args++, &req.arp_ha) < 0) {
267 bb_error_msg_and_die("invalid hardware address"); 266 bb_error_msg_and_die("invalid hardware address");
@@ -345,7 +344,7 @@ static int arp_set(char **args)
345/* Print the contents of an ARP request block. */ 344/* Print the contents of an ARP request block. */
346static void 345static void
347arp_disp(const char *name, char *ip, int type, int arp_flags, 346arp_disp(const char *name, char *ip, int type, int arp_flags,
348 char *hwa, char *mask, char *dev) 347 char *hwa, char *mask, char *dev)
349{ 348{
350 static const int arp_masks[] = { 349 static const int arp_masks[] = {
351 ATF_PERM, ATF_PUBL, 350 ATF_PERM, ATF_PUBL,
@@ -428,7 +427,7 @@ static int arp_show(char *name)
428 /* All these strings can't overflow 427 /* All these strings can't overflow
429 * because fgets above reads limited amount of data */ 428 * because fgets above reads limited amount of data */
430 num = sscanf(line, "%s 0x%x 0x%x %s %s %s\n", 429 num = sscanf(line, "%s 0x%x 0x%x %s %s %s\n",
431 ip, &type, &flags, hwa, mask, dev); 430 ip, &type, &flags, hwa, mask, dev);
432 if (num < 4) 431 if (num < 4)
433 break; 432 break;
434 433
@@ -461,7 +460,7 @@ static int arp_show(char *name)
461 } 460 }
462 if (option_mask32 & ARP_OPT_v) 461 if (option_mask32 & ARP_OPT_v)
463 printf("Entries: %d\tSkipped: %d\tFound: %d\n", 462 printf("Entries: %d\tSkipped: %d\tFound: %d\n",
464 entries, entries - shown, shown); 463 entries, entries - shown, shown);
465 464
466 if (!shown) { 465 if (!shown) {
467 if (hw_set || host || device[0]) 466 if (hw_set || host || device[0])
@@ -477,28 +476,33 @@ static int arp_show(char *name)
477int arp_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 476int arp_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
478int arp_main(int argc UNUSED_PARAM, char **argv) 477int arp_main(int argc UNUSED_PARAM, char **argv)
479{ 478{
480 const char *hw_type = "ether"; 479 const char *hw_type;
481 const char *protocol; 480 const char *protocol;
482 unsigned opts; 481 unsigned opts;
483 482
484 INIT_G(); 483 INIT_G();
485 484
486 xmove_fd(xsocket(AF_INET, SOCK_DGRAM, 0), sockfd); 485 xmove_fd(xsocket(AF_INET, SOCK_DGRAM, 0), sockfd);
486
487 ap = get_aftype(DFLT_AF); 487 ap = get_aftype(DFLT_AF);
488 if (!ap) 488 /* Defaults are always supported */
489 bb_error_msg_and_die("%s: %s not supported", DFLT_AF, "address family"); 489 //if (!ap)
490 // bb_error_msg_and_die("%s: %s not supported", DFLT_AF, "address family");
491 hw = get_hwtype(DFLT_HW);
492 //if (!hw)
493 // bb_error_msg_and_die("%s: %s not supported", DFLT_HW, "hardware type");
490 494
491 opts = getopt32(argv, "A:p:H:t:i:adnDsv", &protocol, &protocol, 495 opts = getopt32(argv, "A:p:H:t:i:adnDsv", &protocol, &protocol,
492 &hw_type, &hw_type, &device); 496 &hw_type, &hw_type, &device);
493 argv += optind; 497 argv += optind;
494 if (opts & (ARP_OPT_A | ARP_OPT_p)) { 498 if (opts & (ARP_OPT_A | ARP_OPT_p)) {
495 ap = get_aftype(protocol); 499 ap = get_aftype(protocol);
496 if (ap == NULL) 500 if (!ap)
497 bb_error_msg_and_die("%s: unknown %s", protocol, "address family"); 501 bb_error_msg_and_die("%s: unknown %s", protocol, "address family");
498 } 502 }
499 if (opts & (ARP_OPT_A | ARP_OPT_p)) { 503 if (opts & (ARP_OPT_H | ARP_OPT_t)) {
500 hw = get_hwtype(hw_type); 504 hw = get_hwtype(hw_type);
501 if (hw == NULL) 505 if (!hw)
502 bb_error_msg_and_die("%s: unknown %s", hw_type, "hardware type"); 506 bb_error_msg_and_die("%s: unknown %s", hw_type, "hardware type");
503 hw_set = 1; 507 hw_set = 1;
504 } 508 }
@@ -507,17 +511,9 @@ int arp_main(int argc UNUSED_PARAM, char **argv)
507 if (ap->af != AF_INET) { 511 if (ap->af != AF_INET) {
508 bb_error_msg_and_die("%s: kernel only supports 'inet'", ap->name); 512 bb_error_msg_and_die("%s: kernel only supports 'inet'", ap->name);
509 } 513 }
510
511 /* If no hw type specified get default */
512 if (!hw) {
513 hw = get_hwtype(DFLT_HW);
514 if (!hw)
515 bb_error_msg_and_die("%s: %s not supported", DFLT_HW, "hardware type");
516 }
517
518 if (hw->alen <= 0) { 514 if (hw->alen <= 0) {
519 bb_error_msg_and_die("%s: %s without ARP support", 515 bb_error_msg_and_die("%s: %s without ARP support",
520 hw->name, "hardware type"); 516 hw->name, "hardware type");
521 } 517 }
522 518
523 /* Now see what we have to do here... */ 519 /* Now see what we have to do here... */
@@ -528,6 +524,7 @@ int arp_main(int argc UNUSED_PARAM, char **argv)
528 return arp_set(argv); 524 return arp_set(argv);
529 return arp_del(argv); 525 return arp_del(argv);
530 } 526 }
527
531 //if (opts & ARP_OPT_a) - default 528 //if (opts & ARP_OPT_a) - default
532 return arp_show(argv[0]); 529 return arp_show(argv[0]);
533} 530}