2016-09-20 37 views
0

可疑人物我有以下簡單的方法:iwlib試圖獲得接入點名稱 - u.addr.sa_data包含導致空的QString

const QString& UeNetworkManager::ueAccessPointMACAddress(const QString& interfaceName) const 
{ 
    static QString ueMACAddress=QString(); 
    iwreq wrq; 
    int result=0; 
    int kernelSocket=iw_sockets_open(); 

    ueMACAddress.clear(); 

    result=iw_get_ext(kernelSocket, 
         interfaceName.toLocal8Bit().constData(), 
         SIOCGIWAP, 
         &wrq); 

    ueMACAddress=result>=0?QString(wrq.u.addr.sa_data):"Invalid MAC address"; 

    iw_sockets_close(kernelSocket); 

    return ueMACAddress; 
} // ueAccessPointMACAddress 

現在,我想提取使用此接入點的MAC地址方法從wrq結構 - 其u.addr.sa_data成員,其中(我認爲,AM不確定)containts MAC地址的接入點。 Follownig調試截圖顯示值u.addr.sa_data成員: QtCreatorDebugScenario 爲什麼我會在ueMACAddress=result>=0?QString(wrq.u.addr.sa_data):"Invalid MAC address";之後得到空的QString代碼行?

回答

0

看來我用錯了命令,這裏的工作方法:

const QStringList& UeNetworkManager::ueAccessPointMACAddresses(const QString& interfaceName) 
{ 
    static QStringList ueMACAddresses=QStringList(); 
    iwrange rangeScan; 
    wireless_scan_head scanResultHead; 
    wireless_scan* scanResult=Q_NULLPTR; 
    int kernelSocket=iw_sockets_open(); 

    ueMACAddresses.clear(); 

    if(iw_get_range_info(kernelSocket, 
         interfaceName.toLocal8Bit().constData(), 
         &rangeScan)>=0) 
    { 
     if(iw_scan(kernelSocket, 
        interfaceName.toLocal8Bit().data(), 
        rangeScan.we_version_compiled, 
        &scanResultHead)>=0) 
     { 
      scanResult=scanResultHead.result; 

      while(scanResult!=Q_NULLPTR) 
      { 
       ueMACAddresses.append(QByteArray(scanResult->ap_addr.sa_data).toHex()); 

       scanResult=scanResult->next; 
      } // while 
     } 
     else 
     { 
      ueMACAddresses.append(tr("MAC scan failed.")); 
     } // if 
    } 
    else 
    { 
      ueMACAddresses.append(interfaceName+ 
            " "+ 
            tr("range scan failed.")); 
    } // if 

    iw_sockets_close(kernelSocket); 

    return ueMACAddresses; 
} // ueAccessPointMACAddress