check netdevice status

#include <sys/ioctl.h>
#include <net/if.h>

int check_netdevice_status(void)
{
    struct ifreq req;

    memset(&req, 0, sizeof(req));
    strcpy(req.ifr_name, "wlan0");
    
    int skfd = socket(AF_INET, SOCK_DGRAM, 0);
    if (skfd < 0) 
    {
        return -1;
    }
    
    if (ioctl(skfd, SIOCGIFFLAGS, &req) < 0)
    {
        close(skfd);
        return -2;
    }
    
    if(!req.ifr_flags & IFF_RUNNING)
    {
        close(skfd);
        return -3; 
    }

    close(skfd);
    return 0;
}