From 0e2dded3469b4f43709ed6af0d61da434d207696 Mon Sep 17 00:00:00 2001 From: arvinzzz Date: Tue, 22 Mar 2022 19:47:03 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=91=8A=E8=AD=A6=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: arvinzzz Change-Id: I09d6e86c958838d95297176c235fe1a7ad34c88c --- components/net/lwip-2.1/porting/src/api_shell.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/components/net/lwip-2.1/porting/src/api_shell.c b/components/net/lwip-2.1/porting/src/api_shell.c index ec4da034..222134a8 100644 --- a/components/net/lwip-2.1/porting/src/api_shell.c +++ b/components/net/lwip-2.1/porting/src/api_shell.c @@ -282,7 +282,7 @@ LWIP_STATIC unsigned int get_hostip(const char *hname) free(tmphstbuf); return 0; } - ret = memcpy_s(&ip, sizeof(ip), pent->h_addr, 4); + ret = memcpy_s(&ip, sizeof(ip), pent->h_addr, sizeof(pent->h_addr)); if (ret != EOK) { free(tmphstbuf); return 0; @@ -410,7 +410,7 @@ LWIP_STATIC int OsPingFunc(u32_t *parg) /* Accessing ip header and icmp header */ iphdr_resp = pbuf_resp->payload; - ip_hlen = (IPH_HL(iphdr_resp) << 2); + ip_hlen = (IPH_HL(iphdr_resp) << 2); /* 2: offset */ if (pbuf_header(pbuf_resp, -ip_hlen)) { /* this failure will never happen, but failure handle is written just to be in safe side */ PRINTK("Ping : memory management failure\n"); @@ -428,7 +428,8 @@ LWIP_STATIC int OsPingFunc(u32_t *parg) ((ICMPH_TYPE(iecho_resp) == ICMP_ECHO) && (iphdr_resp->src.addr == to.sin_addr.s_addr))) { /* second type timeout event */ (void)clock_gettime(CLOCK_MONOTONIC_RAW, &end); - timout_ms = ((end.tv_sec - start.tv_sec) * 1000 + (end.tv_nsec - start.tv_nsec) / 1000000); + timout_ms = ((end.tv_sec - start.tv_sec) * OS_SYS_MS_PER_SECOND + \ + (end.tv_nsec - start.tv_nsec) / OS_SYS_NS_PER_MS); timout_ms = LWIP_SHELL_CMD_PING_TIMEOUT - timout_ms; } else { timout_ms = 0; @@ -445,7 +446,8 @@ LWIP_STATIC int OsPingFunc(u32_t *parg) } /* capture the end time to calculate round trip time */ (void)clock_gettime(CLOCK_MONOTONIC_RAW, &end); - rtt = ((end.tv_sec - start.tv_sec) * 1000 + (end.tv_nsec - start.tv_nsec) / 1000000); + rtt = ((end.tv_sec - start.tv_sec) * OS_SYS_MS_PER_SECOND + \ + (end.tv_nsec - start.tv_nsec) / OS_SYS_NS_PER_MS); if (iphdr_resp->src.addr == to.sin_addr.s_addr) { switch (ICMPH_TYPE(iecho_resp)) { @@ -461,12 +463,12 @@ LWIP_STATIC int OsPingFunc(u32_t *parg) /* delay 1s for every successful ping */ intrvl = interval; do { - if (intrvl < 1000) { + if (intrvl < 1000) { /* 1000: 1000ms = 1s */ sys_msleep(intrvl); break; } - intrvl -= 1000; - sys_msleep(1000); + intrvl -= 1000; /* 1000: 1000ms = 1s */ + sys_msleep(1000); /* 1000: 1000ms = 1s */ if (ping_kill == 1) break; } while (intrvl > 0);