I'm trying to find a way to bind an IPv4 UDP socket to a broadcast address in Micrium (µC/OS-Ⅲ).
Attempt to bind a socket to the actual broadcast address just returns NET_SOCK_ERR_INVALID_ADDR
. The broadcast is not explicitly mentioned on the list of things to bind on the NetSock_Bind
call documentation, there is no analogue of SO_BROADCAST
either. Is it impossible at all?
Can I, as a last resort, add a broadcast address to an existing interface as its own address (this shouldn't mess up ARP, since nobody is going to ask for it, and I'm not going to send anything through it)?
look at micrium documentation. Follow the steps and you'll get no error.
BTW, if you won't use
NetApp_SetSockAddr
and try to bind usingNetSock_Bind
, you'll receive theNET_SOCK_ERR_INVALID_ADDR
which happened to you.Edit:
look at the next code, which works for me. Note that the IP Address I manually initialized the host's address and used the defined address
NET_SOCK_ADDR_IP_V4_WILDCARD
.What I said about the
NetApp_SetSockAddr()
function, is that if I call it instead of manually initializing the host, it returned the error you received.