From 1e8897a61addec5c2067ffbab38122d6c236ced3 Mon Sep 17 00:00:00 2001 From: "Luke T. Shumaker" Date: Mon, 4 Nov 2024 12:49:09 -0700 Subject: libhw: net.h: Clarify UDP truncation behavior --- libhw/common_include/libhw/generic/net.h | 5 +++++ libhw/host_net.c | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'libhw') diff --git a/libhw/common_include/libhw/generic/net.h b/libhw/common_include/libhw/generic/net.h index 8dedaea..e23dcda 100644 --- a/libhw/common_include/libhw/generic/net.h +++ b/libhw/common_include/libhw/generic/net.h @@ -106,6 +106,11 @@ struct net_packet_conn_vtable { ssize_t (*sendto )(implements_net_packet_conn *self, void *buf, size_t len, struct net_ip4_addr node, uint16_t port); + /** + * @return The full length of the message, which may be more + * than the given `len` (as if the Linux MSG_TRUNC flag were + * given). + */ ssize_t (*recvfrom)(implements_net_packet_conn *self, void *buf, size_t len, struct net_ip4_addr *ret_node, uint16_t *ret_port); diff --git a/libhw/host_net.c b/libhw/host_net.c index 27df2e2..75486aa 100644 --- a/libhw/host_net.c +++ b/libhw/host_net.c @@ -457,7 +457,8 @@ static void *hostnet_pthread_recvfrom(void *_args) { if (*(args->ret_size) < 0) goto end; - *(args->ret_size) = recvfrom(args->connfd, args->buf, args->count, 0, &addr.gen, &addr_size); + *(args->ret_size) = recvfrom(args->connfd, args->buf, args->count, + MSG_TRUNC, &addr.gen, &addr_size); if (*(args->ret_size) < 0) goto end; -- cgit v1.2.3-2-g168b