aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-11-13 00:05:17 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-11-13 00:05:17 +0000
commit4d47692fb899be6dec58e7e1ae22893ebb92fa37 (patch)
tree106aa3f2945afd92e88a94a39704a18b5ffc0e75
parentfd5a3d28127f051887b6feb3462928aee045c9ef (diff)
downloadbusybox-w32-4d47692fb899be6dec58e7e1ae22893ebb92fa37.tar.gz
busybox-w32-4d47692fb899be6dec58e7e1ae22893ebb92fa37.tar.bz2
busybox-w32-4d47692fb899be6dec58e7e1ae22893ebb92fa37.zip
arp: stop using globals
function old new delta hw_set 1 - -1 arp_main 1559 1558 -1 sockfd 8 4 -4 hw 4 - -4 device 4 - -4 ap 4 - -4 packed_usage 25402 25393 -9 ------------------------------------------------------------------------------ (add/remove: 0/4 grow/shrink: 0/3 up/down: 0/-27) Total: -27 bytes
-rw-r--r--include/usage.h11
-rw-r--r--networking/arp.c72
2 files changed, 50 insertions, 33 deletions
diff --git a/include/usage.h b/include/usage.h
index d38a16e90..9f7358906 100644
--- a/include/usage.h
+++ b/include/usage.h
@@ -61,12 +61,11 @@
61 "\n -v Verbose" \ 61 "\n -v Verbose" \
62 62
63#define arp_trivial_usage \ 63#define arp_trivial_usage \
64 "\n" \ 64 "\n[-vn] [-H type] [-i if] -a [hostname]" \
65 "[-vn] [-H type] [-i if] -a [hostname]\n" \ 65 "\n[-v] [-i if] -d hostname [pub]" \
66 "[-v] [-i if] -d hostname [pub]\n" \ 66 "\n[-v] [-H type] [-i if] -s hostname hw_addr [temp]" \
67 "[-v] [-H type] [-i if] -s hostname hw_addr [temp]\n" \ 67 "\n[-v] [-H type] [-i if] -s hostname hw_addr [netmask nm] pub" \
68 "[-v] [-H type] [-i if] -s hostname hw_addr [netmask nm] pub\n" \ 68 "\n[-v] [-H type] [-i if] -Ds hostname ifa [netmask nm] pub"
69 "[-v] [-H type] [-i if] -Ds hostname ifa [netmask nm] pub\n"
70#define arp_full_usage "\n\n" \ 69#define arp_full_usage "\n\n" \
71 "Manipulate ARP cache\n" \ 70 "Manipulate ARP cache\n" \
72 "\nOptions:" \ 71 "\nOptions:" \
diff --git a/networking/arp.c b/networking/arp.c
index e2c5bbb7f..278f2dc9a 100644
--- a/networking/arp.c
+++ b/networking/arp.c
@@ -27,24 +27,40 @@
27#define DFLT_AF "inet" 27#define DFLT_AF "inet"
28#define DFLT_HW "ether" 28#define DFLT_HW "ether"
29 29
30#define ARP_OPT_A (0x1) 30enum {
31#define ARP_OPT_p (0x2) 31 ARP_OPT_A = (1 << 0),
32#define ARP_OPT_H (0x4) 32 ARP_OPT_p = (1 << 1),
33#define ARP_OPT_t (0x8) 33 ARP_OPT_H = (1 << 2),
34#define ARP_OPT_i (0x10) 34 ARP_OPT_t = (1 << 3),
35#define ARP_OPT_a (0x20) 35 ARP_OPT_i = (1 << 4),
36#define ARP_OPT_d (0x40) 36 ARP_OPT_a = (1 << 5),
37#define ARP_OPT_n (0x80) /* do not resolve addresses */ 37 ARP_OPT_d = (1 << 6),
38#define ARP_OPT_D (0x100) /* HW-address is devicename */ 38 ARP_OPT_n = (1 << 7), /* do not resolve addresses */
39#define ARP_OPT_s (0x200) 39 ARP_OPT_D = (1 << 8), /* HW-address is devicename */
40#define ARP_OPT_v (0x400 * DEBUG) /* debugging output flag */ 40 ARP_OPT_s = (1 << 9),
41 41 ARP_OPT_v = (1 << 10) * DEBUG, /* debugging output flag */
42 42};
43static const struct aftype *ap; /* current address family */ 43
44static const struct hwtype *hw; /* current hardware type */ 44enum {
45static int sockfd; /* active socket descriptor */ 45 sockfd = 3, /* active socket descriptor */
46static smallint hw_set; /* flag if hw-type was set (-H) */ 46};
47static const char *device = ""; /* current device */ 47
48struct 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};
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
49static const char options[] ALIGN1 = 65static const char options[] ALIGN1 =
50 "pub\0" 66 "pub\0"
@@ -445,27 +461,30 @@ int arp_main(int argc UNUSED_PARAM, char **argv)
445{ 461{
446 const char *hw_type = "ether"; 462 const char *hw_type = "ether";
447 const char *protocol; 463 const char *protocol;
464 unsigned opts;
465
466 INIT_G();
448 467
449 /* Initialize variables... */ 468 xmove_fd(xsocket(AF_INET, SOCK_DGRAM, 0), sockfd);
450 ap = get_aftype(DFLT_AF); 469 ap = get_aftype(DFLT_AF);
451 if (!ap) 470 if (!ap)
452 bb_error_msg_and_die("%s: %s not supported", DFLT_AF, "address family"); 471 bb_error_msg_and_die("%s: %s not supported", DFLT_AF, "address family");
453 472
454 getopt32(argv, "A:p:H:t:i:adnDsv", &protocol, &protocol, 473 opts = getopt32(argv, "A:p:H:t:i:adnDsv", &protocol, &protocol,
455 &hw_type, &hw_type, &device); 474 &hw_type, &hw_type, &device);
456 argv += optind; 475 argv += optind;
457 if (option_mask32 & ARP_OPT_A || option_mask32 & ARP_OPT_p) { 476 if (opts & (ARP_OPT_A | ARP_OPT_p)) {
458 ap = get_aftype(protocol); 477 ap = get_aftype(protocol);
459 if (ap == NULL) 478 if (ap == NULL)
460 bb_error_msg_and_die("%s: unknown %s", protocol, "address family"); 479 bb_error_msg_and_die("%s: unknown %s", protocol, "address family");
461 } 480 }
462 if (option_mask32 & ARP_OPT_A || option_mask32 & ARP_OPT_p) { 481 if (opts & (ARP_OPT_A | ARP_OPT_p)) {
463 hw = get_hwtype(hw_type); 482 hw = get_hwtype(hw_type);
464 if (hw == NULL) 483 if (hw == NULL)
465 bb_error_msg_and_die("%s: unknown %s", hw_type, "hardware type"); 484 bb_error_msg_and_die("%s: unknown %s", hw_type, "hardware type");
466 hw_set = 1; 485 hw_set = 1;
467 } 486 }
468 //if (option_mask32 & ARP_OPT_i)... -i 487 //if (opts & ARP_OPT_i)... -i
469 488
470 if (ap->af != AF_INET) { 489 if (ap->af != AF_INET) {
471 bb_error_msg_and_die("%s: kernel only supports 'inet'", ap->name); 490 bb_error_msg_and_die("%s: kernel only supports 'inet'", ap->name);
@@ -482,16 +501,15 @@ int arp_main(int argc UNUSED_PARAM, char **argv)
482 bb_error_msg_and_die("%s: %s without ARP support", 501 bb_error_msg_and_die("%s: %s without ARP support",
483 hw->name, "hardware type"); 502 hw->name, "hardware type");
484 } 503 }
485 sockfd = xsocket(AF_INET, SOCK_DGRAM, 0);
486 504
487 /* Now see what we have to do here... */ 505 /* Now see what we have to do here... */
488 if (option_mask32 & (ARP_OPT_d|ARP_OPT_s)) { 506 if (opts & (ARP_OPT_d | ARP_OPT_s)) {
489 if (argv[0] == NULL) 507 if (argv[0] == NULL)
490 bb_error_msg_and_die("need host name"); 508 bb_error_msg_and_die("need host name");
491 if (option_mask32 & ARP_OPT_s) 509 if (opts & ARP_OPT_s)
492 return arp_set(argv); 510 return arp_set(argv);
493 return arp_del(argv); 511 return arp_del(argv);
494 } 512 }
495 //if (option_mask32 & ARP_OPT_a) - default 513 //if (opts & ARP_OPT_a) - default
496 return arp_show(argv[0]); 514 return arp_show(argv[0]);
497} 515}