|
|
|
|
|
by ergl
1334 days ago
|
|
You can actually use connect(2) for UDP. From the manual https://man7.org/linux/man-pages/man2/connect.2.html: > If the socket sockfd is of type SOCK_DGRAM, then addr is the address to which datagrams are sent by default, and the only address from which datagrams are received. After that, you can use send() instead of sendmsg(), so it saves you on having to pass the host on each call to sendmsg. It can also avoid extra DNS lookups: everything is handled for you by the kernel. See also: https://stackoverflow.com/a/51296247 |
|
Actually, I don't know what happens if the DNS record expires during the connection. I would presume nothing -- that the socket will stay open with the same (possibly now invalid) destination IP until closed.