mirror of
https://gitee.com/Vancouver2017/luban-lite-t3e-pro.git
synced 2025-12-14 10:28:54 +00:00
V1.0.5
This commit is contained in:
46
packages/third-party/lwip/nettools/nettools.c
vendored
46
packages/third-party/lwip/nettools/nettools.c
vendored
@@ -2,25 +2,33 @@
|
||||
* Copyright (c) 2023, ArtInChip Technology Co., Ltd
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Authors: lv.wu <lv.wu@artinchip.com>
|
||||
*
|
||||
* Authors: lv.wu <lv.wu@artinchip.com>
|
||||
*/
|
||||
|
||||
#include "lwip/netif.h"
|
||||
#include "stdio.h"
|
||||
#include "string.h"
|
||||
#include "rtthread.h"
|
||||
#include "lwip/dhcp.h"
|
||||
|
||||
#if defined(RT_USING_FINSH)
|
||||
#include <finsh.h>
|
||||
#elif defined(AIC_CONSOLE_BARE_DRV)
|
||||
#include <console.h>
|
||||
#endif
|
||||
|
||||
static void list_ifconfig(void)
|
||||
{
|
||||
struct netif *netif;
|
||||
|
||||
for (netif = netif_list; netif != NULL; netif = netif->next) {
|
||||
printf("%s%d:\n",netif->name, netif->num);
|
||||
printf(" IPv4 Address : %s\n", ip4addr_ntoa(&netif->ip_addr));
|
||||
printf(" Default Gateway: %s\n", ip4addr_ntoa(&netif->gw));
|
||||
printf(" Subnet mask : %s\n", ip4addr_ntoa(&netif->netmask));
|
||||
printf("%c%c%d:\n",netif->name[0], netif->name[1], netif->num);
|
||||
printf(" IPv4 Address : %s\n", ip_ntoa(&netif->ip_addr));
|
||||
printf(" Default Gateway: %s\n", ip_ntoa(&netif->gw));
|
||||
printf(" Subnet mask : %s\n", ip_ntoa(&netif->netmask));
|
||||
#if LWIP_IPV6
|
||||
printf(" IPv6 Local address : %s\n", ip6addr_ntoa(netif_ip6_addr(netif, 0)));
|
||||
#endif
|
||||
printf(" MAC addr : %02x:%02x:%02x:%02x:%02x:%02x\n",
|
||||
netif->hwaddr[0],
|
||||
netif->hwaddr[1],
|
||||
@@ -31,7 +39,7 @@ static void list_ifconfig(void)
|
||||
}
|
||||
}
|
||||
|
||||
static void ifconfig(int argc, char *argv[])
|
||||
static int ifconfig(int argc, char *argv[])
|
||||
{
|
||||
struct netif *netif;
|
||||
ip4_addr_t ip;
|
||||
@@ -40,7 +48,7 @@ static void ifconfig(int argc, char *argv[])
|
||||
|
||||
if (argc == 1) {
|
||||
list_ifconfig();
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (argc != 5)
|
||||
@@ -49,7 +57,7 @@ static void ifconfig(int argc, char *argv[])
|
||||
netif = netif_find(argv[1]);
|
||||
if (netif == NULL) {
|
||||
printf("Can't find interface name %s\n", argv[1]);
|
||||
return;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!(ip4addr_aton(argv[2], &ip) && \
|
||||
@@ -57,7 +65,7 @@ static void ifconfig(int argc, char *argv[])
|
||||
ip4addr_aton(argv[4], &netmask))) {
|
||||
printf("Error ip information\n\tip:%s, gw:%s, netmask: %s\n",
|
||||
argv[2], argv[3], argv[4]);
|
||||
return;
|
||||
return -1;
|
||||
}
|
||||
|
||||
#if LWIP_DHCP
|
||||
@@ -71,17 +79,20 @@ static void ifconfig(int argc, char *argv[])
|
||||
|
||||
netif_set_up(netif);
|
||||
|
||||
return;
|
||||
return 0;
|
||||
usage:
|
||||
printf("ifconfig [interface] [ip] [gw] [netmask]\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
#ifdef RT_USING_FINSH
|
||||
MSH_CMD_EXPORT(ifconfig, list/config all net information);
|
||||
#elif defined(AIC_CONSOLE_BARE_DRV)
|
||||
CONSOLE_CMD(ifconfig, ifconfig, "list/config all net information");
|
||||
#endif
|
||||
|
||||
#if LWIP_DHCP
|
||||
static void dhcpc(int argc, char *argv[])
|
||||
static int dhcpc(int argc, char *argv[])
|
||||
{
|
||||
struct netif *netif;
|
||||
|
||||
@@ -91,7 +102,7 @@ static void dhcpc(int argc, char *argv[])
|
||||
netif = netif_find(argv[1]);
|
||||
if (netif == NULL) {
|
||||
printf("Can't find interface name %s\n", argv[1]);
|
||||
return;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!strcmp(argv[2], "start"))
|
||||
@@ -99,12 +110,15 @@ static void dhcpc(int argc, char *argv[])
|
||||
else if (!strcmp(argv[2], "stop"))
|
||||
dhcp_stop(netif);
|
||||
|
||||
return;
|
||||
return 0;
|
||||
|
||||
usage:
|
||||
printf("dhcpc [interface] [start/stop]\n");
|
||||
return -1;
|
||||
}
|
||||
#ifdef RT_USING_FINSH
|
||||
MSH_CMD_EXPORT(dhcpc, dhcp start or stop);
|
||||
MSH_CMD_EXPORT(dhcpc, dhcp client start or stop);
|
||||
#elif defined(AIC_CONSOLE_BARE_DRV)
|
||||
CONSOLE_CMD(dhcpc, dhcpc, "dhcp client start or stop");
|
||||
#endif
|
||||
#endif /* LWIP_DHCP */
|
||||
|
||||
Reference in New Issue
Block a user