AP_HAL: make recv call to be undirected but also get the ip:port of received packet

This commit is contained in:
bugobliterator 2024-02-07 18:06:13 +11:00 committed by Andrew Tridgell
parent 43615f22b7
commit 3c69f156f4
1 changed files with 6 additions and 2 deletions

View File

@ -327,8 +327,12 @@ ssize_t SOCKET_CLASS_NAME::recv(void *buf, size_t size, uint32_t timeout_ms)
socklen_t len = sizeof(struct sockaddr_in);
int fin = get_read_fd();
ssize_t ret;
ret = CALL_PREFIX(recvfrom)(fin, buf, size, MSG_DONTWAIT, (sockaddr *)&last_in_addr[0], &len);
if (ret <= 0) {
uint32_t in_addr[4] = {};
ret = CALL_PREFIX(recvfrom)(fin, buf, size, MSG_DONTWAIT, (sockaddr *)&in_addr[0], &len);
if (ret > 0) {
// only update last_in_addr if we received data
memcpy(last_in_addr, in_addr, sizeof(last_in_addr));
} else {
if (!datagram && connected && ret == 0) {
// remote host has closed connection
connected = false;