SIOCGIWFREQ ioctl返回错误22 EINVAL -无效的参数,为什么
SIOCGIWFREQ ioctl returning error 22 EINVAL - Invalid argument, why?
我正在努力使用以下Qt/C++
方法使用Linux库的无线扩展工具读取Wifi卡的当前频率通道:
const UeTypeCurrentFrequencyChannel& UeNetworkManager::ueCurrentFrequencyChannel(const QString& interfaceName)
{
static UeTypeCurrentFrequencyChannel result=UeTypeCurrentFrequencyChannel();
iwreq wrq;
iw_range range;
int kernelSocket=iw_sockets_open();
if(iw_get_range_info(kernelSocket,
interfaceName.toLocal8Bit().constData(),
&range)>=0)
{
if(iw_get_ext(kernelSocket,
interfaceName.toLocal8Bit().constData(),
SIOCGIWFREQ,
&wrq)>=0)
{
//BUG current frequency and channel is not read, it might be becuase of nonroot credentials - it returns error 22 (EINVAL - Invalid argument), why?
result.first=iw_freq2float(&(wrq.u.freq));
result.second=iw_freq_to_channel(result.first.toDouble(),
&range);
qDebug() << Q_FUNC_INFO
<< "success - current channel:"
<< result;
}
else
{
result.first=QString(interfaceName);
result.second=QString(tr("current channel read failed."));
qDebug() << Q_FUNC_INFO
<< "error (iw_get_ext):"
<< errno;
} // if
}
else
{
result.first=QString(interfaceName);
result.second=QString(tr("current channel read failed."));
qDebug() << Q_FUNC_INFO
<< "error (iw_get_range_info):"
<< errno;
} // if
iw_sockets_close(kernelSocket);
return result;
} // ueCurrentFrequencyChannel
现在,iw_get_ext
总是返回-1
, errno
被设置为22
的值。我已经看了errno.h和搜索错误22
,我有以下错误声明:#define EINVAL 22 /* Invalid argument */
。
为什么我在试图用ioctl
查询网卡的当前频率通道时得到Invalid argument
错误?我已经启动了应用程序,其中包含普通用户和root用户的代码,任何时候都是相同的结果:
static const UeTypeCurrentFrequencyChannel& UeNetworkManager::ueCurrentFrequencyChannel(const QString&) error(iw_get_ext): 22
为什么,我错过了什么?
附录# 1:
如果我从终端使用iwlist
扫描WiFi卡和网络,我得到所有需要的信息,无论我是作为普通用户还是根用户运行它。
附录# 2:代码已经升级,iw_get_range_info()
可以正常工作。
附录# 3:情况变得很奇怪;偶尔我也会成功:
static const UeTypeCurrentFrequencyChannel& UeNetworkManager::ueCurrentFrequencyChannel(const QString&) success - current channel: QPair(QVariant(double, 2.412e+09),QVariant(int, 1))
与iwlist scan output
:
wlan0 Scan completed :
Cell 01 - Address: 64:6E:EA:22:21:D4
Channel:1
Frequency:2.412 GHz (Channel 1)
经过一段时间的编程/测试应用程序,bug再次出现,但iwlist scan
仍然工作。我使用Ubuntu 16.04.1 LTS
内核Linux workstation 4.4.0-38-generic #57-Ubuntu SMP Tue Sep 6 15:42:33 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
。
是否可能问题与WiFi
卡Power Management
有关?
查看cfg80211_wext_giwfreq。这就是为什么如果你的 Wi-Fi
卡没有使用任何连接模式,你会得到当前通道的EINVAL
。iwlist
scan命令之所以有效,是因为Wi-Fi卡会在扫描时间切换到AP client mode
。
- 为什么 CRTP 模板C++给出无效参数错误?
- 为什么此字符串在传递到stoi时被视为无效参数
- boost::asio::async_write无效参数
- C ++回测问题:如何检查构造函数在假定失败时是否失败(给定输入的无效参数)
- 无效参数 C++ cygwin
- 套接字接受无效参数 (c++)
- 从带有 getline() 的文件读入一行上有多个信息得到无效参数错误
- 将无效参数传递给将无效参数视为致命的函数
- 如何避免字符串到整数转换情况下的无效参数异常
- 张量流 无效参数:In[0] 不是矩阵
- cudaFreeHost() 无效参数错误
- 未经治疗的例外,无效的参数传递给了一个认为无效参数作用的函数
- C++带有可变参数模板的无效参数
- std::find是否隐式修复无效参数
- 为什么这个程序告诉我传递了无效参数
- 在Win32中获取SetConsolecursorPosition函数的ERRORRORNO 87(无效参数)
- MSVCR120.dll的无效参数错误(在64位窗口中构建Tesseract Lib)
- 在C++中使用字符串类的 .substr 获取无效参数
- MySQL++ 无效参数错误
- 搜索无效参数