哪个 c/c++ 库可用于处理 linux 的 wifi 连接?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8661474/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 03:51:01  来源:igfitidea点击:

which c/c++ library can be used for handling wifi connections for linux?

c++clinuxwifi

提问by Ashish

I want to implement WiFi manager program which should handle the following.

我想实现应处理以下内容的 WiFi 管理器程序。

  • notification on wi-fi access point has come or gone
  • provide information of available wifi access point
  • connect/disconnect with a given wi-fi access point
  • wi-fi 接入点的通知已经出现或消失
  • 提供可用 wifi 接入点的信息
  • 连接/断开与给定的 wi-fi 接入点

Which is the recommended C/C++ WiFi library for Linux to achieve this?

哪个是推荐的用于 Linux 的 C/C++ WiFi 库来实现这一点?

回答by fge

That would be wireless-tools

那将是无线工具

回答by BRPocock

On Fedora (at least), the preferred way to interact with NetworkManager is via DBus.

在 Fedora 上(至少),与 NetworkManager 交互的首选方式是通过 DBus。

While wireless-tools and the like will work — even direct kernel calls, if you must — there are a couple of problems:

虽然无线工具等可以工作——即使是直接的内核调用,如果你必须——但有几个问题:

  • You'll probably need superuser privileges
  • NetworkManager will probably have a panic attack and get into fights with you, unless you stop its service
  • The user's normal networking controls (e.g. desktop tray icons) are almost certainly configured to use NetworkManager.
  • 您可能需要超级用户权限
  • 除非您停止其服务,否则 NetworkManager 可能会惊慌失措并与您打架
  • 用户的正常网络控制(例如桌面托盘图标)几乎可以肯定配置为使用 NetworkManager。

You can send and receive DBus messages for all the tasks you mentioned, for WiFi as well as arbitrary other types of network interfaces. The API is published here, for version 0.8.

您可以为您提到的所有任务、WiFi 以及任意其他类型的网络接口发送和接收 DBus 消息。API在此处发布,适用于 0.8 版

For newer operating systems, there are apparently changes in the API, with a migration guide.

对于较新的操作系统,API有明显的变化,带有迁移指南

Their wikishould be really helpful.

他们的维基应该真的很有帮助。

I know both Fedora and Ubuntu use NetworkManager by default; I believe many other systems do, as well, but don't have an exhaustive list.

我知道 Fedora 和 Ubuntu 默认都使用 NetworkManager;我相信许多其他系统也这样做,但没有详尽的列表。

Of course, if you're using an embedded system, custom distribution, or something, then your mileage may vary.

当然,如果您使用的是嵌入式系统、自定义发行版或其他东西,那么您的里程可能会有所不同。

回答by asantacreu

I would recommend using directly the NetworkManager Library.

我建议直接使用NetworkManager Library

You can use low-level D-Bus library or libnm-glib library, that makes communication easier: example add connection glib

您可以使用低级 D-Bus 库或 libnm-glib 库,这使通信更容易:例如添加连接 glib

For more info, you can take a look into the code of the command line client nmcli.

有关更多信息,您可以查看命令行客户端nmcli的代码。