This is an automated email from the ASF dual-hosted git repository.
acassis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new 5ba4dcfe464 net/netdev: Return the broadcast address for
SIOCGIFBRDADDR.
5ba4dcfe464 is described below
commit 5ba4dcfe46466d89c0916e76b21732530b7904c6
Author: Marco Casaroli <[email protected]>
AuthorDate: Sun Nov 8 09:44:31 2026 +0100
net/netdev: Return the broadcast address for SIOCGIFBRDADDR.
ioctl_get_ipv4broadcast() stored the result of net_ipv4addr_broadcast()
as the address. That macro tests if an address is a broadcast address
and gives 0 or 1. So SIOCGIFBRDADDR returned 0.0.0.0 for a normal
interface address.
Return the device address with all host bits set (the address OR the
inverted netmask) if the device has IFF_BROADCAST, else 0.0.0.0, as
Linux does. So lo and point-to-point devices still return 0.0.0.0.
Assisted-by: Claude Code:claude-opus-5-5
Signed-off-by: Marco Casaroli <[email protected]>
---
net/netdev/netdev_ioctl.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/net/netdev/netdev_ioctl.c b/net/netdev/netdev_ioctl.c
index 6d752ad1465..03b744a5086 100644
--- a/net/netdev/netdev_ioctl.c
+++ b/net/netdev/netdev_ioctl.c
@@ -284,24 +284,28 @@ static void ioctl_get_ipv4addr(FAR struct sockaddr
*outaddr,
* Name: ioctl_get_ipv4broadcast
*
* Description:
- * Return the sub-net broadcast address to user memory.
+ * Return the sub-net broadcast address to user memory. A device without
+ * IFF_BROADCAST has no broadcast address: return 0.0.0.0.
*
* Input Parameters:
* outaddr - Pointer to the user-provided memory to receive the address.
* inaddr - The source IP address in the device structure.
* netmask - The netmask address mask in the device structure.
+ * flags - The interface flags in the device structure.
*
****************************************************************************/
#ifdef CONFIG_NET_IPv4
static void ioctl_get_ipv4broadcast(FAR struct sockaddr *outaddr,
- in_addr_t inaddr, in_addr_t netmask)
+ in_addr_t inaddr, in_addr_t netmask,
+ uint32_t flags)
{
FAR struct sockaddr_in *dest = (FAR struct sockaddr_in *)outaddr;
dest->sin_family = AF_INET;
dest->sin_port = 0;
- dest->sin_addr.s_addr = net_ipv4addr_broadcast(inaddr, netmask);
+ dest->sin_addr.s_addr = IFF_IS_BROADCAST(flags) ?
+ inaddr | ~netmask : 0;
memset(dest->sin_zero, 0, sizeof(dest->sin_zero));
}
#endif
@@ -1024,7 +1028,7 @@ static int netdev_ifr_ioctl(FAR struct socket *psock, int
cmd,
case SIOCGIFBRDADDR: /* Get broadcast IP address */
ioctl_get_ipv4broadcast(&req->ifr_broadaddr, dev->d_ipaddr,
- dev->d_netmask);
+ dev->d_netmask, dev->d_flags);
break;
case SIOCSIFBRDADDR: /* Set broadcast IP address */