Skip to content

Commit 9230e0d

Browse files
bugfix: fix ICMP specify length issue
1 parent 7c5a561 commit 9230e0d

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

components/lwip/apps/ping/ping_sock.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,10 @@ static int esp_ping_receive(esp_ping_t *ep)
103103
int len = 0;
104104
struct sockaddr_storage from;
105105
int fromlen = sizeof(from);
106+
uint16_t data_head = (uint16_t)(sizeof(struct ip_hdr) + sizeof(struct icmp_echo_hdr));
106107

107108
while ((len = recvfrom(ep->sock, buf, sizeof(buf), 0, (struct sockaddr *)&from, (socklen_t *)&fromlen)) > 0) {
108-
if (len >= (int)(sizeof(struct ip_hdr) + sizeof(struct icmp_echo_hdr))) {
109-
ep->recv_len = (uint32_t)len;
109+
if (len >= data_head) {
110110
if (from.ss_family == AF_INET) {
111111
// IPv4
112112
struct sockaddr_in *from4 = (struct sockaddr_in *)&from;
@@ -126,6 +126,7 @@ static int esp_ping_receive(esp_ping_t *ep)
126126
if ((iecho->id == ep->packet_hdr->id) && (iecho->seqno == ep->packet_hdr->seqno)) {
127127
ep->received++;
128128
ep->ttl = iphdr->_ttl;
129+
ep->recv_len = lwip_ntohs(IPH_LEN(iphdr)) - data_head; // The data portion of ICMP
129130
return len;
130131
}
131132
}

components/lwip/include/apps/ping/ping_sock.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ typedef struct {
8282
.count = 5, \
8383
.interval_ms = 1000, \
8484
.timeout_ms = 1000, \
85-
.data_size = 56, \
85+
.data_size = 64, \
8686
.tos = 0, \
8787
.target_addr = ip_addr_any_type, \
8888
.task_stack_size = 2048, \

0 commit comments

Comments
 (0)