I used this written by someone else at work the other week, but I wanted to do it myself to understand it better.
Working code: https://github.com/superjamie/linux_udp_poll_latency