I can already measure the latency of TCP sockets over the loopback interface. I want to compare this to TCP sockets connecting to one of the ‘real’ addresses the machine has, to see if it’s any different. I could see this being either the same as the loopback interface, or being slower. I’m way below the level I have any real knowledge of at this point, so there’s only one way to find out.

But rather than hardcode in the IP addresses, or take them on the command line, I want the benchmark to find them itself. One thing I want out of these benchmarks is for them to build on any Linux system, and run without needing machine-specific arguments. When I find out what IP addresses my machine has, I use ifconfig. But how does ifconfig do it? I was about to Google the answer when I realised this would be a perfect time use strace, and so I did!

Here’s the quick summary of what happens:

  1. create sockets of both AF_INET and AF_INET6 families
  2. read /proc/net/dev to get a complete list of interfaces; we’ll need this to get the addresses for AF_INET6 socket, as well as to get the list of interfaces that don’t have an AF_INET address
  3. use the SIOCGIFCONF ioctl to get a list of addresses for AF_INET
  4. loop through the interface names that came from /proc/net/dev and for each one
    • read /proc/net/if_inet6 to get the IPv6 address for the interface, if any
    • use a series of ioctl calls to get data about the interface

To see in more detail, take a look at this gist for an annotated strace of ifconfig and ifconfig -s.