You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
peek() function always returns the first byte of the packet.
Expected behavior
The peek()should return the same data byte as the next read() call.
Explanation
This is the implementation of the UDP peek function:
intEthernetUDP::peek()
{
uint8_t b;
// Unlike recv, peek doesn't check to see if there's any data available, so we must.// If the user hasn't called parsePacket yet then return nothing otherwise they// may get the UDP headerif (!_remaining) {
return -1;
}
b = pbuf_get_at(_udp.data.p, 0);
return b;
}
It is just a wrapper arround the lwip function pbuf_get_at(). This function returns the byte at index 0 of the current buffer.
It should returns the byte at the current read position of the current buffer.
Fix
The function is modified to take into account the read position.
intEthernetUDP::peek()
{
uint8_t b;
// Unlike recv, peek doesn't check to see if there's any data available, so we must.// If the user hasn't called parsePacket yet then return nothing otherwise they// may get the UDP headerif (!_remaining) {
return -1;
}
b = pbuf_get_at(_udp.data.p, _udp.data.p->tot_len - _udp.data.available);
return b;
}
Now peek() function returns the byte of the packet at the current read position as expected.
Same correction can be applied for the EthernetClient class (untested):
intEthernetClient::peek()
{
uint8_t b;
// Unlike recv, peek doesn't check to see if there's any data available, so we mustif (!available()) {
return -1;
}
b = pbuf_get_at(_tcp_client->data.p, _tcp_client->data.p->tot_len - _tcp_client->data.available);
return b;
}
Desktop
OS: Windows
Eclipse CDT version: 2024-06
Sloeber version: 4.4.3
STM32 core version: 2.7.1
Upload method: SWD
Hardware
Board Name: Nucleo F767ZI
Hardware Revision: Rev B
The text was updated successfully, but these errors were encountered:
Description
The
peek()
functions of theEthernetUDP
andEthernetClient
classes always returns the first byte of a packet.A fix is proposed.
To Reproduce
Code used:
Command to generate a packet:
snmpget -v 2c -c public 192.168.2.2 SNMPv2-MIB::sysName.0 -r0 -d Sending 43 bytes to UDP: [192.168.2.2]:161->[0.0.0.0]:46928 0000: 30 29 02 01 01 04 06 70 75 62 6C 69 63 A0 1C 02 0).....public... 0016: 04 71 FB CD 11 02 01 00 02 01 00 30 0E 30 0C 06 .q.........0.0.. 0032: 08 2B 06 01 02 01 01 05 00 05 00 .+.........
Serial output:
peek()
function always returns the first byte of the packet.Expected behavior
The
peek()
should return the same data byte as the nextread()
call.Explanation
This is the implementation of the UDP
peek
function:It is just a wrapper arround the lwip function
pbuf_get_at()
. This function returns the byte at index 0 of the current buffer.It should returns the byte at the current read position of the current buffer.
Fix
The function is modified to take into account the read position.
Serial output:
Now
peek()
function returns the byte of the packet at the current read position as expected.Same correction can be applied for the
EthernetClient
class (untested):Desktop
Hardware
The text was updated successfully, but these errors were encountered: