当我意识到它已被贬低并且大多数应用程序使用 nl80211 时,我开始使用 iwconfig/ioctl 编写代码来处理 wifi 卡。我开始阅读它的源代码,但没有文档,代码有点复杂。如何使用 nl80211 或 libnl 进行扫描、关闭/打开、设置卡模式等简单操作?这就是我从 iw 开始的:
void set_card_mode(MODE mode, std::string ifname)
{
int skfd = iw_sockets_open();
struct iwreq wrq;
wrq.u.mode = static_cast<unsigned int>(mode);
power_interface(ifname, false);
if(iw_set_ext(skfd, ifname.c_str(), SIOCSIWMODE, &wrq) < 0)
throw std::runtime_error("Can set card mode");
}
MODE get_card_mode(std::string ifname)
{
int skfd = iw_sockets_open();
struct iwreq wrq;
if (iw_get_ext (skfd, ifname.c_str(), SIOCGIWMODE, &wrq) >= 0)
{
return static_cast<MODE>(wrq.u.mode);
}
}
是否有任何等效的 iw_get_ext 来设置/获取 wifi 接口或任何具有“set_mode”或“power_off”等简单功能的 api?