1 /*
2  * Copyright (C) 2017-2019 Alibaba Group Holding Limited
3  */
4 #if AOS_COMP_CLI
5 #include <string.h>
6 #include <aos/cli.h>
7 #include <lwip/etharp.h>
8 
9 static void arp_command(char *buffer, int32_t buf_len, int32_t argc, char **argv);
10 
11 struct cli_command arp_cmd[] = {
12     { "arp", "arp app", arp_command},
13 };
14 
arp_help_command(void)15 static void arp_help_command(void)
16 {
17     LWIP_DEBUGF( ARP_DEBUG, ("Usage: arp -a\n"));
18     LWIP_DEBUGF( ARP_DEBUG, ("Eample:\n"));
19     LWIP_DEBUGF( ARP_DEBUG, ("arp -a\n"));
20 }
21 
arp_query_command(void)22 static void arp_query_command(void)
23 {
24     if (etharp_info_print() < 0) {
25         LWIP_DEBUGF( ARP_DEBUG, ("arp list empty!\n"));
26     }
27 }
28 
arp_command(char * buffer,int32_t buf_len,int32_t argc,char ** argv)29 static void arp_command(char *buffer, int32_t buf_len, int32_t argc, char **argv)
30 {
31     if (argc < 2) {
32         LWIP_DEBUGF( ARP_DEBUG, ("%s, invalid command\n", __func__));
33         arp_help_command();
34         return;
35     }
36 
37     if (strcmp(argv[1], "-a") == 0) {
38         arp_query_command();
39     } else {
40         arp_help_command();
41     }
42 }
43 
arp_cli_register(void)44 int32_t arp_cli_register(void)
45 {
46     if (0 == aos_cli_register_commands(arp_cmd, 1)) {
47         return 0;
48     }
49 
50     return -1;
51 }
52 #endif /* AOS_COMP_CLI */
53