Skip to content

Commit 733e989

Browse files
committed
reduce storage consumption of ping command for C33
1 parent f032b82 commit 733e989

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

libraries/lwIpWrapper/src/CNetIf.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "CNetIf.h"
22
#include <functional>
3+
#include <stdlib.h>
34
#include "lwip/include/lwip/raw.h"
45
#include "lwip/include/lwip/icmp.h"
56
#include "lwip/include/lwip/ip_addr.h"
@@ -23,7 +24,9 @@ static u8_t icmp_receive_callback(void *arg, struct raw_pcb *pcb, struct pbuf *p
2324
struct icmp_echo_hdr *iecho;
2425
(void)(pcb);
2526
(void)(addr);
26-
LWIP_ASSERT("p != NULL", p != NULL);
27+
if(p == NULL) {
28+
return 0; /* don't consume the packet */
29+
}
2730

2831
recv_callback_data* request = (recv_callback_data*)arg;
2932
if ((p->tot_len < (PBUF_IP_HLEN + sizeof(struct icmp_echo_hdr))) ||
@@ -164,7 +167,8 @@ int CLwipIf::ping(IPAddress ip, uint8_t ttl)
164167

165168
/* initialize callback data for a new request */
166169
memset(&requestCbkData, 0, sizeof(recv_callback_data));
167-
requestCbkData.seqNum = (uint16_t)random(0xffff);
170+
srand(millis());
171+
requestCbkData.seqNum = (uint16_t)rand()%65535;
168172

169173
/* Create a raw socket */
170174
struct raw_pcb* s = raw_new(IP_PROTO_ICMP);

0 commit comments

Comments
 (0)