I'm receiving multicast UDP packets, which works fine, but I don't seem to be getting a valid address returned after I call asyncdispatch.recvFromInto.
Here's a fragment of my code:
- var
- message = newString(1000) sock_address: SockAddr sock_address_len: SockLen
- while true:
- let length = await sock_fd.recvFromInto(
- addr(message[0]), 1000, addr(sock_address), addr(sock_address_len)
)
A valid message is received, but the sock_address appears to be invalid when I later try to decode it using net.fromSockAddr or posix.getnameinfo. The sock_address_len is always zero.
I notice that down in the posix module the SockAddr structure is defined as:
I'm using FreeBSD which has an extra unsigned char called sa_len at the beginning of the struct. I don't know if this is contributing to the problem.
I'm using FreeBSD which has an extra unsigned char called sa_len at the beginning of the struct. I don't know if this is contributing to the problem.
Try adding it and see if that helps.
By the way, since you're already messing around with UDP and async. Maybe you'd be interested in implementing UDP procs in asyncnet to abstract all this low-level logic? (Ideally they should match their equivalents in net: https://nim-lang.org/docs/net.html#recvFrom%2CSocket%2Cstring%2Cint%2Cstring%2CPort%2Cint32)