Skip to content

Commit 8094f71

Browse files
committed
lwIpWrapper: CNetIf make recv_callback_data a static data structure
This ensure access to existing data if icmp callback is fired after ping timeout
1 parent 7f6ad1e commit 8094f71

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

Diff for: libraries/lwIpWrapper/src/CNetIf.cpp

+8-3
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ static u8_t icmp_receive_callback(void *arg, struct raw_pcb *pcb, struct pbuf *p
4343
request->endMillis = millis();
4444
pbuf_free(p);
4545
return 1; /* consume the packet */
46-
4746
}
4847

4948
ip_addr_t* u8_to_ip_addr(uint8_t* ipu8, ip_addr_t* ipaddr)
@@ -159,9 +158,15 @@ int CLwipIf::ping(IPAddress ip, uint8_t ttl)
159158
(void)ttl;
160159
ip_addr_t addr;
161160
addr.addr = ip;
162-
recv_callback_data requestCbkData = { 0, 0, (uint16_t)random(0xffff) };
163161

164-
//Create a raw socket
162+
/* ICMP ping callback data structure */
163+
static recv_callback_data requestCbkData;
164+
165+
/* initialize callback data for a new request */
166+
memset(&requestCbkData, 0, sizeof(recv_callback_data));
167+
requestCbkData.seqNum = (uint16_t)random(0xffff);
168+
169+
/* Create a raw socket */
165170
struct raw_pcb* s = raw_new(IP_PROTO_ICMP);
166171
if (!s) {
167172
return -1;

0 commit comments

Comments
 (0)