Hi! Great article, but I can’t understand how we can get this numbers IFREQ_SIZE = 0x0028…
Dmitry Chopey
1

Thanks for the kind words Dmitry!

Great question… we can get these numbers with a little bit of C.

Both IFREQ_SIZE and IFINDEX_SIZE are the size in bytes of C data structures (ifreq and int) which we can get using sizeof.

SIOCGIFINDEX is a constant defined in the sys/ioctl.h header file.

Here’s a snippet which will print each of these values in hexadecimal:

#include <stdio.h>
#include <net/if.h>
#include <sys/ioctl.h>
int main(int argc, char **argv) {
printf("IFREQ_SIZE = 0x%04lX\n", sizeof(struct ifreq));
printf("IFINDEX_SIZE = 0x%04lX\n", sizeof(int));
printf("SIOCGIFINDEX = 0x%04X\n", SIOCGIFINDEX);
return 0;
}

Hope that helps :)