Skip to content
Prev Previous commit
lwIpWrapper: CNetIf make recv_callback_data a static data structure
  This ensure access to existing data if icmp callback is fired after ping timeout
  • Loading branch information
pennam committed Mar 3, 2025
commit 8094f719bf74c5327438902b9883e8abcef73c9e
11 changes: 8 additions & 3 deletions libraries/lwIpWrapper/src/CNetIf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ static u8_t icmp_receive_callback(void *arg, struct raw_pcb *pcb, struct pbuf *p
request->endMillis = millis();
pbuf_free(p);
return 1; /* consume the packet */

}

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

//Create a raw socket
/* ICMP ping callback data structure */
static recv_callback_data requestCbkData;

/* initialize callback data for a new request */
memset(&requestCbkData, 0, sizeof(recv_callback_data));
requestCbkData.seqNum = (uint16_t)random(0xffff);

/* Create a raw socket */
struct raw_pcb* s = raw_new(IP_PROTO_ICMP);
if (!s) {
return -1;
Expand Down
Loading