32#include "../core/ipv4/etharp.c"
33#define icmp6_hdr netinet_icmp6_hdr
34#include <netinet/icmp6.h>
39#if LWIP_ENABLE_LOS_SHELL_CMD
41#include "lwip/tcpip.h"
43#include "lwip/netdb.h"
44#include "lwip/stats.h"
47#include "netif/etharp.h"
48#include "lwip/ip_addr.h"
49#include "lwip/ip6_addr.h"
51#include "lwip/priv/nd6_priv.h"
53#include "lwip/inet_chksum.h"
69#include "lwip/priv/tcp_priv.h"
80#define LWIP_STATIC static
90#define LWIP_MAX_PING6_ARG_COUNT 64
91#define LWIP_PING6_STANDARD_PKT_SIZE 56
92#define LWIP_PING6_STARTING_SEQ_NUM 0x2255
93#define LWIP_PING6_OUT_OF_ORDER_MAGNITUDE 1
95#define LWIP_PING6_COUNT_ARG 1
96#define LWIP_PING6_SOURCE_ADDRESS_ARG 2
97#define LWIP_PING6_INTERFACE_ARG 4
98#define LWIP_PING6_HOSTNAME_ARG 8
99#define LWIP_PING6_DEFAULT_SOCKET 16
106int print_netif(
struct netif *netif,
char *print_buf,
unsigned int buf_len);
136LWIP_STATIC
unsigned int get_hostip(
const char *hname);
145#ifdef LWIP_DEBUG_INFO
195#define IFCONFIG_OPTION_SET_IP (1)
196#define IFCONFIG_OPTION_SET_NETMASK (1 << 1)
197#define IFCONFIG_OPTION_SET_GW (1 << 2)
198#define IFCONFIG_OPTION_SET_HW (1 << 3)
199#define IFCONFIG_OPTION_SET_UP (1 << 4)
200#define IFCONFIG_OPTION_SET_DOWN (1 << 5)
201#define IFCONFIG_OPTION_SET_MTU (1 << 6)
202#define IFCONFIG_OPTION_DEL_IP (1 << 7)
204#define NETSTAT_ENTRY_SIZE 120
205#define MAX_NETSTAT_ENTRY (NETSTAT_ENTRY_SIZE * (MEMP_NUM_TCP_PCB + MEMP_NUM_UDP_PCB + MEMP_NUM_TCP_PCB_LISTEN + 1))
207#define PRINT_BUF_LEN 1024
208#define MAX_MACADDR_STRING_LENGTH 18
210#define CONVERT_STRING_TO_HEX(_src, _dest) \
212 const char *_srcString = (char *)_src; \
214 while (*_srcString) { \
215 _dest = (unsigned char)((_dest << 4) & 0xFF); \
216 if ((*_srcString >= 48) && (*_srcString <= 57)) \
217 _dest |= (unsigned char)(*_srcString - 48); \
218 else if ((*_srcString >= 65 && *_srcString <= 70)) \
219 _dest |= (unsigned char)((*_srcString - 65) + 10); \
220 else if ((*_srcString >= 97 && *_srcString <= 102)) \
221 _dest |= (unsigned char)((*_srcString - 97) + 10); \
227#define ERR_IFCONFIG_STRING_PUT(ret, str) \
229 (ret) = snprintf_s(ifconfig_cmd->cb_print_buf + ifconfig_cmd->print_len, \
230 PRINT_BUF_LEN - ifconfig_cmd->print_len, \
231 ((PRINT_BUF_LEN - ifconfig_cmd->print_len) - 1), (str)); \
232 if (((ret) > 0) && ((unsigned int)(ret) < (PRINT_BUF_LEN - ifconfig_cmd->print_len))) \
233 ifconfig_cmd->print_len += (unsigned int)(ret); \
236#define LWIP_MSECS_TO_SECS(time_in_msecs) (time_in_msecs / 1000)
269int print_netif(
struct netif *netif,
char *print_buf,
unsigned int buf_len)
272 char *tmp = print_buf;
280 if (netif->link_layer_type == LOOPBACK_IF) {
281 ret = snprintf_s(tmp, buf_len, (buf_len - 1),
"%.2s\t", netif->name);
283 ret = snprintf_s(tmp, buf_len, (buf_len - 1),
"%s\t", netif_get_name(netif));
285 if ((ret <= 0) || ((
unsigned int)ret >= buf_len))
288 buf_len -= (
unsigned int)ret;
290 ret = snprintf_s(tmp, buf_len, (buf_len - 1),
"ip:%s ", ipaddr_ntoa(&netif->ip_addr));
291 if ((ret <= 0) || ((
unsigned int)ret >= buf_len))
294 buf_len -= (
unsigned int)ret;
296 ret = snprintf_s(tmp, buf_len, (buf_len - 1),
"netmask:%s ", ipaddr_ntoa(&netif->netmask));
297 if ((ret <= 0) || ((
unsigned int)ret >= buf_len))
300 buf_len -= (
unsigned int)ret;
302 ret = snprintf_s(tmp, buf_len, (buf_len - 1),
"gateway:%s\n", ipaddr_ntoa(&netif->gw));
303 if ((ret <= 0) || ((
unsigned int)ret >= buf_len))
306 buf_len -= (
unsigned int)ret;
310 for (i = 0; i < LWIP_IPV6_NUM_ADDRESSES; i++) {
312 if (!ip6_addr_isvalid(netif->ip6_addr_state[i])) {
315 addr = ip6addr_ntoa((
const ip6_addr_t *)&netif->ip6_addr[i]);
316 ret = snprintf_s(tmp, buf_len, (buf_len - 1),
"\tip6: %s/64\n", addr ? addr :
"::");
317 if ((ret <= 0) || ((
unsigned int)ret >= buf_len))
320 buf_len -= (
unsigned int)ret;
324 ret = snprintf_s(tmp, buf_len, (buf_len - 1),
"\tHWaddr ");
325 if ((ret <= 0) || ((
unsigned int)ret >= buf_len))
328 buf_len -= (
unsigned int)ret;
330 for (i = 0; i < netif->hwaddr_len - 1; i++) {
331 ret = snprintf_s(tmp, buf_len, (buf_len - 1),
"%02x:", netif->hwaddr[i]);
332 if ((ret <= 0) || ((
unsigned int)ret >= buf_len))
335 buf_len -= (
unsigned int)ret;
338 ret = snprintf_s(tmp, buf_len, (buf_len - 1),
"%02x", netif->hwaddr[i]);
339 if ((ret <= 0) || ((
unsigned int)ret >= buf_len))
342 buf_len -= (
unsigned int)ret;
344 ret = snprintf_s(tmp, buf_len, (buf_len - 1),
" MTU:%d %s", netif->mtu,
345 netif->flags & NETIF_FLAG_UP ?
"Running" :
"Stop");
346 if ((ret <= 0) || ((
unsigned int)ret >= buf_len))
349 buf_len -= (
unsigned int)ret;
351 if (netif_default == netif && netif_is_up(netif)) {
352 ret = snprintf_s(tmp, buf_len, (buf_len - 1),
" %s",
"Default");
353 if ((ret <= 0) || ((
unsigned int)ret >= buf_len))
356 buf_len -= (
unsigned int)ret;
359 ret = snprintf_s(tmp, buf_len, (buf_len - 1),
" %s\n", netif->flags & NETIF_FLAG_LINK_UP ?
"Link UP" :
"Link Down");
360 if ((ret <= 0) || ((
unsigned int)ret >= buf_len))
365 ret = snprintf_s(tmp, buf_len, (buf_len - 1),
"\tRX packets:%u ",
366 netif->mib2_counters.ifinucastpkts + netif->mib2_counters.ifinnucastpkts);
367 if ((ret <= 0) || ((
unsigned int)ret >= buf_len))
370 buf_len -= (
unsigned int)ret;
372 ret = snprintf_s(tmp, buf_len, (buf_len - 1),
"errors:%u ", netif->mib2_counters.ifinerrors);
373 if ((ret <= 0) || ((
unsigned int)ret >= buf_len))
376 buf_len -= (
unsigned int)ret;
378 ret = snprintf_s(tmp, buf_len, (buf_len - 1),
"dropped:%u ", netif->mib2_counters.ifindiscards);
379 if ((ret <= 0) || ((
unsigned int)ret >= buf_len))
382 buf_len -= (
unsigned int)ret;
384 ret = snprintf_s(tmp, buf_len, (buf_len - 1),
"overruns:%u\n", netif->mib2_counters.ifinoverruns);
385 if ((ret <= 0) || ((
unsigned int)ret >= buf_len))
388 buf_len -= (
unsigned int)ret;
390 ret = snprintf_s(tmp, buf_len, (buf_len - 1),
"\tTX packets:%u ",
391 netif->mib2_counters.ifoutucastpkts + netif->mib2_counters.ifoutnucastpkts);
392 if ((ret <= 0) || ((
unsigned int)ret >= buf_len))
395 buf_len -= (
unsigned int)ret;
397 ret = snprintf_s(tmp, buf_len, (buf_len - 1),
"errors:%u ", netif->mib2_counters.ifouterrors);
398 if ((ret <= 0) || ((
unsigned int)ret >= buf_len))
401 buf_len -= (
unsigned int)ret;
403 ret = snprintf_s(tmp, buf_len, (buf_len - 1),
"dropped:%u\n", netif->mib2_counters.ifoutdiscards);
404 if ((ret <= 0) || ((
unsigned int)ret >= buf_len))
407 buf_len -= (
unsigned int)ret;
409 ret = snprintf_s(tmp, buf_len, (buf_len - 1),
"\tRX bytes:%u ", netif->mib2_counters.ifinoctets);
410 if ((ret <= 0) || ((
unsigned int)ret >= buf_len))
413 buf_len -= (
unsigned int)ret;
415 ret = snprintf_s(tmp, buf_len, (buf_len - 1),
"TX bytes:%u\n", netif->mib2_counters.ifoutoctets);
416 if ((ret <= 0) || ((
unsigned int)ret >= buf_len))
419 buf_len -= (
unsigned int)ret;
423 return (
int)(tmp - print_buf);
431 struct netif *netif = NULL;
435 if (netif_list == NULL) {
437 ((PRINT_BUF_LEN - ifconfig_cmd->
print_len) - 1),
"Device not init\n");
438 if ((ret > 0) && ((
unsigned int)ret < (PRINT_BUF_LEN - ifconfig_cmd->
print_len))) {
445 if (ifconfig_cmd->
iface[0] ==
'\0') {
447 for (netif = netif_list; netif != NULL; netif = netif->next) {
449 PRINT_BUF_LEN - ifconfig_cmd->
print_len);
453 netif = netif_find(ifconfig_cmd->
iface);
456 (PRINT_BUF_LEN - ifconfig_cmd->
print_len),
457 ((PRINT_BUF_LEN - ifconfig_cmd->
print_len) - 1),
"Device not found\n");
458 if ((ret > 0) && ((
unsigned int)ret < (PRINT_BUF_LEN - ifconfig_cmd->
print_len))) {
467 PRINT_BUF_LEN - ifconfig_cmd->
print_len);
479 struct netif *netif = NULL;
484 struct netif *loc_netif = NULL;
490 netif = netif_find(ifconfig_cmd->
iface);
492 ERR_IFCONFIG_STRING_PUT(ret,
"Device not found\n");
496 if (ifconfig_cmd->
option & IFCONFIG_OPTION_SET_UP) {
497 (
void)netif_set_up(netif);
499 }
else if (ifconfig_cmd->
option & IFCONFIG_OPTION_SET_DOWN) {
500 (
void)netif_set_down(netif);
504 if ((ifconfig_cmd->
option & IFCONFIG_OPTION_SET_IP) ||
505 (ifconfig_cmd->
option & IFCONFIG_OPTION_SET_NETMASK) ||
506 (ifconfig_cmd->
option & IFCONFIG_OPTION_SET_HW)) {
507 (
void)netif_set_down(netif);
510 if (ifconfig_cmd->
option & IFCONFIG_OPTION_SET_IP) {
512 if (IP_IS_V4_VAL(ifconfig_cmd->
ip_addr)) {
514 if (ip_addr_ismulticast_val(&
ip_addr) || ip_addr_isbroadcast_val(&
ip_addr, netif) ||
516 ERR_IFCONFIG_STRING_PUT(ret,
"Don't set ip as a multicast/broadcast/0/loopback address!\n");
521 if (!ip_addr_netcmp_val(&
ip_addr, &netif->ip_addr, ip_2_ip4(&netif->netmask))) {
522 ip_addr_set_zero(&netif->gw);
523 if (netif == netif_default) {
524 (
void)netif_set_default(NULL);
529 loc_netif = netif_list;
530 while (loc_netif != NULL) {
531 if (loc_netif == netif) {
532 loc_netif = loc_netif->next;
535 if (IP_IS_V4_VAL(ifconfig_cmd->
ip_addr) && ip_addr_cmp(&netif->netmask, &loc_netif->netmask) &&
536 ip_addr_netcmp_val(&loc_netif->ip_addr, &
ip_addr, ip_2_ip4(&netif->netmask))) {
537 ERR_IFCONFIG_STRING_PUT(ret,
"Duplicate network!\n");
540 loc_netif = loc_netif->next;
544 if (netif_dhcp_data(netif) && netif_dhcp_data(netif)->state != DHCP_STATE_OFF) {
548 netif_set_ipaddr(netif, ip_2_ip4(&
ip_addr));
549 }
else if (IP_IS_V6_VAL(ifconfig_cmd->
ip_addr)) {
551 err = netif_add_ip6_address(netif, ip_2_ip6(&
ip_addr), &idx);
552 if (err != ERR_OK || idx == -1) {
553 ERR_IFCONFIG_STRING_PUT(ret,
"The IPv6 has reached the Global address limit, "
554 "you should delete one address before add!\n");
560 if (ifconfig_cmd->
option & IFCONFIG_OPTION_DEL_IP) {
564 if (ifconfig_cmd->
option & IFCONFIG_OPTION_SET_NETMASK) {
567 if (!ip_addr_netmask_valid(ip_2_ip4(&
netmask))) {
568 ERR_IFCONFIG_STRING_PUT(ret,
"ifconfig: netmask is invalid!\n");
573 if (netif_dhcp_data(netif) && netif_dhcp_data(netif)->state != DHCP_STATE_OFF) {
577 if (netif_ip4_netmask(netif)->addr != ip_2_ip4(&
netmask)->addr) {
579 loc_netif = netif_list;
580 while (loc_netif != NULL) {
581 if (loc_netif == netif) {
582 loc_netif = loc_netif->next;
585 if (ip_addr_cmp(&loc_netif->netmask, &
netmask) &&
586 ip_addr_netcmp(&loc_netif->ip_addr, &netif->ip_addr, ip_2_ip4(&
netmask))) {
587 ERR_IFCONFIG_STRING_PUT(ret,
"Duplicate network!\n");
590 loc_netif = loc_netif->next;
592 netif_set_netmask(netif, ip_2_ip4(&
netmask));
594 if (!ip_addr_netcmp(&netif->gw, &netif->ip_addr, ip_2_ip4(&
netmask))) {
595 ip_addr_set_zero(&(netif->gw));
596 if (netif == netif_default) {
597 (
void)netif_set_default(NULL);
603 if ((ifconfig_cmd->
option & IFCONFIG_OPTION_SET_HW) &&
605 ERR_IFCONFIG_STRING_PUT(ret,
"Failed to update the hwaddr of the device!\n");
606 (
void)netif_set_up(netif);
610 if ((ifconfig_cmd->
option & IFCONFIG_OPTION_SET_IP) ||
611 (ifconfig_cmd->
option & IFCONFIG_OPTION_SET_NETMASK) ||
612 (ifconfig_cmd->
option & IFCONFIG_OPTION_SET_HW)) {
613 (
void)netif_set_up(netif);
616 if (ifconfig_cmd->
option & IFCONFIG_OPTION_SET_GW) {
617 ip_addr_set_val(&
gw, &ifconfig_cmd->
gw);
620 if (ip_addr_ismulticast_val(&
gw) || ip_addr_isbroadcast_val(&
gw, netif) ||
621 ip_addr_isany(&
gw) || ip_addr_isloopback(&
gw)) {
622 ERR_IFCONFIG_STRING_PUT(ret,
"Don't set gateway as a multicast/broadcast/0/loopback address!\n");
627 if (!ip_addr_netcmp_val(&
gw, &netif->ip_addr, ip_2_ip4(&netif->netmask))) {
628 ERR_IFCONFIG_STRING_PUT(ret,
"The address is unreachable!\n");
632 if (netif_default != netif) {
633 ip_addr_set_zero(&netif->gw);
634 (
void)netif_set_default(netif);
638 if (netif_dhcp_data(netif) && netif_dhcp_data(netif)->state != DHCP_STATE_OFF) {
642 netif_set_gw(netif, ip_2_ip4(&
gw));
645 if (ifconfig_cmd->
option & IFCONFIG_OPTION_SET_MTU) {
648 ERR_IFCONFIG_STRING_PUT(ret,
"Invalid MTU\n");
658 static const char *SIZES[] = {
"B",
"KB",
"MB",
"GB"};
662 while ((size >= 1024) && (divis < ((
sizeof(SIZES) /
sizeof(
char *)) - 1))) {
668 PRINTK(
"(%.1f %s) \r\n", (
float)size + (
float)rem / 1024.0, SIZES[divis]);
676 "\n[interface ipaddr] <netmask mask> <gateway gw>"\
677 "\n[interface inet6 add|del ipaddr]"\
678 "\n[interface hw ether MAC]"\
679 "\n[interface mtu NN]"\
680 "\n[interface up|down]\n",
693 u32_t stat_rx_or_tx_cnt;
694 u32_t stat_rx_or_tx_bytes;
699 struct netif *netiftmp = NULL;
700#if LWIP_ENABLE_IP_CONFLICT_SIGNAL
712 PRINTK(
"%s: tcpip_init have not been called\n", __FUNCTION__);
743 if (strcmp(
"-a", argv[0]) == 0) {
745 stat_rx_or_tx_cnt = lwip_stats.ip.recv;
746 stat_err_cnt = (u32_t)(lwip_stats.ip.ip_rx_err +
747 lwip_stats.ip.lenerr +
748 lwip_stats.ip.chkerr +
749 lwip_stats.ip.opterr +
750 lwip_stats.ip.proterr);
751 stat_drop_cnt = (u32_t)(lwip_stats.ip.drop + lwip_stats.link.link_rx_drop);
752 stat_rx_or_tx_bytes = lwip_stats.ip.ip_rx_bytes;
754 PRINTK(
"%18s:%u\t errors:%u\t ip dropped:%u\t link dropped:%u\t overrun:%d\t bytes:%u ",
759 lwip_stats.link.link_rx_drop,
760 lwip_stats.ip.link_rx_overrun,
761 stat_rx_or_tx_bytes);
766 stat_rx_or_tx_cnt = lwip_stats.ip6.recv;
767 stat_err_cnt = (u32_t)(lwip_stats.ip6.ip_rx_err +
768 lwip_stats.ip6.lenerr +
769 lwip_stats.ip6.chkerr +
770 lwip_stats.ip6.opterr +
771 lwip_stats.ip6.proterr);
772 stat_drop_cnt = lwip_stats.ip6.drop;
773 stat_rx_or_tx_bytes = lwip_stats.ip6.ip_rx_bytes;
775 PRINTK(
"%18s:%u\t errors:%u\t dropped:%u\t overrun:%d\t bytes:%u ",
780 lwip_stats.ip.link_rx_overrun,
781 stat_rx_or_tx_bytes);
786 stat_rx_or_tx_cnt = (u32_t)(lwip_stats.ip.fw + lwip_stats.ip.xmit);
787 stat_err_cnt = (u32_t)(lwip_stats.ip.rterr + lwip_stats.ip.ip_tx_err);
789 stat_drop_cnt = lwip_stats.link.link_tx_drop;
790 stat_rx_or_tx_bytes = lwip_stats.ip.ip_tx_bytes;
792 PRINTK(
"%18s:%u\t errors:%u\t link dropped:%u\t overrun:0\t bytes:%u",
797 stat_rx_or_tx_bytes);
802 stat_rx_or_tx_cnt = (u32_t)(lwip_stats.ip6.fw + lwip_stats.ip6.xmit);
803 stat_err_cnt = (u32_t)(lwip_stats.ip6.rterr + lwip_stats.ip6.ip_tx_err);
804 stat_rx_or_tx_bytes = lwip_stats.ip6.ip_tx_bytes;
806 PRINTK(
"%18s:%u\t errors:%u\t overrun:0\t bytes:%u",
810 stat_rx_or_tx_bytes);
819 (
void)memset_s(&ifconfig_cmd,
sizeof(ifconfig_cmd), 0,
sizeof(ifconfig_cmd));
821 PRINTK(
"%s: sys_sem_new fail\n", __FUNCTION__);
828 if (strlen(argv[i]) < IFNAMSIZ) {
829 if (strncpy_s(ifconfig_cmd.
iface, IFNAMSIZ, argv[i], (strlen(argv[i]))) != EOK) {
831 PRINTK(
"ifconfig : strncpy_s error\n");
834 ifconfig_cmd.
iface[IFNAMSIZ - 1] =
'\0';
837 PRINTK(
"ifconfig : interface name is too big\n");
847 PRINTK(
"ifconfig : internal error, l:%d err:%d\n", __LINE__, ret);
861 PRINTK(
"ifconfig : internal error, l:%d err:%d\n", __LINE__, ret);
873 if (strcmp(
"up", argv[i]) == 0) {
874 ifconfig_cmd.
option |= IFCONFIG_OPTION_SET_UP;
879 PRINTK(
"ifconfig : internal error, l:%d err:%d\n", __LINE__, ret);
887 }
else if (strcmp(
"down", argv[i]) == 0) {
888 ifconfig_cmd.
option |= IFCONFIG_OPTION_SET_DOWN;
893 PRINTK(
"ifconfig : internal error, l:%d err:%d\n", __LINE__, ret);
905 if (netiftmp == NULL) {
907 PRINTK(
"ifconfig : Interface %s not found\n", ifconfig_cmd.
iface);
910#if LWIP_ENABLE_IP_CONFLICT_SIGNAL
911 old_ip4addr = ipaddr_addr(ipaddr_ntoa(&netiftmp->ip_addr));
914 if (!strcmp(argv[i],
"inet") || ip4addr_aton(argv[i], ip_2_ip4(&ifconfig_cmd.
ip_addr))) {
915 if (!strcmp(argv[i],
"inet")) {
921 if (!ip4addr_aton(argv[i + 1], ip_2_ip4(&ifconfig_cmd.
ip_addr))) {
923 PRINTK(
"ifconfig : Invalid IPv4 Address\n");
929 IP_SET_TYPE_VAL((ifconfig_cmd.
ip_addr), IPADDR_TYPE_V4);
931 if (!ip_addr_cmp(&ifconfig_cmd.
ip_addr, &netiftmp->ip_addr)) {
932 ifconfig_cmd.
option |= IFCONFIG_OPTION_SET_IP;
935 ifconfig_cmd.
option |= IFCONFIG_OPTION_SET_IP;
939 }
else if (!strcmp(argv[i],
"inet6")) {
944 if (strcmp(argv[i + 1],
"add") && strcmp(argv[i + 1],
"del")) {
951 PRINTK(
"ifconfig : Invalid IPv6 Address\n");
955 IP_SET_TYPE_VAL((ifconfig_cmd.
ip_addr), IPADDR_TYPE_V6);
956 ifconfig_cmd.
option |= (!strcmp(argv[i + 1],
"add") ? IFCONFIG_OPTION_SET_IP : IFCONFIG_OPTION_DEL_IP);
961 if (ifconfig_cmd.
option & IFCONFIG_OPTION_DEL_IP) {
969 if (strcmp(
"netmask", argv[i]) == 0 && (argc > 1) && (ipaddr_addr(argv[i + 1]) != IPADDR_NONE)) {
971 ip_addr_set_ip4_u32_val((ifconfig_cmd.
netmask), ipaddr_addr(argv[i + 1]));
972 ifconfig_cmd.
option |= IFCONFIG_OPTION_SET_NETMASK;
975 }
else if (strcmp(
"gateway", argv[i]) == 0 && (argc > 1) && (ipaddr_addr(argv[i + 1]) != IPADDR_NONE)) {
977 ip_addr_set_ip4_u32_val((ifconfig_cmd.
gw), ipaddr_addr(argv[i + 1]));
978 ifconfig_cmd.
option |= IFCONFIG_OPTION_SET_GW;
981 }
else if (strcmp(
"hw", argv[i]) == 0 && argc > 2 && strcmp(
"ether", argv[i + 1]) == 0) {
984 u32_t macaddrlen = strlen(argv[i + 2]) + 1;
985 char tmpStr[MAX_MACADDR_STRING_LENGTH];
986 char *tmpStr1 = NULL;
987 char *saveptr = NULL;
990 if (macaddrlen != MAX_MACADDR_STRING_LENGTH) {
992 PRINTK(
"ifconfig : wrong MAC address format\n");
996 if (strncpy_s(tmpStr, MAX_MACADDR_STRING_LENGTH, argv[i + 2], macaddrlen - 1) != 0) {
998 PRINTK(
"ifconfig : wrong MAC address\n");
1001 for (j = 0, tmpStr1 = tmpStr; j < 6; j++, tmpStr1 = NULL) {
1002 digit = strtok_r(tmpStr1,
":", &saveptr);
1003 if ((digit == NULL) || (strlen(digit) > 2)) {
1005 PRINTK(
"ifconfig : wrong MAC address format\n");
1008 CONVERT_STRING_TO_HEX(digit, ifconfig_cmd.
ethaddr[j]);
1010 ifconfig_cmd.
option |= IFCONFIG_OPTION_SET_HW;
1013 }
else if (!strcmp(
"mtu", argv[i]) && (argc > 1)) {
1015 if ((atoi(argv[i + 1]) < 0) || (atoi(argv[i + 1]) > 0xFFFF)) {
1017 PRINTK(
"\nifconfig: Invalid argument for mtu\n");
1018 goto ifconfig_error;
1021 ifconfig_cmd.
mtu = (u16_t)(atoi(argv[i + 1]));
1022 ifconfig_cmd.
option |= IFCONFIG_OPTION_SET_MTU;
1027 goto ifconfig_error;
1031#if LWIP_ARP && LWIP_ENABLE_IP_CONFLICT_SIGNAL
1032 if ((ifconfig_cmd.
option & IFCONFIG_OPTION_SET_IP) && IP_IS_V4_VAL((ifconfig_cmd.
ip_addr))) {
1036 PRINTK(
"ifconfig: internal error\n");
1044 if ((ifconfig_cmd.
option & IFCONFIG_OPTION_SET_IP) && IP_IS_V6_VAL((ifconfig_cmd.
ip_addr))) {
1048 PRINTK(
"ifconfig: internal error\n");
1056 if (ret != ERR_OK) {
1058#if LWIP_ARP && LWIP_ENABLE_IP_CONFLICT_SIGNAL
1059 if ((ifconfig_cmd.
option & IFCONFIG_OPTION_SET_IP) && IP_IS_V4_VAL((ifconfig_cmd.
ip_addr))) {
1066 if ((ifconfig_cmd.
option & IFCONFIG_OPTION_SET_IP) && IP_IS_V6_VAL((ifconfig_cmd.
ip_addr))) {
1072 PRINTK(
"%s : tcpip_callback failed in line %d : errnu %d", __FUNCTION__, __LINE__, ret);
1078#if LWIP_ARP && LWIP_ENABLE_IP_CONFLICT_SIGNAL
1080 if ((ifconfig_cmd.
option & IFCONFIG_OPTION_SET_IP) && IP_IS_V4_VAL((ifconfig_cmd.
ip_addr))) {
1086 PRINT_ERR(
"ifconfig: internal error\n");
1089 }
else if (err < DUP_ARP_DETECT_TIME) {
1091 PRINT_ERR(
"ifconfig: ip conflict!\n");
1092 ip_addr_set_ip4_u32_val(ifconfig_cmd.
ip_addr, old_ip4addr);
1094 if (ret != ERR_OK) {
1096 PRINTK(
"%s : tcpip_callback failed in line %d : errnu %d", __FUNCTION__, __LINE__, ret);
1108 if ((ifconfig_cmd.
option & IFCONFIG_OPTION_SET_IP) && IP_IS_V6_VAL(ifconfig_cmd.
ip_addr)) {
1113 if (retval == SYS_ARCH_ERROR) {
1116 PRINT_ERR(
"ifconfig: internal error\n");
1118 }
else if (retval < DUP_ARP_DETECT_TIME) {
1120 struct netif *netif = NULL;
1121 PRINT_ERR(
"ifconfig: IP conflict!\n");
1123 i = netif_get_ip6_addr_match(netif, &ifconfig_cmd.
ip_addr.u_addr.ip6);
1125 netif->ip6_addr_state[i] = IP6_ADDR_INVALID;
1146#define ARP_OPTION_ADD 1
1148#define ARP_OPTION_DEL 2
1150#define ARP_OPTION_SHOW 3
1176 char *tmp = printf_buf;
1180 ret = snprintf_s(tmp, buf_len, (buf_len - 1),
"%-24s%-24s%-12s%-12s\n",
"Address",
"HWaddress",
"Iface",
"Type");
1181 if ((ret <= 0) || ((
unsigned int)ret >= buf_len))
1184 buf_len -= (
unsigned int)ret;
1186 if (netif != NULL) {
1187 for (i = 0; i < ARP_TABLE_SIZE; ++i) {
1188 state = arp_table[i].state;
1189 if (((state == ETHARP_STATE_STABLE)
1190 #
if ETHARP_SUPPORT_STATIC_ENTRIES
1191 || (state == ETHARP_STATE_STATIC)
1193 ) && arp_table[i].netif) {
1195 if (strcmp(netif_get_name(netif), netif_get_name(arp_table[i].netif)) != 0) {
1199 ret = snprintf_s(tmp, buf_len, (buf_len - 1),
"%-24s%02X:%02X:%02X:%02X:%02X:%02X %s %s\n",
1200 ip4addr_ntoa(&arp_table[i].ipaddr),
1201 arp_table[i].ethaddr.addr[0], arp_table[i].ethaddr.addr[1],
1202 arp_table[i].ethaddr.addr[2], arp_table[i].ethaddr.addr[3],
1203 arp_table[i].ethaddr.addr[4], arp_table[i].ethaddr.addr[5],
1204 netif_get_name(netif),
1205#
if ETHARP_SUPPORT_STATIC_ENTRIES
1206 ((state == ETHARP_STATE_STATIC) ?
"static" :
"dynamic")
1211 if ((ret <= 0) || ((
unsigned int)ret >= buf_len))
1214 buf_len -= (
unsigned int)ret;
1218 for (i = 0; i < ARP_TABLE_SIZE; ++i) {
1219 state = arp_table[i].state;
1220 if (((state == ETHARP_STATE_STABLE)
1221 #
if ETHARP_SUPPORT_STATIC_ENTRIES
1222 || (state == ETHARP_STATE_STATIC)
1224 ) && arp_table[i].netif) {
1225 ret = snprintf_s(tmp, buf_len, (buf_len - 1),
"%-24s%02X:%02X:%02X:%02X:%02X:%02X %s %s\n",
1226 ip4addr_ntoa(&arp_table[i].ipaddr),
1227 arp_table[i].ethaddr.addr[0], arp_table[i].ethaddr.addr[1],
1228 arp_table[i].ethaddr.addr[2], arp_table[i].ethaddr.addr[3],
1229 arp_table[i].ethaddr.addr[4], arp_table[i].ethaddr.addr[5],
1230 netif_get_name(arp_table[i].netif),
1231#
if ETHARP_SUPPORT_STATIC_ENTRIES
1232 ((state == ETHARP_STATE_STATIC) ?
"static" :
"dynamic")
1237 if ((ret <= 0) || ((
unsigned int)ret >= buf_len))
1240 buf_len -= (
unsigned int)ret;
1253 struct netif *netif = NULL;
1254 struct eth_addr ethaddr;
1259 if (arp_cmd->
iface[0] ==
'd' && arp_cmd->
iface[1] ==
'e') {
1263 netif = netif_find(arp_cmd->
iface);
1264 if (netif == NULL) {
1265 (
void)snprintf_s(arp_cmd->
cb_print_buf, PRINT_BUF_LEN, (PRINT_BUF_LEN - 1),
"No such device\n");
1272 case ARP_OPTION_SHOW:
1273 if (netif != NULL) {
1280 case ARP_OPTION_ADD:
1281#if ETHARP_SUPPORT_STATIC_ENTRIES
1282 ipaddr.addr = arp_cmd->
ipaddr;
1283 (
void)memcpy_s(ethaddr.addr,
sizeof(ethaddr.addr), arp_cmd->
ethaddr, 6);
1284 if (netif != NULL) {
1285 if (ip4_addr_netcmp(&ipaddr, ip_2_ip4(&(netif->ip_addr)), ip_2_ip4(&(netif->netmask)))) {
1287 ETHARP_FLAG_TRY_HARD | ETHARP_FLAG_STATIC_ENTRY);
1292 ret = etharp_add_static_entry(&ipaddr, ðaddr);
1299 case ARP_OPTION_DEL:
1300 ipaddr.addr = arp_cmd->
ipaddr;
1301 (
void)memcpy_s(ethaddr.addr,
sizeof(ethaddr.addr), arp_cmd->
ethaddr, 6);
1302 if (netif != NULL) {
1305 for (netif = netif_list; netif != NULL; netif = netif->next) {
1307 if (ret == ERR_OK) {
1316 (
void)snprintf_s(arp_cmd->
cb_print_buf, PRINT_BUF_LEN, (PRINT_BUF_LEN - 1),
"Error\n");
1321 if (type == ARP_OPTION_ADD || type == ARP_OPTION_DEL) {
1322 if (ret == ERR_MEM) {
1323 (
void)snprintf_s(arp_cmd->
cb_print_buf, PRINT_BUF_LEN, (PRINT_BUF_LEN - 1),
"Out of memory error\n");
1324 }
else if (ret == ERR_ARG) {
1325 (
void)snprintf_s(arp_cmd->
cb_print_buf, PRINT_BUF_LEN, (PRINT_BUF_LEN - 1),
"Illegal argument\n");
1326 }
else if (ret == ERR_RTE) {
1327 (
void)snprintf_s(arp_cmd->
cb_print_buf, PRINT_BUF_LEN, (PRINT_BUF_LEN - 1),
"Network is unreachable\n");
1329 (
void)snprintf_s(arp_cmd->
cb_print_buf, PRINT_BUF_LEN, (PRINT_BUF_LEN - 1),
"Successed\n");
1342 "\n%s [-i IF] -s IPADDR HWADDR"
1343 "\n%s [-i IF] -d IPADDR\n",
1352 size_t interface_len = 0;
1356 PRINTK(
"%s: tcpip_init have not been called\n", __FUNCTION__);
1360 arp_cmd.
iface[0] =
'd';
1361 arp_cmd.
iface[1] =
'e';
1362 arp_cmd.
iface[2] =
'0';
1363 arp_cmd.
option = ARP_OPTION_SHOW;
1366 PRINTK(
"%s: sys_sem_new fail\n", __FUNCTION__);
1372 if (strcmp(
"-i", argv[i]) == 0 && (argc > 1)) {
1374 interface_len = strlen(argv[i + 1]);
1375 if (interface_len < IFNAMSIZ) {
1376 if (strncmp(argv[i + 1],
"lo", (
sizeof(
"lo") - 1)) == 0) {
1377 PRINTK(
"Illegal operation\n");
1380 if (strncpy_s(arp_cmd.
iface, IFNAMSIZ, argv[i + 1], interface_len) != EOK) {
1381 PRINTK(
"strncpy_s error\n");
1384 arp_cmd.
iface[interface_len] =
'\0';
1386 PRINTK(
"Iface name is big \n");
1391 }
else if (strcmp(
"-d", argv[i]) == 0 && (argc > 1)) {
1393 arp_cmd.
option = ARP_OPTION_DEL;
1396 if (arp_cmd.
ipaddr == IPADDR_NONE) {
1397 PRINTK(
"IP address is not correct!\n");
1403 }
else if (strcmp(
"-s", argv[i]) == 0 && (argc > 2)) {
1406 u32_t macaddrlen = strlen(argv[i + 2]) + 1;
1407 char tmpStr[MAX_MACADDR_STRING_LENGTH];
1408 char *tmpStr1 = NULL;
1409 char *saveptr1 = NULL;
1413 arp_cmd.
option = ARP_OPTION_ADD;
1416 if (arp_cmd.
ipaddr == IPADDR_NONE) {
1417 PRINTK(
"IP address is not correct!\n");
1422 if ((arp_cmd.
ipaddr & (u32_t)0x0000007fUL) == (u32_t)0x0000007fUL) {
1423 PRINTK(
"IP address is not correct!\n");
1427 if (macaddrlen != MAX_MACADDR_STRING_LENGTH) {
1428 PRINTK(
"Wrong MAC address length\n");
1432 if (strncpy_s(tmpStr, MAX_MACADDR_STRING_LENGTH, argv[i + 2], macaddrlen - 1) != 0) {
1433 PRINTK(
"Wrong MAC address\n");
1437 for (j = 0, tmpStr1 = tmpStr; j < 6; j++, tmpStr1 = NULL) {
1438 digit = strtok_r(tmpStr1,
":", &saveptr1);
1439 if ((digit == NULL) || (strlen(digit) > 2)) {
1440 PRINTK(
"MAC address is not correct\n");
1444 for (temp = digit; *temp !=
'\0'; temp++) {
1445 if (!isxdigit(*temp)) {
1446 PRINTK(
"MAC address is not correct\n");
1451 CONVERT_STRING_TO_HEX(digit, arp_cmd.
ethaddr[j]);
1462 if (ret != ERR_OK) {
1463 PRINTK(
"%s : tcpip_callback failed in line %d : errnu %d", __FUNCTION__, __LINE__, ret);
1479#ifdef LOSCFG_SHELL_CMD_DEBUG
1485 struct netif *netif = NULL;
1489 if (ifcmd_data == NULL) {
1492 netif = netif_find(ifcmd_data->
if_name);
1493 if (netif == NULL) {
1494 ifcmd_data->
err = ERR_VAL;
1496 (
void)netif_set_up(netif);
1497 ifcmd_data->
err = ERR_OK;
1505 struct netif *netif = NULL;
1509 if (ifcmd_data == NULL) {
1512 netif = netif_find(ifcmd_data->
if_name);
1513 if (netif == NULL) {
1514 ifcmd_data->
err = ERR_VAL;
1516 (
void)netif_set_down(netif);
1517 ifcmd_data->
err = ERR_OK;
1529 static struct hostent hostbuf;
1530 struct hostent *hp = NULL;
1531 const size_t hstbuflen = 1024;
1532 char tmphstbuf[1024];
1536 res = lwip_gethostbyname_r(host, &hostbuf, tmphstbuf, hstbuflen, &hp, &herr);
1538 if (res || hp == NULL)
1545 unsigned int ip = 0;
1549 if (pent == NULL || pent->h_addr == NULL)
1551 ret = memcpy_s(&ip,
sizeof(ip), pent->h_addr, 4);
1559#if LWIP_EXT_POLL_SUPPORT
1562#define PING_ZERO_DATA_LEN 8
1567 "\n ping [-n cnt] [-w interval] [-l data_len] destination"
1568 "\n ping [-t] [-w interval] destination"
1570 PRINTK(
"\n -t means ping forever, user can use -k to stop the forever ping\n");
1573LWIP_STATIC
int osPingFunc(u32_t destip, u32_t cnt, u32_t interval, u32_t data_len)
1576 struct sockaddr_in to;
1577 struct pbuf *pbuf_resp = NULL;
1578 struct icmp_echo_hdr *iecho = NULL;
1579 struct icmp_echo_hdr *iecho_resp = NULL;
1580 struct ip_hdr *iphdr_resp = NULL;
1586 u32_t failed_cnt = 0;
1587 struct timespec start, end;
1593 char *data_buf = NULL;
1594 BOOL timeout_flag =
false;
1597 iecho_len =
sizeof(
struct icmp_echo_hdr) + data_len;
1598 sfd =
lwip_socket(PF_INET, SOCK_RAW, IPPROTO_ICMP);
1600 perror(
"Ping socket");
1603 pbuf_resp = pbuf_alloc(PBUF_RAW, IP_HLEN +
sizeof(
struct icmp_echo_hdr), PBUF_RAM);
1604 if (pbuf_resp == NULL) {
1605 PRINTK(
"Ping: pbuf_resp malloc failed\n");
1609 iecho = (
struct icmp_echo_hdr *)mem_malloc(iecho_len);
1610 if (iecho == NULL) {
1611 PRINTK(
"Ping: echo request malloc failed\n");
1616 to.sin_family = AF_INET;
1617 to.sin_addr.s_addr = destip;
1620 if (data_len > PING_ZERO_DATA_LEN) {
1621 (
void)memset_s(iecho,
sizeof(
struct icmp_echo_hdr) + PING_ZERO_DATA_LEN,
1622 0,
sizeof(
struct icmp_echo_hdr) + PING_ZERO_DATA_LEN);
1623 data_buf = (
char *)iecho +
sizeof(
struct icmp_echo_hdr) + PING_ZERO_DATA_LEN;
1624 for (i = 0; i < data_len - PING_ZERO_DATA_LEN; i++) {
1625 *(data_buf + i) = i + 0x10;
1628 (
void)memset_s(iecho,
sizeof(
struct icmp_echo_hdr) + data_len, 0,
sizeof(
struct icmp_echo_hdr) + data_len);
1631 ICMPH_TYPE_SET(iecho, (u8_t)ICMP_ECHO);
1632 forever = (cnt ? 0 : 1);
1634 while (!
ping_kill && (forever || (i < cnt))) {
1635 iecho->seqno = htons((u16_t)i);
1637 iecho->chksum = inet_chksum((
void *)iecho, iecho_len);
1639 ret =
sendto(sfd, iecho, iecho_len, 0, (
struct sockaddr *)&to, (socklen_t)
sizeof(to));
1641 perror(
"Ping: sending ICMP echo request failed\n");
1652 pfd.events = POLLIN;
1654 timeout_flag =
false;
1655 ret = poll(&pfd, 1, LWIP_SHELL_CMD_PING_TIMEOUT);
1657 perror(
"Ping: poll\n");
1659 }
else if (ret == 0) {
1661 timeout_flag =
true;
1665 ret =
recv(sfd, pbuf_resp->payload, pbuf_resp->len, MSG_DONTWAIT);
1667 perror(
"Ping: recv echo reply failed\n");
1672 iphdr_resp = pbuf_resp->payload;
1674 ip_hlen = (IPH_HL(iphdr_resp) << 2);
1675 if (pbuf_header(pbuf_resp, -ip_hlen)) {
1677 PRINTK(
"Ping : memory management failure\n");
1680 iecho_resp = (
struct icmp_echo_hdr *)pbuf_resp->payload;
1682 if (pbuf_header(pbuf_resp, ip_hlen)) {
1684 PRINTK(
"ping : memory management failure\n");
1688 if ((iphdr_resp->src.addr != to.sin_addr.s_addr) ||
1689 ((ICMPH_TYPE(iecho_resp) == ICMP_ECHO) && (iphdr_resp->src.addr == to.sin_addr.s_addr))) {
1692 timout_ms = ((end.tv_sec - start.tv_sec) * 1000 + (end.tv_nsec - start.tv_nsec) / 1000000);
1693 timout_ms = LWIP_SHELL_CMD_PING_TIMEOUT - timout_ms;
1698 }
while (timout_ms >= 0);
1701 if ((timout_ms < 0) || (timeout_flag ==
true)) {
1704 PRINTK(
"\nPing: destination unreachable ...");
1709 rtt = ((end.tv_sec - start.tv_sec) * 1000 + (end.tv_nsec - start.tv_nsec) / 1000000);
1711 if (iphdr_resp->src.addr == to.sin_addr.s_addr) {
1712 switch (ICMPH_TYPE(iecho_resp)) {
1714 PRINTK(
"\n[%u]Reply from %s: ", i,
inet_ntop(AF_INET, &to.sin_addr, buf,
sizeof(buf)));
1716 PRINTK(
"time=%ims ", rtt);
1718 PRINTK(
"time<1ms ");
1720 PRINTK(
"TTL=%u", iphdr_resp->_ttl);
1725 if (intrvl < 1000) {
1733 }
while (intrvl > 0);
1737 PRINTK(
"\nPing: destination host unreachable ...");
1740 PRINTK(
"\nPing: source quench ...");
1743 PRINTK(
"\nPing: redirect ...");
1746 PRINTK(
"\nPing: time exceeded ...");
1749 PRINTK(
"\nPing: parameter problem ...");
1752 PRINTK(
"\nPing: unknown error ...");
1759 PRINTK(
"\n--- %s ping statistics ---\n",
inet_ntop(AF_INET, &to.sin_addr, buf,
sizeof(buf)));
1760 PRINTK(
"%u packets transmitted, %u received, %u loss\n", i, succ_cnt, failed_cnt);
1764 (
void)lwip_close(sfd);
1765 if (pbuf_resp != NULL) {
1766 (
void)pbuf_free(pbuf_resp);
1768 if (iecho != NULL) {
1774static void ping_cmd(
unsigned int p0,
unsigned int p1,
unsigned int p2,
unsigned int p3)
1778 u32_t interval = p2;
1779 u32_t data_len = p3;
1782 ret =
osPingFunc(destip, count, interval, data_len);
1784 PRINTK(
"Ping cmd failed due to some errors\n");
1796 u32_t interval = 1000;
1797 u32_t data_len = 48;
1798 ip4_addr_t dst_ipaddr;
1802 PRINTK(
"Ping: tcpip_init have not been called\n");
1806 if ((argc < 1) || (argv == NULL)) {
1807 PRINTK(
"Ping: require dest ipaddr at least\n");
1813 if (strcmp(
"-n", argv[i]) == 0 && (argc > 1)) {
1814 ret = atoi(argv[i + 1]);
1816 PRINTK(
"Ping count should be greater than 0 \n");
1823 }
else if (strcmp(
"-t", argv[i]) == 0) {
1828 }
else if (strcmp(
"-w", argv[i]) == 0 && (argc > 1)) {
1829 ret = atoi(argv[i + 1]);
1831 PRINTK(
"Ping interval should be greater than 0 \n");
1838 }
else if (strcmp(
"-l", argv[i]) == 0 && (argc > 1)) {
1839 ret = atoi(argv[i + 1]);
1840 if (ret < 0 || ret > (
int)(LWIP_MAX_UDP_RAW_SEND_SIZE -
sizeof(
struct icmp_echo_hdr))) {
1841 PRINTK(
"Ping data length error, should be in range of [0, %d] \n",
1842 LWIP_MAX_UDP_RAW_SEND_SIZE -
sizeof(
struct icmp_echo_hdr));
1848 }
else if (strcmp(
"-k", argv[i]) == 0) {
1853 PRINTK(
"No ping task running...\n");
1860 PRINTK(
"Invalid Ping param\n");
1867 count = LWIP_SHELL_CMD_PING_RETRY_TIMES;
1880 if (dst_ipaddr.addr == IPADDR_NONE || dst_ipaddr.addr == IPADDR_ANY) {
1881 PRINTK(
"Invalid dest ipaddr: NONE or ANY\n");
1886 if (count == 0 || count > LWIP_SHELL_CMD_PING_RETRY_TIMES) {
1888 PRINTK(
"Ping task already running and only support one now\n");
1892 stPingTask.
uwStackSize = LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE;
1893 stPingTask.
pcName =
"ping_task";
1895 stPingTask.
uwResved = LOS_TASK_STATUS_DETACHED;
1896 stPingTask.
auwArgs[0] = dst_ipaddr.addr;
1897 stPingTask.
auwArgs[1] = count;
1898 stPingTask.
auwArgs[2] = interval;
1899 stPingTask.
auwArgs[3] = data_len;
1901 if (ret != LOS_OK) {
1902 PRINTK(
"ping_task create failed 0x%08x.\n", ret);
1903 count = LWIP_SHELL_CMD_PING_RETRY_TIMES;
1913 if (
osPingFunc(dst_ipaddr.addr, count, interval, data_len) < 0) {
1914 PRINTK(
"Ping cmd failed due some errors\n");
1931 struct sockaddr_in to;
1932 struct icmp_echo_hdr iecho;
1933 struct pbuf *pbuf_resp = NULL;
1934 struct icmp_echo_hdr *iecho_resp = NULL;
1935 struct ip_hdr *iphdr_resp = NULL;
1937 ip_addr_t dst_ipaddr;
1939 struct timeval stTimeVal;
1940 struct timespec start, end;
1948 PRINTK(
"ping: tcpip_init have not been called\n");
1952 if ((argc < 1) || (argv == NULL)) {
1953 PRINTK(
"ping : invalid arguments, ping command receives ip as command line argument \n");
1958 pingcount = atoi(argv[1]);
1960 pingcount = LWIP_SHELL_CMD_PING_RETRY_TIMES;
1962 pingcount = LWIP_SHELL_CMD_PING_RETRY_TIMES;
1964 PRINTK(
"ping %u packets start.\n", pingcount);
1968 ip_2_ip4(&dst_ipaddr)->addr =
get_hostip(argv[0]);
1970 ip_2_ip4(&dst_ipaddr)->addr =
inet_addr(argv[0]);
1973 to.sin_family = AF_INET;
1974 to.sin_addr.s_addr = ip_2_ip4(&dst_ipaddr)->addr;
1977 if (to.sin_addr.s_addr == IPADDR_NONE || to.sin_addr.s_addr == IPADDR_ANY) {
1978 PRINTK(
"ping : invalid ip address : NONE or ANY\n");
1982 sfd =
lwip_socket(PF_INET, SOCK_RAW, IPPROTO_ICMP);
1984 PRINTK(
"ping : failed, socket creation failed\n");
1988 pbuf_resp = pbuf_alloc(PBUF_RAW, IP_HLEN +
sizeof(
struct icmp_echo_hdr), PBUF_RAM);
1989 if (pbuf_resp == NULL) {
1990 PRINTK(
"ping : memory allocation failed\n");
1994 for (i = 0; i < pingcount; i++) {
1995 (
void)memset_s(&iecho,
sizeof(iecho), 0,
sizeof(iecho));
1996 ICMPH_TYPE_SET(&iecho, (u8_t)ICMP_ECHO);
1997 iecho.chksum = inet_chksum(&iecho,
sizeof(
struct icmp_echo_hdr));
1999 ret =
lwip_sendto(sfd, &iecho,
sizeof(
struct icmp_echo_hdr), 0, (
struct sockaddr *)&to, (socklen_t)
sizeof(to));
2001 PRINTK(
"ping : sending ICMP echo msg failed\n");
2008 FD_ZERO(&fdReadSet);
2009 FD_SET(sfd, &fdReadSet);
2010 stTimeVal.tv_sec = LWIP_SHELL_CMD_PING_TIMEOUT / 1000;
2011 stTimeVal.tv_usec = 0;
2014 ret = select(sfd + 1, &fdReadSet, 0, 0, &stTimeVal);
2016 PRINTK(
"ping : select failure\n");
2018 }
else if (ret == 0) {
2019 PRINTK(
"Request timed out.\n");
2025 rtt = ((end.tv_sec - start.tv_sec) * 1000 + (end.tv_nsec - start.tv_nsec) / 1000000);
2027 ret = lwip_recv(sfd, pbuf_resp->payload, pbuf_resp->len, 0);
2029 PRINTK(
"ping : receiving ICMP echo response msg failed\n");
2034 iphdr_resp = (
struct ip_hdr *)(pbuf_resp->payload);
2035 ip_hlen = (s16_t)(IPH_HL(iphdr_resp) * 4);
2036 if (pbuf_header(pbuf_resp, (s16_t)(-ip_hlen))) {
2038 PRINTK(
"ping : memory management failure\n");
2041 iecho_resp = (
struct icmp_echo_hdr *)pbuf_resp->payload;
2044 if (pbuf_header(pbuf_resp, ip_hlen)) {
2046 PRINTK(
"ping : memory management failure\n");
2050 if (iphdr_resp->src.addr == to.sin_addr.s_addr) {
2051 if (ICMPH_TYPE(iecho_resp) == ICMP_ER) {
2052 PRINTK(
"[%u]Reply from %s: time=%ims TTL=%u\n", i,
2053 inet_ntoa_r(to.sin_addr.s_addr, buf,
sizeof(buf)), rtt, iphdr_resp->_ttl);
2054 }
else if (ICMPH_TYPE(iecho_resp) == ICMP_ECHO) {
2062 (
void)lwip_close(sfd);
2063 (
void)pbuf_free(pbuf_resp);
2067 (
void)lwip_close(sfd);
2068 if (pbuf_resp != NULL) {
2069 (
void)pbuf_free(pbuf_resp);
2088 u32_t last_received;
2089 struct timespec start, end, start_in_reply;
2090 struct timespec first, last;
2097 struct sockaddr_in6 to;
2098 struct icmp6_echo_hdr *iecho_resp = NULL;
2099 struct icmp6_echo_hdr *iecho = NULL;
2100 struct timeval stTimeVal;
2101 struct timeval deltaTimeVal;
2102 struct pbuf *pbuf_resp = NULL;
2103 struct pbuf *pbuf_req = NULL;
2106 u8_t select_on_socket = 0;
2107 char buf[INET6_ADDRSTRLEN];
2110 PRINTK(
"%s: tcpip_init have not been called\n", __FUNCTION__);
2115 if ((argc < 1) || (argc > LWIP_MAX_PING6_ARG_COUNT) || (argv == NULL)) {
2124 if (ping6_params.
args_found & LWIP_PING6_SOURCE_ADDRESS_ARG) {
2125 type = LWIP_PING6_SOURCE_ADDRESS_ARG;
2126 param = (
void *)(&ping6_params.
src_addr);
2127 }
else if (ping6_params.
args_found & LWIP_PING6_INTERFACE_ARG) {
2128 type = LWIP_PING6_INTERFACE_ARG;
2131 type = LWIP_PING6_DEFAULT_SOCKET;
2142 pbuf_req = pbuf_alloc(PBUF_RAW, LWIP_PING6_STANDARD_PKT_SIZE, PBUF_RAM);
2143 pbuf_resp = pbuf_alloc(PBUF_RAW, LWIP_PING6_STANDARD_PKT_SIZE, PBUF_RAM);
2144 if ((pbuf_resp == NULL) || (pbuf_req == NULL)) {
2145 PRINTK(
"ping6 : Memory Allocation Failed\n");
2150 to.sin6_family = AF_INET6;
2151 inet6_addr_from_ip6addr(&to.sin6_addr, &(ping6_params.
dst_addr));
2152 to.sin6_port = htons(IPPROTO_ICMPV6);
2155 if (lwip_strnicmp(
inet_ntop(AF_INET6, &to.sin6_addr, buf,
sizeof(buf)), argv[ping6_params.
host_index],
2156 sizeof(to.sin6_addr))) {
2158 PRINTK(
"PING %s (%s) with %d bytes of data.\n",
2159 argv[ping6_params.
host_index], buf, LWIP_PING6_STANDARD_PKT_SIZE);
2161 PRINTK(
"PING %s with %d bytes of data.\n", buf, LWIP_PING6_STANDARD_PKT_SIZE);
2164 PRINTK(
"PING %s with %d bytes of data\n",
inet_ntop(AF_INET6, &to.sin6_addr, buf,
sizeof(buf)), LWIP_PING6_STANDARD_PKT_SIZE);
2172 last_received = LWIP_PING6_STARTING_SEQ_NUM + LWIP_PING6_OUT_OF_ORDER_MAGNITUDE + 1;
2173 icmpv6_id = (u16_t)LWIP_RAND();
2174 icmpv6_seq = LWIP_PING6_STARTING_SEQ_NUM;
2180 for (nsent = 0; nsent < ping6_params.
pingcount; nsent++) {
2184 if (memset_s(pbuf_req->payload, pbuf_req->len, (
int)(start.tv_nsec), pbuf_req->len) != 0) {
2188 iecho = (
struct icmp6_echo_hdr *)pbuf_req->payload;
2189 iecho->type = ICMP6_TYPE_EREQ;
2190 iecho->id = icmpv6_id;
2192 iecho->seqno = icmpv6_seq;
2196 (
void)pbuf_header(pbuf_req, (s16_t)(-(s16_t)(
sizeof(
struct icmp6_echo_hdr))));
2197 if (memcpy_s(pbuf_req->payload, pbuf_req->len, (
void *)&start,
sizeof(start)) != 0) {
2200 (
void)pbuf_header(pbuf_req, (s16_t)((s16_t)(
sizeof(
struct icmp6_echo_hdr))));
2202 ret =
lwip_sendto(sfd, iecho, pbuf_req->len, 0, (
struct sockaddr *)&to, (socklen_t)
sizeof(to));
2204 PRINTK(
"ping6 : Sending ICMP Echo message failed\n");
2209 FD_ZERO(&fdReadSet);
2210 FD_SET(sfd, &fdReadSet);
2211 stTimeVal.tv_sec = LWIP_MSECS_TO_SECS(LWIP_SHELL_CMD_PING_TIMEOUT);
2212 stTimeVal.tv_usec = 0;
2213 select_on_socket = 1;
2215 while (select_on_socket) {
2216 select_on_socket = 0;
2217 ret = select(sfd + 1, &fdReadSet, 0, 0, &stTimeVal);
2219 PRINTK(
"ping6 : select failure\n");
2221 }
else if (ret == 0) {
2223 PRINTK(
"Request timed out\n");
2230 ret = lwip_recv(sfd, pbuf_resp->payload, pbuf_resp->len, 0);
2232 PRINTK(
"ping6 : receiving ICMP echo response msg failed\n");
2236 if ((u32_t)ret <
sizeof(
struct icmp6_echo_hdr *)) {
2238 PRINTK(
"ping6 : received ICMP echo response too short\n");
2239 goto REDUCE_SELECT_TIME;
2244 iecho_resp = (
struct icmp6_echo_hdr *)pbuf_resp->payload;
2246 if (iecho_resp->id == icmpv6_id) {
2247 if (iecho_resp->type == ICMP6_TYPE_EREP) {
2248 if (ret < LWIP_PING6_STANDARD_PKT_SIZE) {
2250 PRINTK(
"ping6 : received ICMP echo response too short\n");
2251 goto REDUCE_SELECT_TIME;
2254 if (nsent && iecho_resp->seqno != icmpv6_seq &&
2255 (iecho_resp->seqno<(u16_t)(last_received - LWIP_PING6_OUT_OF_ORDER_MAGNITUDE) ||
2256 iecho_resp->seqno>(u16_t)(
2257 last_received + LWIP_PING6_OUT_OF_ORDER_MAGNITUDE))) {
2259 goto REDUCE_SELECT_TIME;
2262 last_received = iecho_resp->seqno;
2264 (
void)pbuf_header(pbuf_resp, (s16_t)(-(s16_t)(
sizeof(
struct icmp6_echo_hdr))));
2265 if (memcpy_s((
void *)&start_in_reply,
sizeof(start_in_reply),
2266 pbuf_resp->payload,
sizeof(start_in_reply)) != EOK) {
2267 goto REDUCE_SELECT_TIME;
2269 (
void)pbuf_header(pbuf_resp, (s16_t)((s16_t)(
sizeof(
struct icmp6_echo_hdr))));
2271 rtt = ((end.tv_sec - start.tv_sec) * 1000 + (end.tv_nsec - start.tv_nsec) / 1000000);
2273 PRINTK(
"%d bytes from %s : icmp_seq=%d time", ret,
2274 inet_ntop(AF_INET6, &to.sin6_addr, buf,
sizeof(buf)),
2275 ((iecho_resp->seqno) - LWIP_PING6_STARTING_SEQ_NUM));
2279 PRINTK(
"=%i ms\n", rtt);
2285 if ((iecho_resp->seqno != icmpv6_seq) && (nsent < ping6_params.
pingcount)) {
2288 goto REDUCE_SELECT_TIME;
2297 deltaTimeVal.tv_sec = (
long)(end.tv_sec - start.tv_sec);
2298 deltaTimeVal.tv_usec = (
long)((end.tv_nsec - start.tv_nsec) / 1000);
2301 timersub(&stTimeVal, &deltaTimeVal, &stTimeVal);
2302 select_on_socket = 1;
2311 PRINTK(
"--- %s ping statistics ---\n", argv[ping6_params.
host_index]);
2312 PRINTK(
"%d packets transmitted, %d received, %.2f%% packet loss, time %dms\n",
2313 nsent, nrecieve, (
float)(((
float)(nsent - nrecieve)) * ((
float)(100)) / ((
float)(nsent))),
2314 ((last.tv_sec - first.tv_sec) * 1000 + (last.tv_nsec - first.tv_nsec) / 1000000));
2322 (
void)lwip_close(sfd);
2325 if (pbuf_resp != NULL) {
2326 (
void)pbuf_free(pbuf_resp);
2329 if (pbuf_req != NULL) {
2330 (
void)pbuf_free(pbuf_req);
2332 return (u32_t)((ret == (
int)ERR_OK) ? LOS_OK : LOS_NOK);
2336 PRINTK(
"\tping6 [-c count] [-I interface/sourceAddress] destination\n");
2344 struct sockaddr_in6 stHostAddr6;
2345 struct icmp6_filter icmp6_sock_filter;
2347 sfd =
lwip_socket(PF_INET6, SOCK_RAW, IPPROTO_ICMPV6);
2349 PRINTK(
"ping6 : Failed, socket creation failed\n");
2353 if (param != NULL) {
2354 if (type == LWIP_PING6_SOURCE_ADDRESS_ARG) {
2356 (
void)memset_s(&stHostAddr6,
sizeof(stHostAddr6), 0,
sizeof(stHostAddr6));
2357 stHostAddr6.sin6_family = AF_INET6;
2358 inet6_addr_from_ip6addr(&stHostAddr6.sin6_addr, (ip6_addr_t *)param);
2359 stHostAddr6.sin6_port = htons(IPPROTO_ICMPV6);
2360 stHostAddr6.sin6_scope_id = 0;
2362 ret =
lwip_bind(sfd, (
struct sockaddr *)&stHostAddr6,
sizeof(stHostAddr6));
2364 (
void)lwip_close(sfd);
2365 PRINTK(
"ping6 : bind icmp socket: cannot assign requested address\n");
2368 }
else if (type == LWIP_PING6_INTERFACE_ARG) {
2370 ret =
lwip_setsockopt(sfd, SOL_SOCKET, SO_BINDTODEVICE, (
char *)(param), strlen((
char *)(param)));
2372 (
void)lwip_close(sfd);
2373 PRINTK(
"ping6: unknownn iface %s\n", (
char *)(param));
2380 ICMP6_FILTER_SETBLOCKALL (&icmp6_sock_filter);
2381 ICMP6_FILTER_SETPASS (ICMP6_TYPE_EREP, &icmp6_sock_filter);
2382 ICMP6_FILTER_SETPASS (ICMP6_TYPE_DUR, &icmp6_sock_filter);
2383 ICMP6_FILTER_SETPASS (ICMP6_TYPE_PTB, &icmp6_sock_filter);
2384 ICMP6_FILTER_SETPASS (ICMP6_TYPE_TE, &icmp6_sock_filter);
2386 ret =
lwip_setsockopt(sfd, IPPROTO_ICMPV6, ICMP6_FILTER, &icmp6_sock_filter,
sizeof(
struct icmp6_filter));
2388 (
void)lwip_close(sfd);
2389 PRINTK(
"ping6 : setsockopt: Invalid Argument\n");
2407 struct addrinfo *res = NULL;
2408 struct addrinfo hints_structure;
2412 IP6_ADDR(&(ping6_params->
dst_addr), 0, 0, 0, 0);
2413 IP6_ADDR(&(ping6_params->
src_addr), 0, 0, 0, 0);
2415 ping6_params->
pingcount = LWIP_SHELL_CMD_PING_RETRY_TIMES;
2420 if (strcmp(
"-c", argv[i]) == 0) {
2422 if (ping6_params->
args_found & LWIP_PING6_COUNT_ARG) {
2423 PRINTK(
"ping6: -c option present multiple times \n");
2429 PRINTK(
"ping6: ping count(-c) should require an argument \n");
2434 pingcount = atoi(argv[i + 1]);
2435 if (pingcount <= 0) {
2436 PRINTK(
"ping6: bad number of packets to transmit \n");
2441 ping6_params->
args_found |= LWIP_PING6_COUNT_ARG;
2442 ping6_params->
pingcount = (u32_t)pingcount;
2444 }
else if (strcmp(
"-I", argv[i]) == 0) {
2447 if ((ping6_params->
args_found & LWIP_PING6_SOURCE_ADDRESS_ARG) ||
2448 (ping6_params->
args_found & LWIP_PING6_INTERFACE_ARG)) {
2449 PRINTK(
"ping6: -I option present multiple times \n");
2455 PRINTK(
"ping6: interface/source address(-I) should require an argument \n");
2462 ping6_params->
args_found |= LWIP_PING6_SOURCE_ADDRESS_ARG;
2470 ping6_params->
args_found |= LWIP_PING6_INTERFACE_ARG;
2474 if (argv[i][0] ==
'-') {
2476 PRINTK(
"ping6: bad option %s\n", argv[i]);
2479 }
else if (ping6_params->
args_found & LWIP_PING6_HOSTNAME_ARG) {
2481 PRINTK(
"ping6: bad parameter %s\n", argv[i]);
2488 hints_structure.ai_family = AF_INET6;
2489 hints_structure.ai_flags = 0;
2490 ret = lwip_getaddrinfo(argv[i], NULL, &hints_structure, &res);
2491 if (ret != ERR_OK) {
2492 PRINTK(
"ping6 : Host : %s can't be resolved to IPv6 address\n", argv[i]);
2497 inet6_addr_to_ip6addr(&(ping6_params->
dst_addr),
2498 &(((
const struct sockaddr_in6 *)(res->ai_addr))->sin6_addr));
2502 PRINTK(
"ping6 : Invalid IPv6 Address : %s\n", argv[i]);
2507 if (ip6_addr_isany(&(ping6_params->
dst_addr)) || ip6_addr_isnone(&(ping6_params->
dst_addr))) {
2509 PRINTK(
"ping6 : IPv6 address of host : %s (%s) is invalid\n", argv[i],
2510 ip6addr_ntoa((
const ip6_addr_t *)&(ping6_params->
dst_addr)));
2512 PRINTK(
"ping6 : Invalid IPv6 address : %s\n", argv[i]);
2517 ping6_params->
args_found |= LWIP_PING6_HOSTNAME_ARG;
2523 if (!(ping6_params->
args_found & LWIP_PING6_HOSTNAME_ARG)) {
2525 PRINTK(
"ping6 : Hostname/IPv6 address to ping is not specified\n");
2530 if (ip6_addr_islinklocal(&(ping6_params->
dst_addr)) &&
2531 !(ping6_params->
args_found & (LWIP_PING6_INTERFACE_ARG | LWIP_PING6_SOURCE_ADDRESS_ARG))) {
2533 PRINTK(
"ping6 : Interface specification is mandatory for link-local addresses\n");
2542 lwip_freeaddrinfo(res);
2570 case ICMP6_TYPE_DUR:
2571 return "Destination Unreachable";
2572 case ICMP6_TYPE_PTB:
2573 return "Packet too big";
2575 return "Time Exceeded";
2577 return "Parameter Problem";
2581 return "Unknown Error";
2584#ifdef LOSCFG_SHELL_CMD_DEBUG
2594 struct timeval get_time;
2597 (
void)memset_s(&get_time,
sizeof(
struct timeval), 0,
sizeof(
struct timeval));
2600 PRINTK(
"%s: tcpip_init have not been called\n", __FUNCTION__);
2604 if (argc < 1 || argv == NULL) {
2609 if (server_num >= 0 && server_num < argc) {
2610 ret = ctime_r((time_t *)&get_time.tv_sec, buf);
2612 PRINTK(
"time server %s: %s\n", argv[server_num], ret);
2614 PRINTK(
"ctime return null error\n");
2617 PRINTK(
"no server suitable for synchronization found\n");
2623 PRINTK(
"\nUsage:\n");
2624 PRINTK(
"ntpdate [SERVER_IP1] [SERVER_IP2] ...\n");
2628#ifdef LOSCFG_SHELL_CMD_DEBUG
2637 ip_addr_t dns = {0};
2640 if (argc < 1 || argv == NULL) {
2645 PRINTK(
"%s: tcpip_init have not been called\n", __FUNCTION__);
2649 if (argc == 1 && (strcmp(argv[0],
"-a") == 0)) {
2650 for (i = 0; i < DNS_MAX_SERVERS; i++) {
2652 if (err == ERR_OK) {
2653 PRINTK(
"dns %d: %s\n", i + 1, ipaddr_ntoa_unsafe(&dns));
2655 PRINTK(
"dns: failed\n");
2660 }
else if (argc == 2) {
2662 if ((i <= 0) || (i > DNS_MAX_SERVERS))
2666#if LWIP_IPV4 && LWIP_IPV6
2667 dns.type = IPADDR_TYPE_V6;
2669 if (!ip6_addr_isglobal((ip6_addr_t *)&dns)) {
2670 PRINTK(
"ip address<%s> is wrong\n", argv[1]);
2677 ((ip4_addr_t *)&dns)->addr = ipaddr_addr(argv[1]);
2678 if (((ip4_addr_t *)&dns)->addr == IPADDR_NONE) {
2679 PRINTK(
"ip address<%s> is wrong\n", argv[1]);
2682#if LWIP_IPV4 && LWIP_IPV6
2683 dns.type = IPADDR_TYPE_V4;
2689 if (err != ERR_OK) {
2690 PRINTK(
"dns : failed\n");
2697 PRINTK(
"\tdns <1-%d> <IP>\n", DNS_MAX_SERVERS);
2698 PRINTK(
"\tdns -a\n");
2702#ifdef LOSCFG_SHELL_CMD_DEBUG
2707extern struct nd6_neighbor_cache_entry
neighbor_cache[LWIP_ND6_NUM_NEIGHBORS];
2713 u16_t offset = 0, len;
2714 struct ip6_hdr *iphdr = NULL;
2715 struct udp_hdr *udphdr = NULL;
2716 struct ip6_dest_hdr *dest_hdr = NULL;
2717 struct ip6_frag_hdr *frag_hdr = NULL;
2721 LWIP_ERROR(
"netstat_get_udp6_sendQLen: NULL pcb received\n", (udppcb != NULL),
return -1);
2722 LWIP_ERROR(
"netstat_get_udp6_sendQLen: NULL pbuf received\n", (udpbuf != NULL),
return -1);
2724 iphdr = (
struct ip6_hdr *)udpbuf->payload;
2726 if (!(ip6_addr_cmp(&iphdr->dest, ip_2_ip6(&udppcb->remote_ip)) &&
2727 (ip_addr_isany(&udppcb->local_ip) ||
2728 ip6_addr_cmp(&iphdr->src, ip_2_ip6(&udppcb->local_ip))))) {
2733 if (pbuf_header(udpbuf, (s16_t)(-(s16_t)(len)))) {
2739 nexth = IP6H_NEXTH(iphdr);
2740 while (offset < udpbuf->tot_len) {
2741 if (nexth == IP6_NEXTH_NONE || nexth == IP6_NEXTH_UDP || nexth == IP6_NEXTH_UDPLITE) {
2745 case IP6_NEXTH_HOPBYHOP:
2746 case IP6_NEXTH_ROUTING:
2747 nexth = *((u8_t *)udpbuf->payload);
2748 hlen = (u16_t)(8 * (1 + *((u8_t *)udpbuf->payload + 1)));
2750 case IP6_NEXTH_DESTOPTS:
2751 nexth = *((u8_t *)udpbuf->payload);
2752 dest_hdr = (
struct ip6_dest_hdr *)udpbuf->payload;
2753 hlen = (u16_t)(8 * (1 + dest_hdr->_hlen));
2755 case IP6_NEXTH_FRAGMENT:
2756 frag_hdr = (
struct ip6_frag_hdr *)udpbuf->payload;
2757 nexth = frag_hdr->_nexth;
2758 hlen = IP6_FRAG_HLEN;
2765 (
void)pbuf_header(udpbuf, (s16_t)(-(s16_t)hlen));
2766 offset = (u16_t)(offset + hlen);
2770 if (offset >= udpbuf->tot_len) {
2771 offset = (u16_t)(offset - hlen);
2775 LWIP_ERROR(
"Transport option should be UDP", (nexth == IP6_NEXTH_UDP || nexth == IP6_NEXTH_UDPLITE),
goto FUNC_OUT);
2777 if (offset > iphdr->_plen) {
2782 if (udpbuf->tot_len < UDP_HLEN) {
2786 udphdr = (
struct udp_hdr *)udpbuf->payload;
2787 if ((ntohs(udphdr->dest) == udppcb->remote_port) && (ntohs(udphdr->src) == udppcb->local_port)) {
2788 if (ntohs(udphdr->len) > UDP_HLEN) {
2789 sendLen = ntohs(udphdr->len) - UDP_HLEN;
2791 sendLen = udpbuf->tot_len - UDP_HLEN;
2796 (
void)pbuf_header(udpbuf, (s16_t)offset);
2805 u16_t offset = 0, len;
2806 struct ip_hdr *iphdr = NULL;
2807 struct udp_hdr *udphdr = NULL;
2809 LWIP_ERROR(
"netstat_get_udp_sendQLen: NULL pcb received\n", (udppcb != NULL),
return -1);
2810 LWIP_ERROR(
"netstat_get_udp_sendQLen: NULL pbuf received\n", (udpbuf != NULL),
return -1);
2812 iphdr = (
struct ip_hdr *)udpbuf->payload;
2814 if (!(ip4_addr_cmp(&iphdr->dest, ip_2_ip4(&udppcb->remote_ip)) &&
2815 (ip_addr_isany(&udppcb->local_ip) ||
2816 ip4_addr_cmp(&iphdr->src, ip_2_ip4(&udppcb->local_ip))))) {
2820 if ((IPH_PROTO(iphdr) != IP_PROTO_UDP) && (IPH_PROTO(iphdr) != IP_PROTO_UDPLITE)) {
2822 if (IPH_PROTO(iphdr) != IP_PROTO_UDP) {
2827 if ((ntohs(IPH_OFFSET(iphdr)) & IP_OFFMASK) != 0) {
2831 len = (u16_t)(IPH_HL(iphdr) * 4);
2832 if (pbuf_header(udpbuf, (s16_t)(-len))) {
2836 offset = (u16_t)(offset + len);
2838 udphdr = (
struct udp_hdr *)udpbuf->payload;
2839 if ((ntohs(udphdr->dest) == udppcb->remote_port) && (ntohs(udphdr->src) == udppcb->local_port)) {
2840 sendLen = ntohs(udphdr->len) - UDP_HLEN;
2844 (
void)pbuf_header(udpbuf, (s16_t)offset);
2851 unsigned int retVal = 0;
2853 struct netconn *conn = NULL;
2856 LWIP_ERROR(
"netstat_tcp_recvq: Received NULL pcb\n", (tpcb != NULL),
return 0);
2859 conn = (
struct netconn *)tpcb->callback_arg;
2861 switch (conn->type) {
2865 case NETCONN_RAW_IPV6:
2866 case NETCONN_UDP_IPV6:
2869 SYS_ARCH_GET(((
unsigned int)conn->recv_avail ), retVal);
2883 struct tcp_seg *useg = NULL;
2885 LWIP_ERROR(
"netstat_tcp_sendq: Received NULL pcb\n", (tpcb != NULL),
return 0);
2887 for (useg = tpcb->unacked; useg != NULL; useg = useg->next) {
2888 retVal = retVal + useg->len;
2901#if LWIP_ND6_QUEUEING
2902 struct nd6_q_entry *neibq = NULL;
2905 LWIP_ERROR(
"netstat_udp_sendq6: Received NULL pcb\n", (upcb != NULL),
return 0);
2907 for (i = 0; i < LWIP_ND6_NUM_NEIGHBORS; i++) {
2909 if (ip6_addr_cmp(&upcb->remote_ip.u_addr.ip6, &
neighbor_cache[i].next_hop_address)) {
2915#if LWIP_ND6_QUEUEING
2916 for (neibq =
neighbor_cache[idx].q; neibq != NULL; neibq = neibq->next) {
2940 struct etharp_q_entry *arpq = NULL;
2943 LWIP_ERROR(
"netstat_udp_sendq: Received NULL pcb\n", (upcb != NULL),
return 0);
2945 for (i = 0; i < ARP_TABLE_SIZE; ++i) {
2946 if (arp_table[i].state != ETHARP_STATE_EMPTY) {
2947 if (ip4_addr_cmp(ip_2_ip4(&upcb->remote_ip), &arp_table[i].ipaddr)) {
2956 for (arpq = arp_table[arpidx].q; arpq != NULL; arpq = arpq->next) {
2981 unsigned int retVal = 0;
2988 switch (NETCONNTYPE_GROUP((
unsigned int)(conn->type))) {
2992 case NETCONN_PKT_RAW:
2995 SYS_ARCH_GET(((
unsigned int)conn->recv_avail ), retVal);
3012 switch (NETCONNTYPE_GROUP((
unsigned int)(conn->type))) {
3020 case NETCONN_PKT_RAW:
3035 s8_t local_ip_port[64] = {0};
3036 s8_t remote_ip_port[64] = {0};
3037 struct tcp_pcb *tpcb = NULL;
3038 struct tcp_pcb_listen *lpcb = NULL;
3039 struct udp_pcb *upcb = NULL;
3040 struct raw_pcb *rpcb = NULL;
3041 s8_t *entry_buf = NULL;
3042 u32_t entry_buf_len;
3043 u32_t entry_buf_offset;
3050 u8_t netif_name[IFNAMSIZ];
3051 struct netif *netif = NULL;
3054 if (ndata == NULL) {
3059 entry_buf_offset = 0;
3061 if (entry_buf == NULL) {
3064 iRet = snprintf_s((
char *)(entry_buf + entry_buf_offset), entry_buf_len, entry_buf_len - 1,
3065 "========== total sockets %d ====== unused sockets %d ==========\n",
3067 if ((iRet <= 0) || ((u32_t)(iRet) >= entry_buf_len)) {
3070 entry_buf_len -= (u32_t)(iRet);
3071 entry_buf_offset += (u32_t)(iRet);
3074 if (tcp_active_pcbs != NULL || tcp_bound_pcbs != NULL || tcp_tw_pcbs != NULL || tcp_listen_pcbs.pcbs != NULL) {
3075 iRet = snprintf_s((
char *)(entry_buf + entry_buf_offset), entry_buf_len, entry_buf_len - 1,
3076 "%-8s%-12s%-12s%-24s%-24s%-16s\n",
3077 "Proto",
"Recv-Q",
"Send-Q",
"Local Address",
"Foreign Address",
"State");
3078 if ((iRet <= 0) || ((u32_t)(iRet) >= entry_buf_len)) {
3081 entry_buf_len -= (u32_t)(iRet);
3082 entry_buf_offset += (u32_t)(iRet);
3084 for (tpcb = tcp_active_pcbs; tpcb != NULL; tpcb = tpcb->next) {
3085 iRet = snprintf_s((
char *)local_ip_port,
sizeof(local_ip_port), (
sizeof(local_ip_port) - 1),
3086 "%s:%d", ipaddr_ntoa(&tpcb->local_ip), tpcb->local_port);
3087 if ((iRet <= 0) || ((u32_t)(iRet) >=
sizeof(local_ip_port))) {
3091 iRet = snprintf_s((
char *)remote_ip_port,
sizeof(remote_ip_port), (
sizeof(remote_ip_port) - 1),
3092 "%s:%d", ipaddr_ntoa(&tpcb->remote_ip), tpcb->remote_port);
3093 if ((iRet <= 0) || ((u32_t)(iRet) >=
sizeof(remote_ip_port))) {
3096 if (tpcb->state == SYN_RCVD) {
3103 iRet = snprintf_s((
char *)(entry_buf + entry_buf_offset), entry_buf_len, entry_buf_len - 1,
3104 IP_IS_V6(&tpcb->local_ip) ?
"%-8s%-12d%-12d%-39s%-39s%-16s\n" :
3105 "%-8s%-12d%-12d%-24s%-24s%-16s\n",
3106 IP_IS_V6(&tpcb->local_ip) ?
"tcp-ip6" :
"tcp",
3107 recvQlen, sendQlen, local_ip_port, remote_ip_port,
tcp_state_str[tpcb->state]);
3108 if ((iRet <= 0) || ((u32_t)(iRet) >= entry_buf_len)) {
3111 entry_buf_len -= (u32_t)(iRet);
3112 entry_buf_offset += (u32_t)(iRet);
3119 for (tpcb = tcp_bound_pcbs; tpcb != NULL; tpcb = tpcb->next) {
3120 iRet = snprintf_s((
char *)local_ip_port,
sizeof(local_ip_port), (
sizeof(local_ip_port) - 1),
3121 "%s:%d", ipaddr_ntoa(&tpcb->local_ip), tpcb->local_port);
3122 if ((iRet <= 0) || ((u32_t)(iRet) >=
sizeof(local_ip_port))) {
3126 iRet = snprintf_s((
char *)remote_ip_port,
sizeof(remote_ip_port), (
sizeof(remote_ip_port) - 1),
3127 "%s:%d", ipaddr_ntoa(&tpcb->remote_ip), tpcb->remote_port);
3128 if ((iRet <= 0) || ((u32_t)(iRet) >=
sizeof(remote_ip_port))) {
3132 iRet = snprintf_s((
char *)(entry_buf + entry_buf_offset), entry_buf_len, entry_buf_len - 1,
3133 IP_IS_V6(&tpcb->local_ip) ?
"%-8s%-12d%-12d%-39s%-39s%-16s\n" :
3134 "%-8s%-12d%-12d%-24s%-24s%-16s\n",
3135 IP_IS_V6(&tpcb->local_ip) ?
"tcp-ip6" :
"tcp",
3136 recvQlen, sendQlen, local_ip_port, remote_ip_port,
tcp_state_str[tpcb->state]);
3137 if ((iRet <= 0) || ((u32_t)(iRet) >= entry_buf_len)) {
3140 entry_buf_len -= (u32_t)(iRet);
3141 entry_buf_offset += (u32_t)(iRet);
3144 for (tpcb = tcp_tw_pcbs; tpcb != NULL; tpcb = tpcb->next) {
3145 iRet = snprintf_s((
char *)local_ip_port,
sizeof(local_ip_port), (
sizeof(local_ip_port) - 1),
3146 "%s:%d", ipaddr_ntoa(&tpcb->local_ip), tpcb->local_port);
3147 if ((iRet <= 0) || ((u32_t)(iRet) >=
sizeof(local_ip_port))) {
3151 iRet = snprintf_s((
char *)remote_ip_port,
sizeof(remote_ip_port), (
sizeof(remote_ip_port) - 1),
3152 "%s:%d", ipaddr_ntoa(&tpcb->remote_ip), tpcb->remote_port);
3153 if ((iRet <= 0) || ((u32_t)(iRet) >=
sizeof(remote_ip_port))) {
3159 iRet = snprintf_s((
char *)(entry_buf + entry_buf_offset), entry_buf_len, entry_buf_len - 1,
3160 IP_IS_V6(&tpcb->local_ip) ?
"%-8s%-12d%-12d%-39s%-39s%-16s\n" :
3161 "%-8s%-12d%-12d%-24s%-24s%-16s\n",
3162 IP_IS_V6(&tpcb->local_ip) ?
"tcp-ip6" :
"tcp",
3163 recvQlen, sendQlen, local_ip_port, remote_ip_port,
tcp_state_str[tpcb->state]);
3164 if ((iRet <= 0) || ((u32_t)(iRet) >= entry_buf_len)) {
3167 entry_buf_len -= (u32_t)(iRet);
3168 entry_buf_offset += (u32_t)(iRet);
3175 for (lpcb = tcp_listen_pcbs.listen_pcbs; lpcb != NULL; lpcb = lpcb->next) {
3176 iRet = snprintf_s((
char *)local_ip_port,
sizeof(local_ip_port), (
sizeof(local_ip_port) - 1),
3177 "%s:%d", ipaddr_ntoa(&lpcb->local_ip), lpcb->local_port);
3178 if ((iRet <= 0) || ((u32_t)(iRet) >=
sizeof(local_ip_port))) {
3182 iRet = snprintf_s((
char *)remote_ip_port,
sizeof(remote_ip_port), (
sizeof(remote_ip_port) - 1),
3183 "%s:%d", ipaddr_ntoa(&lpcb->remote_ip), 0);
3184 if ((iRet <= 0) || ((u32_t)(iRet) >=
sizeof(remote_ip_port))) {
3190 iRet = snprintf_s((
char *)(entry_buf + entry_buf_offset), entry_buf_len, entry_buf_len - 1,
3191 IP_IS_V6(&lpcb->local_ip) ?
"%-8s%-12d%-12d%-39s%-39s%-16s\n" :
3192 "%-8s%-12d%-12d%-24s%-24s%-16s\n",
3193 IP_IS_V6(&lpcb->local_ip) ?
"tcp-ip6" :
"tcp",
3194 recvQlen, sendQlen, local_ip_port, remote_ip_port,
tcp_state_str[lpcb->state]);
3195 if ((iRet <= 0) || ((u32_t)(iRet) >= entry_buf_len)) {
3198 entry_buf_len -= (u32_t)(iRet);
3199 entry_buf_offset += (u32_t)(iRet);
3204 if (udp_pcbs != NULL) {
3205 iRet = snprintf_s((
char *)(entry_buf + entry_buf_offset), entry_buf_len, entry_buf_len - 1,
3206 "\n%-8s%-12s%-12s%-24s%-24s\n",
3207 "Proto",
"Recv-Q",
"Send-Q",
"Local Address",
"Foreign Address");
3208 if ((iRet <= 0) || ((u32_t)(iRet) >= entry_buf_len)) {
3211 entry_buf_len -= (u32_t)(iRet);
3212 entry_buf_offset += (u32_t)(iRet);
3214 for (upcb = udp_pcbs; upcb != NULL; upcb = upcb->next) {
3215 iRet = snprintf_s((
char *)local_ip_port,
sizeof(local_ip_port), (
sizeof(local_ip_port) - 1),
3216 "%s:%d", ipaddr_ntoa(&upcb->local_ip), upcb->local_port);
3217 if ((iRet <= 0) || ((u32_t)(iRet) >=
sizeof(local_ip_port))) {
3221 iRet = snprintf_s((
char *)remote_ip_port,
sizeof(remote_ip_port), (
sizeof(remote_ip_port) - 1),
3222 "%s:%d", ipaddr_ntoa(&upcb->remote_ip), upcb->remote_port);
3223 if ((iRet <= 0) || ((u32_t)(iRet) >=
sizeof(remote_ip_port))) {
3233 iRet = snprintf_s((
char *)(entry_buf + entry_buf_offset), entry_buf_len, entry_buf_len - 1,
3234 IP_IS_V6(&upcb->local_ip) ?
"%-8s%-12d%-12d%-39s%-39s%-16s\n" :
3235 "%-8s%-12d%-12d%-24s%-24s%-16s\n",
3236 IP_IS_V6(&upcb->local_ip) ?
"udp-ip6" :
"udp",
3237 recvQlen, sendQlen, local_ip_port, remote_ip_port,
" ");
3238 if ((iRet <= 0) || ((u32_t)(iRet) >= entry_buf_len)) {
3241 entry_buf_len -= (u32_t)(iRet);
3242 entry_buf_offset += (u32_t)(iRet);
3249 iRet = snprintf_s((
char *)(entry_buf + entry_buf_offset), entry_buf_len, entry_buf_len - 1,
3250 "\n%-8s%-12s%-12s%-20s%-20s%-16s%-16s\n",
3251 "Type",
"Recv-Q",
"Send-Q",
"Local Address",
"Foreign Address",
"Protocol",
"HDRINCL");
3252 if ((iRet <= 0) || ((u32_t)(iRet) >= entry_buf_len)) {
3255 entry_buf_len -= (u32_t)(iRet);
3256 entry_buf_offset += (u32_t)(iRet);
3258 for (rpcb =
raw_pcbs; rpcb != NULL; rpcb = rpcb->next) {
3259 iRet = snprintf_s((
char *)local_ip_port,
sizeof(local_ip_port), (
sizeof(local_ip_port) - 1),
3260 "%s", ipaddr_ntoa(&rpcb->local_ip));
3261 if ((iRet <= 0) || ((u32_t)(iRet) >=
sizeof(local_ip_port))) {
3265 iRet = snprintf_s((
char *)remote_ip_port,
sizeof(remote_ip_port), (
sizeof(remote_ip_port) - 1),
3266 "%s", ipaddr_ntoa(&rpcb->remote_ip));
3267 if ((iRet <= 0) || ((u32_t)(iRet) >=
sizeof(remote_ip_port))) {
3274 proto = rpcb->protocol;
3275 iRet = snprintf_s((
char *)(entry_buf + entry_buf_offset), entry_buf_len, entry_buf_len - 1,
3276 "%-8s%-12d%-12d%-20s%-20s%-16u%-16d\n",
3277 "raw", recvQlen, sendQlen, local_ip_port, remote_ip_port, proto, 0);
3278 if ((iRet <= 0) || ((u32_t)(iRet) >= entry_buf_len)) {
3281 entry_buf_len -= (u32_t)(iRet);
3282 entry_buf_offset += (u32_t)(iRet);
3287 iRet = snprintf_s((
char *)(entry_buf + entry_buf_offset), entry_buf_len, entry_buf_len - 1,
3288 "\n%-12s%-12s%-12s%-16s%-12s\n",
"Type",
"Recv-Q",
"Send-Q",
"Protocol",
"netif");
3289 if ((iRet <= 0) || ((u32_t)(iRet) >= entry_buf_len)) {
3292 entry_buf_len -= (u32_t)(iRet);
3293 entry_buf_offset += (u32_t)(iRet);
3295 for (rpcb =
pkt_raw_pcbs; rpcb != NULL; rpcb = rpcb->next) {
3299 for (netif = netif_list; netif != NULL; netif = netif->next) {
3300 if (netif_get_index(netif) == rpcb->netif_idx) {
3301 (
void)snprintf_s((
char *)netif_name, IFNAMSIZ, IFNAMSIZ - 1,
"%s", netif_get_name(netif));
3306 if (netif == NULL) {
3307 (
void)snprintf_s((
char *)netif_name, IFNAMSIZ, IFNAMSIZ - 1,
"%s",
"None");
3310 proto = rpcb->protocol;
3312 iRet = snprintf_s((
char *)(entry_buf + entry_buf_offset), entry_buf_len, entry_buf_len - 1,
3313 "%-12s%-12d%-12d%-16x%-12s\n",
"pkt-raw", recvQlen, sendQlen, proto, netif_name);
3314 if ((iRet <= 0) || ((u32_t)(iRet) >= entry_buf_len)) {
3317 entry_buf_len -= (u32_t)(iRet);
3318 entry_buf_offset += (u32_t)(iRet);
3336 PRINTK(
"\nUsage: netstat\n");
3341 PRINTK(
"%s: tcpip_init have not been called\n", __FUNCTION__);
3347 PRINTK(
"%s: no free mem\n", __FUNCTION__);
3358 if (err != ERR_OK) {
3381#define NETIF_NAME_LEN 10
3382STATIC VOID OsShellDhclientUsage(VOID)
3384 PRINTK(
"<netif name>, start dhcp for netif name\n"
3385 "-x <netif name>, stop dhcp for netif name\n"
3386 "-h | --help, print dhclient command usage\n");
3389u32_t OsShellDhclient(
int argc,
const char **argv)
3391 struct netif *netif = NULL;
3394 OsShellDhclientUsage();
3395 }
else if (argc == 1) {
3396 if (strcmp(argv[0],
"-h") == 0 || strcmp(argv[0],
"--help") == 0) {
3397 OsShellDhclientUsage();
3399 netif = netif_find(argv[0]);
3400 if (netif != NULL) {
3401 (VOID)netifapi_dhcp_start(netif);
3403 PRINTK(
"dhclient: invalid option: %s\n", argv[0]);
3404 OsShellDhclientUsage();
3407 }
else if (argc == 2) {
3408 if (strcmp(argv[0],
"-x") == 0) {
3409 netif = netif_find(argv[1]);
3410 if (netif != NULL) {
3411 (VOID)netifapi_dhcp_stop(netif);
3413 PRINTK(
"dhclient: invalid option: %s\n", argv[1]);
3414 OsShellDhclientUsage();
3417 PRINTK(
"dhclient: invalid option: %s\n", argv[0]);
3418 OsShellDhclientUsage();
3421 OsShellDhclientUsage();
3431#ifdef LWIP_DEBUG_TCPSERVER
3433#define MAX_SIZE 1024
3438 char msg[MAX_SIZE] = {0};
3440 PRINTK(
"waiting for recv\n");
3441 (
void)memset_s(msg, MAX_SIZE, 0, MAX_SIZE);
3442 ret =
recv(sockfd, msg, MAX_SIZE - 1, 0);
3444 PRINTK(
"recv failed, %d.\n", (u32_t)ret);
3447 }
else if (ret == 0) {
3449 PRINTK(
"client disconnect.\n");
3454 for (i = 0; i < n; ++i) {
3455 if (msg[i] >=
'a' && msg[i] <=
'z') {
3456 msg[i] = (char)(msg[i] + (
'A' -
'a'));
3457 }
else if (msg[i] >=
'A' && msg[i] <=
'Z') {
3458 msg[i] = (char)(msg[i] + (
'a' -
'A'));
3462 if (
send(sockfd, msg, n, 0) < 0) {
3463 PRINTK(
"send failed!\r\n");
3474 struct sockaddr_in seraddr;
3475 struct sockaddr_in cliaddr;
3476 u32_t cliaddr_size = (u32_t)
sizeof(cliaddr);
3477 int reuse, iPortVal;
3480 PRINTK(
"tcpip_init have not been called\n");
3484 if (argc < 1 || argv == NULL) {
3485 PRINTK(
"\nUsage: tcpserver <port>\n");
3489 iPortVal = atoi(argv[0]);
3491 if (iPortVal <= 0 || iPortVal > 65535) {
3492 PRINTK(
"\nUsage: Invalid port\n");
3496 port = (uint16_t)iPortVal;
3500 PRINTK(
"argv[0]:%s, argc:%d\r\n", argv[0], argc);
3501 sockfd =
socket(AF_INET, SOCK_STREAM, 0);
3503 PRINTK(
"\nUsage: create socket fail!\n");
3507 if (
setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, (
const char *)&reuse,
sizeof(reuse)) != 0) {
3509 PRINTK(
"set SO_REUSEADDR failed\n");
3513 (
void)memset_s(&seraddr,
sizeof(seraddr), 0,
sizeof(seraddr));
3514 seraddr.sin_family = AF_INET;
3515 seraddr.sin_addr.s_addr = htonl(INADDR_ANY);
3516 seraddr.sin_port = htons(port);
3518 ret =
bind(sockfd, (
struct sockaddr *)&seraddr,
sizeof(seraddr));
3520 PRINTK(
"bind ip and port failed");
3528 PRINTK(
"listen failed\n");
3532 PRINTK(
"waiting for accept\n");
3533 (
void)memset_s(&cliaddr,
sizeof(
struct sockaddr_in), 0,
sizeof(
struct sockaddr_in));
3534 ret = (
int)
accept(sockfd, (
struct sockaddr *)&cliaddr, &cliaddr_size);
3537 PRINTK(
"Accept failed, %d\n", ret);
3545#ifdef LOSCFG_SHELL_CMD_DEBUG
3550#ifdef LWIP_DEBUG_UDPSERVER
3551void udpserver(
int argc,
const char **argv)
3553 int sockfd, fromlen;
3555 struct sockaddr_in seraddr;
3556 struct sockaddr_in cliaddr;
3559 char msg[MAX_SIZE] = {0};
3563 PRINTK(
"\nUsage: udpserver <port>\n");
3567 iPortVal = atoi(argv[0]);
3569 if (iPortVal <= 0 || iPortVal > 65535) {
3570 PRINTK(
"\nUsage: Invalid Port\n");
3574 port = (uint16_t)iPortVal;
3576 PRINTK(
"port:%d\r\n", port);
3578 sockfd =
lwip_socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
3580 PRINTK(
"\ncreate socket fail\n");
3584 (
void)memset_s(&seraddr,
sizeof(seraddr), 0,
sizeof(seraddr));
3585 (
void)memset_s(&cliaddr,
sizeof(cliaddr), 0,
sizeof(cliaddr));
3586 seraddr.sin_family = AF_INET;
3587 seraddr.sin_addr.s_addr = htonl(INADDR_ANY);
3588 seraddr.sin_port = htons(port);
3589 ret =
lwip_bind(sockfd, (
struct sockaddr *)&seraddr,
sizeof(seraddr));
3591 PRINTK(
"bind ip and port failed:%d\n", errno);
3597 ret =
recvfrom(sockfd, msg, MAX_SIZE - 1, 0, (
struct sockaddr *)&cliaddr, (socklen_t *)&fromlen);
3600 for (i = 0; i < n; ++i) {
3601 if (msg[i] >=
'a' && msg[i] <=
'z') {
3602 msg[i] = (char)(msg[i] +
'A' -
'a');
3603 }
else if (msg[i] >=
'A' && msg[i] <=
'Z') {
3604 msg[i] = (char)(msg[i] +
'a' -
'A');
3607 ret =
sendto(sockfd, msg, n + 1, 0, (
struct sockaddr *)&cliaddr, (socklen_t)fromlen);
3608 if (ret <= 0 && errno == EPIPE) {
3620#ifdef LOSCFG_SHELL_CMD_DEBUG
3625#ifdef LWIP_DEBUG_INFO
3633 if (!strcmp(
"-i", argv[1])) {
3635 }
else if (!strcmp(
"-udp", argv[1])) {
3636 debug_memp_type_info(MEMP_UDP_PCB);
3637 }
else if (!strcmp(
"-tcp", argv[1])) {
3638 debug_memp_type_info(MEMP_TCP_PCB);
3639 }
else if (!strcmp(
"-raw", argv[1])) {
3640 debug_memp_type_info(MEMP_RAW_PCB);
3641 }
else if (!strcmp(
"-conn", argv[1])) {
3642 debug_memp_type_info(MEMP_NETCONN);
3646 }
else if (argc == 3) {
3647 if (!strcmp(
"-d", argv[1])) {
3648 type = atoi(argv[2]);
3650 debug_memp_detail(type);
3652 PRINTK(
"Error: type < 0\n");
3669 u32_t ret = LOS_NOK;
3672 if (!strcmp(
"-i", argv[1])) {
3674 for (idx = 0; idx < (
int)LWIP_CONFIG_NUM_SOCKETS; idx++) {
3675 debug_socket_info(idx, 1, 0);
3679 }
else if (argc == 3) {
3680 if (!strcmp(
"-d", argv[1])) {
3682 idx = atoi(argv[2]);
3684 debug_socket_info(idx, 1, 1);
3687 PRINTK(
"Error: idx < 0\n");
3698 u32_t ret = LOS_NOK;
3700 if (argc < 1 || argv == NULL) {
3704 if (!strcmp(
"memp", argv[0])) {
3706 if (ret != LOS_OK) {
3709 }
else if (!strcmp(
"sock", argv[0])) {
3712 if (ret != LOS_OK) {
3722 PRINTK(
"\nUsage:\n");
3723 PRINTK(
"netdebug memp {-i | -d <type> | -udp | -tcp | -raw |-conn}\n");
3724 PRINTK(
"netdebug sock {-i | -d <idx>}\n");
3729 PRINTK(
"\nUsage:\n");
3730 PRINTK(
"netdebug memp {-i | -d <type> | -udp | -tcp | -raw |-conn}\n");
3735 PRINTK(
"\nUsage:\n");
3736 PRINTK(
"netdebug sock {-i | -d <idx>}\n");
3741#if defined(LOSCFG_SHELL_CMD_DEBUG) && defined(LWIP_DEBUG_INFO)
3748 char acIPv6Addr[IP6ADDR_STRLEN_MAX + 1] = {0};
3749 char aclladdr[20] = {0};
3750 const char *acStates[] = {
"NO_ENTRY",
"INCOMPLETE",
"REACHABLE",
"STALE",
"DELAY",
"PROBE"};
3751 u8_t atleastOneEntry = 0;
3754 PRINTK(
"%s: tcpip_init have not been called\n", __FUNCTION__);
3759 PRINTK(
"=================\n");
3760 PRINTK(
"|| Prefix List ||\n");
3761 PRINTK(
"=================\n");
3762 PRINTK(
"%-50s %-16s %-20s\n",
"Prefix",
"netif",
"validLifetime");
3763 PRINTK(
"---------------------------------------------------------------------------------\n");
3765 for (i = 0; i < LWIP_ND6_NUM_PREFIXES; i++) {
3766 if (prefix_list[i].netif != NULL && prefix_list[i].invalidation_timer > 0) {
3767 atleastOneEntry = 1;
3768 (
void)ip6addr_ntoa_r((
const ip6_addr_t *)(prefix_list[i].prefix.addr), (acIPv6Addr),
sizeof(acIPv6Addr));
3769 PRINTK(
"%-50s ", acIPv6Addr);
3770 PRINTK(
"%-16s ", netif_get_name(prefix_list[i].netif));
3771 PRINTK(
"%-20u\n", prefix_list[i].invalidation_timer);
3775 if (!atleastOneEntry) {
3776 PRINTK(
"**** NO VALID PREFIXES FOUND CONFIGURED ****\n");
3778 PRINTK(
"---------------------------------------------------------------------------------\n");
3780 atleastOneEntry = 0;
3783 PRINTK(
"============================\n");
3784 PRINTK(
"|| Neighbor Cache Entries ||\n");
3785 PRINTK(
"============================\n");
3786 PRINTK(
"%-50s %-25s %-16s %-15s %-10s\n",
"Neighbor",
"MAC",
"netif",
"state",
"IsRouter");
3787 PRINTK(
"------------------------------------------------------------"
3788 "----------------------------------------------------------\n");
3791 for (i = 0; i < LWIP_ND6_NUM_NEIGHBORS; i++) {
3793 atleastOneEntry = 1;
3794 (
void)ip6addr_ntoa_r((
const ip6_addr_t *)(
neighbor_cache[i].next_hop_address.addr), (acIPv6Addr),
3795 sizeof(acIPv6Addr));
3796 PRINTK(
"%-50s ", acIPv6Addr);
3798 if (snprintf_s(aclladdr,
sizeof(aclladdr),
sizeof(aclladdr) - 1,
"%02X:%02X:%02X:%02X:%02X:%02X",
3803 PRINTK(
"%-25s ", aclladdr);
3809 if (!atleastOneEntry) {
3810 PRINTK(
"**** NO NEIGHBOURS FOUND ****\n");
3812 PRINTK(
"------------------------------------------------------------"
3813 "----------------------------------------------------------\n");
3815 atleastOneEntry = 0;
3818 PRINTK(
"===============================\n");
3819 PRINTK(
"|| Destination Cache Entries ||\n");
3820 PRINTK(
"===============================\n");
3821 PRINTK(
"%-50s %-50s %-10s %-10s\n",
"Destination",
"NextHop",
"PMTU",
"age");
3822 PRINTK(
"------------------------------------------------------------"
3823 "--------------------------------------------------------\n");
3825 for (i = 0; i < LWIP_ND6_NUM_DESTINATIONS; i++) {
3826 if (!ip6_addr_isany(&(destination_cache[i].destination_addr))) {
3827 atleastOneEntry = 1;
3828 (
void)ip6addr_ntoa_r((
const ip6_addr_t *)(destination_cache[i].destination_addr.addr), (acIPv6Addr),
3829 sizeof(acIPv6Addr));
3830 PRINTK(
"%-50s ", acIPv6Addr);
3831 (
void)ip6addr_ntoa_r((
const ip6_addr_t *)(destination_cache[i].next_hop_addr.addr), (acIPv6Addr),
3832 sizeof(acIPv6Addr));
3833 PRINTK(
"%-50s ", acIPv6Addr);
3834 PRINTK(
"%-10u ", destination_cache[i].pmtu);
3835 PRINTK(
"%-10u\n", destination_cache[i].age);
3838 if (!atleastOneEntry) {
3839 PRINTK(
"**** NO DESTINATION CACHE FOUND ****\n");
3841 PRINTK(
"------------------------------------------------------------"
3842 "--------------------------------------------------------\n");
3844 atleastOneEntry = 0;
3846 PRINTK(
"============================\n");
3847 PRINTK(
"|| Default Router Entries ||\n");
3848 PRINTK(
"============================\n");
3849 PRINTK(
"%-50s %-20s %-10s\n",
"Router",
"invalidation_timer",
"flags");
3850 PRINTK(
"-----------------------------------------------------------------------------\n");
3852 for (i = 0; i < LWIP_ND6_NUM_ROUTERS; i++) {
3853 if (default_router_list[i].neighbor_entry) {
3854 atleastOneEntry = 1;
3855 (
void)ip6addr_ntoa_r((
const ip6_addr_t *)((default_router_list[i].neighbor_entry)->next_hop_address.addr),
3856 (acIPv6Addr),
sizeof(acIPv6Addr));
3857 PRINTK(
"%-50s ", acIPv6Addr);
3858 PRINTK(
"%-20u ", default_router_list[i].invalidation_timer);
3859 PRINTK(
"%-10u\n", default_router_list[i].flags);
3862 if (!atleastOneEntry) {
3863 PRINTK(
"**** NO DEFAULT ROUTERS FOUND ****\n");
3865 PRINTK(
"-----------------------------------------------------------------------------\n");
3871#ifdef LOSCFG_SHELL_CMD_DEBUG
3875extern void cmd_reset(
void);
3877void osShellReboot(
int argc,
const char **argv)
3882#ifdef LOSCFG_SHELL_CMD_DEBUG
LWIP_STATIC void lwip_arp_internal(void *arg)
u32_t osShellPing(int argc, const char **argv)
LWIP_STATIC void lwip_ifconfig_usage(const char *cmd)
u32_t osShellPing6(int argc, const char **argv)
int netstat_udp_sendq(struct udp_pcb *upcb)
u32_t osTcpserver(int argc, const char **argv)
int netstat_netconn_recvq(const struct netconn *conn)
LWIP_STATIC void lwip_ifconfig_show_internal(void *arg)
int netstat_get_udp_sendQLen6(struct udp_pcb *udppcb, struct pbuf *udpbuf)
LWIP_STATIC void lwip_ifconfig_internal(void *arg)
int get_unused_socket_num(void)
volatile int tcpip_init_finish
int netstat_netconn_sendq(struct netconn *conn)
static void lwip_ping_usage(void)
void lwip_printsize(size_t size)
struct nd6_neighbor_cache_entry neighbor_cache[LWIP_ND6_NUM_NEIGHBORS]
u32_t lwip_ifconfig(int argc, const char **argv)
int netstat_tcp_sendq(struct tcp_pcb *tpcb)
const char *const tcp_state_str[]
void tcp_access(int sockfd)
u32_t osShellIpDebug(int argc, const char **argv)
struct ping6_stats ping6_stats_t
static void ping_cmd(unsigned int p0, unsigned int p1, unsigned int p2, unsigned int p3)
LWIP_STATIC const char * convert_icmpv6_err_to_string(u8_t err_type)
SHELLCMD_ENTRY(ifconfig_shellcmd, CMD_TYPE_EX, "ifconfig", XARGS,(CmdCallBackFunc) lwip_ifconfig)
void udpserver(int argc, const char **argv)
LWIP_STATIC int print_netif(struct netif *netif, char *print_buf, unsigned int buf_len)
u32_t osShellDns(int argc, const char **argv)
void ifup_internal(void *arg)
void ifdown_internal(void *arg)
u32_t osShellNetDebug(int argc, const char **argv)
LWIP_STATIC void lwip_arp_show_internal(struct netif *netif, char *printf_buf, unsigned int buf_len)
LWIP_STATIC void update_ping6_stats(ping6_stats_t *ping6_stats, u32_t rtt, u32_t nreceived)
LWIP_STATIC int osPingFunc(u32_t destip, u32_t cnt, u32_t interval, u32_t data_len)
LWIP_STATIC unsigned int get_hostip(const char *hname)
sys_sem_t ip_conflict_detect
struct ping6_args ping6_args_t
int netstat_tcp_recvq(struct tcp_pcb *tpcb)
LWIP_STATIC u32_t netdebug_memp(int argc, const char **argv)
int netstat_udp_sendq6(struct udp_pcb *upcb)
LWIP_STATIC struct hostent * gethostnameinfo(const char *host)
LWIP_STATIC int create_ping6_socket(u8_t type, const void *param)
u32_t lwip_arp(int argc, const char **argv)
u32_t osShellNtpdate(int argc, const char **argv)
LWIP_STATIC int parse_args_ping6(int argc, const char **argv, ping6_args_t *ping6_params)
LWIP_STATIC u32_t netdebug_sock(int argc, const char **argv)
int netstat_get_udp_sendQLen(struct udp_pcb *udppcb, struct pbuf *udpbuf)
LWIP_STATIC void lwip_arp_usage(const char *cmd)
u32_t osShellNetstat(int argc, const char **argv)
void netstat_internal(void *ctx)
@ CMD_TYPE_EX
不支持标准命令参数输入,会把用户填写的命令关键字屏蔽掉,例如:输入ls /ramfs,传入给注册函数的参数只有/ramfs,而ls命令关键字并不会被传入。
int ip6addr_aton(const char *cp, ip6_addr_t *addr)
sys_sem_t dup_addr_detect
struct netif * netifapi_netif_find_by_name(const char *name)
u32_t is_ip_conflict_signal
int lwip_sntp_start(int server_num, char **sntp_server, struct timeval *time)
u32_t is_dup_detect_initialized
err_t etharp_delete_arp_entry(struct netif *netif, ip4_addr_t *ipaddr)
err_t lwip_dns_setserver(u8_t numdns, ip_addr_t *dnsserver)
struct raw_pcb * raw_pcbs
err_t netif_set_hwaddr(struct netif *netif, const unsigned char *hw_addr, int hw_len)
err_t netif_dhcp_off(struct netif *netif)
err_t netif_do_rmv_ipv6_addr(struct netif *netif, void *arguments)
err_t etharp_update_arp_entry(struct netif *netif, const ip4_addr_t *ipaddr, struct eth_addr *ethaddr, u8_t flags)
err_t netif_set_mtu(struct netif *netif, u16_t netif_mtu)
struct raw_pcb * pkt_raw_pcbs
err_t lwip_dns_getserver(u8_t numdns, ip_addr_t *dnsserver)
LITE_OS_SEC_TEXT UINT32 LOS_CurTaskIDGet(VOID)
Obtain current running task ID.
LITE_OS_SEC_TEXT_INIT UINT32 LOS_TaskCreate(UINT32 *taskID, TSK_INIT_PARAM_S *initParam)
创建任务,并使该任务进入ready状态,如果就绪队列中没有更高优先级的任务,则运行该任务
VOID *(* TSK_ENTRY_FUNC)(UINTPTR param1, UINTPTR param2, UINTPTR param3, UINTPTR param4)
Define the type of a task entrance function.
int setsockopt(int s, int level, int optname, const void *optval, socklen_t optlen)
设置socket 配置项
in_addr_t inet_addr(const char *cp)
ssize_t recv(int s, void *mem, size_t len, int flags)
ssize_t sendto(int s, const void *dataptr, size_t size, int flags, const struct sockaddr *to, socklen_t tolen)
区别是送达地址,意思是这些数据要发给哪个地址的
int bind(int s, const struct sockaddr *name, socklen_t namelen)
int accept(int s, struct sockaddr *addr, socklen_t *addrlen)
const char * inet_ntop(int af, const void *src, char *dst, socklen_t size)
ssize_t recvfrom(int s, void *mem, size_t len, int flags, struct sockaddr *from, socklen_t *fromlen)
区别是返回源地址,意思是这些数据是从哪个地址过来的
int listen(int s, int backlog)
ssize_t send(int s, const void *dataptr, size_t size, int flags)
相当于文件操作的 write 功能,区别是第四个参数 同 recv
int socket(int domain, int type, int protocol)
ssize_t lwip_sendto(int s, const void *dataptr, size_t size, int flags, const struct sockaddr *to, socklen_t tolen)
int lwip_setsockopt(int s, int level, int optname, const void *optval, socklen_t optlen)
int lwip_bind(int s, const struct sockaddr *name, socklen_t namelen)
int lwip_socket(int domain, int type, int protocol)
char cb_print_buf[PRINT_BUF_LEN]
char cb_print_buf[PRINT_BUF_LEN]
u32_t netstat_out_buf_len
u32_t netstat_out_buf_updated_len
TSK_ENTRY_FUNC pfnTaskEntry
void sys_sem_free(sys_sem_t *sem)
void sys_sem_signal(sys_sem_t *sem)
u32_t sys_arch_sem_wait(sys_sem_t *sem, u32_t timeoutMs)
err_t sys_sem_new(sys_sem_t *sem, u8_t count)
ARG_NUM_3 ARG_NUM_1 ARG_NUM_2 ARG_NUM_2 ARG_NUM_3 ARG_NUM_1 ARG_NUM_4 ARG_NUM_2 ARG_NUM_2 ARG_NUM_5 ARG_NUM_2 ARG_NUM_0 ARG_NUM_2 ARG_NUM_1 ARG_NUM_2 ARG_NUM_3 ARG_NUM_7 ARG_NUM_2 ARG_NUM_3 ARG_NUM_2 ARG_NUM_4 ARG_NUM_5 ARG_NUM_6 ARG_NUM_3 ARG_NUM_5 ARG_NUM_7 ARG_NUM_1 ARG_NUM_4 ARG_NUM_5 ARG_NUM_4 ARG_NUM_7 ARG_NUM_2 ARG_NUM_3 ARG_NUM_7 ARG_NUM_7 ARG_NUM_3 ARG_NUM_3 ARG_NUM_3 ARG_NUM_7 ARG_NUM_3 ARG_NUM_2 char ARG_NUM_2 ARG_NUM_1 ARG_NUM_0 ARG_NUM_0 ARG_NUM_3 void ARG_NUM_1 ARG_NUM_0 unsigned ARG_NUM_0 ARG_NUM_2 ARG_NUM_3 ARG_NUM_2 ARG_NUM_5 ARG_NUM_3 ARG_NUM_3 ARG_NUM_4 ARG_NUM_1 ARG_NUM_1 ARG_NUM_3 ARG_NUM_2 ARG_NUM_1 ARG_NUM_4 ARG_NUM_4 ARG_NUM_5 ARG_NUM_3 ARG_NUM_2 void ARG_NUM_6 unsigned ARG_NUM_0 unsigned ARG_NUM_0 ARG_NUM_3 ARG_NUM_3 ARG_NUM_2 ARG_NUM_2 ARG_NUM_1 ARG_NUM_2 ARG_NUM_1 char ARG_NUM_0 ARG_NUM_4 ARG_NUM_1 ARG_NUM_2 ARG_NUM_2 ARG_NUM_4 ARG_NUM_5 ARG_NUM_2 ARG_NUM_3 ARG_NUM_3 ARG_NUM_3 ARG_NUM_3 ARG_NUM_6 ARG_NUM_6 ARG_NUM_5 ARG_NUM_3 void ARG_NUM_3 ARG_NUM_3 ARG_NUM_5 ARG_NUM_1 unsigned ARG_NUM_3 long
ARG_NUM_3 ARG_NUM_1 ARG_NUM_2 ARG_NUM_2 ARG_NUM_3 ARG_NUM_1 ARG_NUM_4 ARG_NUM_2 ARG_NUM_2 ARG_NUM_5 ARG_NUM_2 void
int clock_gettime(clockid_t clockID, struct timespec *tp)
当用户程序进行特定系统调用时(例如clock_gettime(CLOCK_REALTIME_COARSE, &ts)),VDSO代码页会将其拦截;
u32_t(* CmdCallBackFunc)(u32_t argc, const char **argv)