Skip to content

Commit 55ea2d0

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 55ea2d0

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
@@ -18,6 +18,9 @@ bool CLwipIf::pending_eth_rx = false;
1818

1919
FspTimer CLwipIf::timer;
2020

21+
/* ICMP ping callback data structure */
22+
static recv_callback_data requestCbkData;
23+
2124
static u8_t icmp_receive_callback(void *arg, struct raw_pcb *pcb, struct pbuf *p, const ip_addr_t *addr)
2225
{
2326
struct icmp_echo_hdr *iecho;
@@ -43,7 +46,6 @@ static u8_t icmp_receive_callback(void *arg, struct raw_pcb *pcb, struct pbuf *p
4346
request->endMillis = millis();
4447
pbuf_free(p);
4548
return 1; /* consume the packet */
46-
4749
}
4850

4951
ip_addr_t* u8_to_ip_addr(uint8_t* ipu8, ip_addr_t* ipaddr)
@@ -159,9 +161,12 @@ int CLwipIf::ping(IPAddress ip, uint8_t ttl)
159161
(void)ttl;
160162
ip_addr_t addr;
161163
addr.addr = ip;
162-
recv_callback_data requestCbkData = { 0, 0, (uint16_t)random(0xffff) };
163164

164-
//Create a raw socket
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)