Strncpy is not used correctly either.
strncpy(ifr.ifr_name, dev, IFNAMSIZ);
will not necessarily NULL terminate ifr.ifr_name for all values of dev variable. NULL terminated input is assumed later when ifr.ifr_name is used in strcpy.