Everything you ever wanted to know about UDP sockets but were afraid to ask
blog.cloudflare.com
blog.cloudflare.com
Doing basic CMSG operations in some programming languages is remarkably hard. Using IPv4-mapped-IPv6 addresses is little known. Most programming languages and frameworks are unaware of AF_UNSPEC. And so on.
Not everybody will end up doing the low level socket juggling, but I think it's at least good to know the capabilities of the operating system.
After bind() before connect() there is a race condition, you can receive packets going to unconnected bind() socket, right?
bind(0.0.0.0, 1234)
## packet to port 1234 arrives NOW
connect(1.1.1.1, 53)
If you recv() you will not be able to figure out if the received packet came from 1.1.1.1 or someone else. Therefore in case of bind+connect you must use recvfrom and validate source of the packet, at least for early packets on the socket.You are absolutely right, there is very little documentation on UDP (probably because it was a pariah protocol reserved for "weird" things like DNS and SIP).
Now that UDP is becoming the mainstream, any documentation is highly appreciated.
Any chance of an article explaining difference in UDP handling between Linux and Windows? I've seen some weird client UDP issues on Windows side some time ago, and (unsurprisingly) found zero documentation explaining these issues.
I mean it happens, but on a high-profile site like cloudflare?