linux 检查设备wifi连接的状态

typedef enum {
    NO_AP,
    HAVE_AP_NO_STA,
    HAVE_AP_HAVE_STA,
}wifi_t;

int getwifi_status(void)
{
#define WIFI_FLAG_STR "sta's macaddr:"
    char buf[64] = {0};
    int n = 0;
	FILE *m_pStream = NULL;

    if (NULL == m_pStream) {
        m_pStream = fopen("/proc/net/rtl8812au/wlan0/all_sta_info", "r");
        return NO_AP;
    }
    if (fseek(m_pStream, 0, SEEK_SET) < 0) {
        if (m_pStream) {
            fclose(m_pStream);
            m_pStream = NULL;
        }
        return NO_AP;
    }
    while (NULL != (fgets(buf, 64, m_pStream))) {
        if (!strncmp(buf, WIFI_FLAG_STR, strlen(WIFI_FLAG_STR))) {
            n++;
        }
    }
    /*
    	count = 0,1,no device
    	count = 2,found wifi,no conect
    	count >=3,sta num = (count-2)
    */
    if (n <= 1) {
        return NO_AP;
    }
    if (2 == n) {
        return HAVE_AP_NO_STA;
    }
    return HAVE_AP_HAVE_STA;
}

版权声明:本文为ding283595861原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。