Merge branch 'bugfix/fix_ping_specify_length_issue_v4.2' into 'release/v4.2'
bugfix: fix ICMP specify length issue (backport v4.2) See merge request espressif/esp-idf!9401
This commit is contained in:
commit
ce60660c7c
2 changed files with 4 additions and 3 deletions
|
@ -103,10 +103,10 @@ static int esp_ping_receive(esp_ping_t *ep)
|
||||||
int len = 0;
|
int len = 0;
|
||||||
struct sockaddr_storage from;
|
struct sockaddr_storage from;
|
||||||
int fromlen = sizeof(from);
|
int fromlen = sizeof(from);
|
||||||
|
uint16_t data_head = (uint16_t)(sizeof(struct ip_hdr) + sizeof(struct icmp_echo_hdr));
|
||||||
|
|
||||||
while ((len = recvfrom(ep->sock, buf, sizeof(buf), 0, (struct sockaddr *)&from, (socklen_t *)&fromlen)) > 0) {
|
while ((len = recvfrom(ep->sock, buf, sizeof(buf), 0, (struct sockaddr *)&from, (socklen_t *)&fromlen)) > 0) {
|
||||||
if (len >= (int)(sizeof(struct ip_hdr) + sizeof(struct icmp_echo_hdr))) {
|
if (len >= data_head) {
|
||||||
ep->recv_len = (uint32_t)len;
|
|
||||||
if (from.ss_family == AF_INET) {
|
if (from.ss_family == AF_INET) {
|
||||||
// IPv4
|
// IPv4
|
||||||
struct sockaddr_in *from4 = (struct sockaddr_in *)&from;
|
struct sockaddr_in *from4 = (struct sockaddr_in *)&from;
|
||||||
|
@ -126,6 +126,7 @@ static int esp_ping_receive(esp_ping_t *ep)
|
||||||
if ((iecho->id == ep->packet_hdr->id) && (iecho->seqno == ep->packet_hdr->seqno)) {
|
if ((iecho->id == ep->packet_hdr->id) && (iecho->seqno == ep->packet_hdr->seqno)) {
|
||||||
ep->received++;
|
ep->received++;
|
||||||
ep->ttl = iphdr->_ttl;
|
ep->ttl = iphdr->_ttl;
|
||||||
|
ep->recv_len = lwip_ntohs(IPH_LEN(iphdr)) - data_head; // The data portion of ICMP
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,7 +82,7 @@ typedef struct {
|
||||||
.count = 5, \
|
.count = 5, \
|
||||||
.interval_ms = 1000, \
|
.interval_ms = 1000, \
|
||||||
.timeout_ms = 1000, \
|
.timeout_ms = 1000, \
|
||||||
.data_size = 56, \
|
.data_size = 64, \
|
||||||
.tos = 0, \
|
.tos = 0, \
|
||||||
.target_addr = ip_addr_any_type, \
|
.target_addr = ip_addr_any_type, \
|
||||||
.task_stack_size = 2048, \
|
.task_stack_size = 2048, \
|
||||||
|
|
Loading…
Reference in a new issue