27 |
#define DFLT_AF "inet" |
#define DFLT_AF "inet" |
28 |
#define DFLT_HW "ether" |
#define DFLT_HW "ether" |
29 |
|
|
30 |
#define ARP_OPT_A (0x1) |
enum { |
31 |
#define ARP_OPT_p (0x2) |
ARP_OPT_A = (1 << 0), |
32 |
#define ARP_OPT_H (0x4) |
ARP_OPT_p = (1 << 1), |
33 |
#define ARP_OPT_t (0x8) |
ARP_OPT_H = (1 << 2), |
34 |
#define ARP_OPT_i (0x10) |
ARP_OPT_t = (1 << 3), |
35 |
#define ARP_OPT_a (0x20) |
ARP_OPT_i = (1 << 4), |
36 |
#define ARP_OPT_d (0x40) |
ARP_OPT_a = (1 << 5), |
37 |
#define ARP_OPT_n (0x80) /* do not resolve addresses */ |
ARP_OPT_d = (1 << 6), |
38 |
#define ARP_OPT_D (0x100) /* HW-address is devicename */ |
ARP_OPT_n = (1 << 7), /* do not resolve addresses */ |
39 |
#define ARP_OPT_s (0x200) |
ARP_OPT_D = (1 << 8), /* HW-address is devicename */ |
40 |
#define ARP_OPT_v (0x400 * DEBUG) /* debugging output flag */ |
ARP_OPT_s = (1 << 9), |
41 |
|
ARP_OPT_v = (1 << 10) * DEBUG, /* debugging output flag */ |
42 |
|
}; |
43 |
static const struct aftype *ap; /* current address family */ |
|
44 |
static const struct hwtype *hw; /* current hardware type */ |
enum { |
45 |
static int sockfd; /* active socket descriptor */ |
sockfd = 3, /* active socket descriptor */ |
46 |
static smallint hw_set; /* flag if hw-type was set (-H) */ |
}; |
47 |
static const char *device = ""; /* current device */ |
|
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 |
|
}; |
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 |
|
|
64 |
|
|
65 |
static const char options[] ALIGN1 = |
static const char options[] ALIGN1 = |
66 |
"pub\0" |
"pub\0" |
461 |
{ |
{ |
462 |
const char *hw_type = "ether"; |
const char *hw_type = "ether"; |
463 |
const char *protocol; |
const char *protocol; |
464 |
|
unsigned opts; |
465 |
|
|
466 |
|
INIT_G(); |
467 |
|
|
468 |
/* Initialize variables... */ |
xmove_fd(xsocket(AF_INET, SOCK_DGRAM, 0), sockfd); |
469 |
ap = get_aftype(DFLT_AF); |
ap = get_aftype(DFLT_AF); |
470 |
if (!ap) |
if (!ap) |
471 |
bb_error_msg_and_die("%s: %s not supported", DFLT_AF, "address family"); |
bb_error_msg_and_die("%s: %s not supported", DFLT_AF, "address family"); |
472 |
|
|
473 |
getopt32(argv, "A:p:H:t:i:adnDsv", &protocol, &protocol, |
opts = getopt32(argv, "A:p:H:t:i:adnDsv", &protocol, &protocol, |
474 |
&hw_type, &hw_type, &device); |
&hw_type, &hw_type, &device); |
475 |
argv += optind; |
argv += optind; |
476 |
if (option_mask32 & ARP_OPT_A || option_mask32 & ARP_OPT_p) { |
if (opts & (ARP_OPT_A | ARP_OPT_p)) { |
477 |
ap = get_aftype(protocol); |
ap = get_aftype(protocol); |
478 |
if (ap == NULL) |
if (ap == NULL) |
479 |
bb_error_msg_and_die("%s: unknown %s", protocol, "address family"); |
bb_error_msg_and_die("%s: unknown %s", protocol, "address family"); |
480 |
} |
} |
481 |
if (option_mask32 & ARP_OPT_A || option_mask32 & ARP_OPT_p) { |
if (opts & (ARP_OPT_A | ARP_OPT_p)) { |
482 |
hw = get_hwtype(hw_type); |
hw = get_hwtype(hw_type); |
483 |
if (hw == NULL) |
if (hw == NULL) |
484 |
bb_error_msg_and_die("%s: unknown %s", hw_type, "hardware type"); |
bb_error_msg_and_die("%s: unknown %s", hw_type, "hardware type"); |
485 |
hw_set = 1; |
hw_set = 1; |
486 |
} |
} |
487 |
//if (option_mask32 & ARP_OPT_i)... -i |
//if (opts & ARP_OPT_i)... -i |
488 |
|
|
489 |
if (ap->af != AF_INET) { |
if (ap->af != AF_INET) { |
490 |
bb_error_msg_and_die("%s: kernel only supports 'inet'", ap->name); |
bb_error_msg_and_die("%s: kernel only supports 'inet'", ap->name); |
501 |
bb_error_msg_and_die("%s: %s without ARP support", |
bb_error_msg_and_die("%s: %s without ARP support", |
502 |
hw->name, "hardware type"); |
hw->name, "hardware type"); |
503 |
} |
} |
|
sockfd = xsocket(AF_INET, SOCK_DGRAM, 0); |
|
504 |
|
|
505 |
/* Now see what we have to do here... */ |
/* Now see what we have to do here... */ |
506 |
if (option_mask32 & (ARP_OPT_d|ARP_OPT_s)) { |
if (opts & (ARP_OPT_d | ARP_OPT_s)) { |
507 |
if (argv[0] == NULL) |
if (argv[0] == NULL) |
508 |
bb_error_msg_and_die("need host name"); |
bb_error_msg_and_die("need host name"); |
509 |
if (option_mask32 & ARP_OPT_s) |
if (opts & ARP_OPT_s) |
510 |
return arp_set(argv); |
return arp_set(argv); |
511 |
return arp_del(argv); |
return arp_del(argv); |
512 |
} |
} |
513 |
//if (option_mask32 & ARP_OPT_a) - default |
//if (opts & ARP_OPT_a) - default |
514 |
return arp_show(argv[0]); |
return arp_show(argv[0]); |
515 |
} |
} |