Skip to main content

Practice ยท 3 of 3

UDP Send and Receive

CHALLENGE
Difficulty: advanced+25 XP

POSIX. Implement ssize_t udp_roundtrip(int ufd, const char *msg, char *out, size_t cap) โ€” sendto msg to the loopback address and the socket's OWN bound port (getsockname), then recvfrom into out (at most cap-1 bytes, NUL-terminated) and return the byte count, or -1 on any failure (NULL args, cap 0). Bind ufd to port 0 before calling โ€” the tests do.

Back to lesson: Practice: Socket Drills on Loopback