Changeset 2725 in MondoRescue for branches/2.2.9/mindi-busybox/networking/arp.c
- Timestamp:
- Feb 25, 2011, 9:26:54 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2.9/mindi-busybox/networking/arp.c
r1765 r2725 28 28 #define DFLT_HW "ether" 29 29 30 #define ARP_OPT_A (0x1) 31 #define ARP_OPT_p (0x2) 32 #define ARP_OPT_H (0x4) 33 #define ARP_OPT_t (0x8) 34 #define ARP_OPT_i (0x10) 35 #define ARP_OPT_a (0x20) 36 #define ARP_OPT_d (0x40) 37 #define ARP_OPT_n (0x80) /* do not resolve addresses */ 38 #define ARP_OPT_D (0x100) /* HW-address is devicename */ 39 #define ARP_OPT_s (0x200) 40 #define ARP_OPT_v (0x400 * DEBUG) /* debugging output flag */ 41 42 43 static const struct aftype *ap; /* current address family */ 44 static const struct hwtype *hw; /* current hardware type */ 45 static int sockfd; /* active socket descriptor */ 46 static smallint hw_set; /* flag if hw-type was set (-H) */ 47 static const char *device = ""; /* current device */ 30 enum { 31 ARP_OPT_A = (1 << 0), 32 ARP_OPT_p = (1 << 1), 33 ARP_OPT_H = (1 << 2), 34 ARP_OPT_t = (1 << 3), 35 ARP_OPT_i = (1 << 4), 36 ARP_OPT_a = (1 << 5), 37 ARP_OPT_d = (1 << 6), 38 ARP_OPT_n = (1 << 7), /* do not resolve addresses */ 39 ARP_OPT_D = (1 << 8), /* HW-address is devicename */ 40 ARP_OPT_s = (1 << 9), 41 ARP_OPT_v = (1 << 10) * DEBUG, /* debugging output flag */ 42 }; 43 44 enum { 45 sockfd = 3, /* active socket descriptor */ 46 }; 47 48 struct globals { 49 const struct aftype *ap; /* current address family */ 50 const struct hwtype *hw; /* current hardware type */ 51 const char *device; /* current device */ 52 smallint hw_set; /* flag if hw-type was set (-H) */ 53 54 } FIX_ALIASING; 55 #define G (*(struct globals*)&bb_common_bufsiz1) 56 #define ap (G.ap ) 57 #define hw (G.hw ) 58 #define device (G.device ) 59 #define hw_set (G.hw_set ) 60 #define INIT_G() do { \ 61 device = ""; \ 62 } while (0) 63 48 64 49 65 static const char options[] ALIGN1 = … … 201 217 bb_error_msg("device '%s' has HW address %s '%s'", 202 218 ifname, xhw->name, 203 xhw->print(( char *) &ifr.ifr_hwaddr.sa_data));219 xhw->print((unsigned char *) &ifr.ifr_hwaddr.sa_data)); 204 220 } 205 221 } … … 314 330 char *hwa, char *mask, char *dev) 315 331 { 332 static const int arp_masks[] = { 333 ATF_PERM, ATF_PUBL, 334 #ifdef HAVE_ATF_MAGIC 335 ATF_MAGIC, 336 #endif 337 #ifdef HAVE_ATF_DONTPUB 338 ATF_DONTPUB, 339 #endif 340 ATF_USETRAILERS, 341 }; 342 static const char arp_labels[] ALIGN1 = "PERM\0""PUP\0" 343 #ifdef HAVE_ATF_MAGIC 344 "AUTO\0" 345 #endif 346 #ifdef HAVE_ATF_DONTPUB 347 "DONTPUB\0" 348 #endif 349 "TRAIL\0" 350 ; 351 316 352 const struct hwtype *xhw; 317 353 … … 334 370 printf("netmask %s ", mask); 335 371 336 if (arp_flags & ATF_PERM) 337 printf("PERM "); 338 if (arp_flags & ATF_PUBL) 339 printf("PUP "); 340 #ifdef HAVE_ATF_MAGIC 341 if (arp_flags & ATF_MAGIC) 342 printf("AUTO "); 343 #endif 344 #ifdef HAVE_ATF_DONTPUB 345 if (arp_flags & ATF_DONTPUB) 346 printf("DONTPUB "); 347 #endif 348 if (arp_flags & ATF_USETRAILERS) 349 printf("TRAIL "); 350 351 printf("on %s\n", dev); 372 print_flags_separated(arp_masks, arp_labels, arp_flags, " "); 373 printf(" on %s\n", dev); 352 374 } 353 375 … … 377 399 host = xstrdup(ap->sprint(&sa, 1)); 378 400 } 379 fp = xfopen ("/proc/net/arp", "r");401 fp = xfopen_for_read("/proc/net/arp"); 380 402 /* Bypass header -- read one line */ 381 403 fgets(line, sizeof(line), fp); … … 435 457 } 436 458 437 int arp_main(int argc, char **argv) ;438 int arp_main(int argc , char **argv)459 int arp_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 460 int arp_main(int argc UNUSED_PARAM, char **argv) 439 461 { 440 char *hw_type; 441 char *protocol; 442 443 /* Initialize variables... */ 462 const char *hw_type = "ether"; 463 const char *protocol; 464 unsigned opts; 465 466 INIT_G(); 467 468 xmove_fd(xsocket(AF_INET, SOCK_DGRAM, 0), sockfd); 444 469 ap = get_aftype(DFLT_AF); 445 470 if (!ap) 446 471 bb_error_msg_and_die("%s: %s not supported", DFLT_AF, "address family"); 447 472 448 getopt32(argv, "A:p:H:t:i:adnDsv", &protocol, &protocol,473 opts = getopt32(argv, "A:p:H:t:i:adnDsv", &protocol, &protocol, 449 474 &hw_type, &hw_type, &device); 450 475 argv += optind; 451 if (opt ion_mask32 & ARP_OPT_A || option_mask32 & ARP_OPT_p) {476 if (opts & (ARP_OPT_A | ARP_OPT_p)) { 452 477 ap = get_aftype(protocol); 453 478 if (ap == NULL) 454 479 bb_error_msg_and_die("%s: unknown %s", protocol, "address family"); 455 480 } 456 if (opt ion_mask32 & ARP_OPT_A || option_mask32 & ARP_OPT_p) {481 if (opts & (ARP_OPT_A | ARP_OPT_p)) { 457 482 hw = get_hwtype(hw_type); 458 483 if (hw == NULL) … … 460 485 hw_set = 1; 461 486 } 462 //if (opt ion_mask32& ARP_OPT_i)... -i487 //if (opts & ARP_OPT_i)... -i 463 488 464 489 if (ap->af != AF_INET) { … … 477 502 hw->name, "hardware type"); 478 503 } 479 sockfd = xsocket(AF_INET, SOCK_DGRAM, 0);480 504 481 505 /* Now see what we have to do here... */ 482 if (opt ion_mask32 & (ARP_OPT_d|ARP_OPT_s)) {506 if (opts & (ARP_OPT_d | ARP_OPT_s)) { 483 507 if (argv[0] == NULL) 484 508 bb_error_msg_and_die("need host name"); 485 if (opt ion_mask32& ARP_OPT_s)509 if (opts & ARP_OPT_s) 486 510 return arp_set(argv); 487 511 return arp_del(argv); 488 512 } 489 //if (opt ion_mask32& ARP_OPT_a) - default513 //if (opts & ARP_OPT_a) - default 490 514 return arp_show(argv[0]); 491 515 }
Note:
See TracChangeset
for help on using the changeset viewer.