(C,Linux)的了解,如果一个网络接口是无线或有线 [英] (C, Linux) Knowing if a network interface is wireless or wired

查看:1157
本文介绍了(C,Linux)的了解,如果一个网络接口是无线或有线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有两个分开的部分的程序:其中一个应执行时所述网络接口是无线LAN而另一个时,它的一个有线LAN连接。我怎么能知道我的节目里面?我应该使用什么函数来获得这些信息?

I have a program that has two separate sections: one of them should be executed when the network interface is wireless LAN and the other one when it's a wired LAN connection. How can I know that inside of my program? What function should I use to get that information?

推荐答案

您可以在命令行中使用iwconfig命令:

You can use the iwconfig command from the command line:

$ iwconfig
lo        no wireless extensions.
eth0      no wireless extensions.

如果您需要使用它从C,如上@不透明的链接解释说,获得源代码,或者使用strace的,看看哪个的ioctl(),你需要使用:

If you need to use it from C, as @opaque's link above explains, get the sources or use strace to see which ioctls() you need to use:

ioctl(3, SIOCGIWNAME, 0x7fff82c0d040)   = -1 EOPNOTSUPP (Operation not supported)
ioctl(3, SIOCGIFFLAGS, {ifr_name="lo", ifr_flags=IFF_UP|IFF_LOOPBACK|IFF_RUNNING}) = 0
write(2, "lo        no wireless extensions"..., 35lo        no wireless extensions.

) = 35
ioctl(3, SIOCGIWNAME, 0x7fff82c0d040)   = -1 EOPNOTSUPP (Operation not supported)
ioctl(3, SIOCGIFFLAGS, {ifr_name="eth0", ifr_flags=IFF_UP|IFF_BROADCAST|IFF_RUNNING|IFF_MULTICAST}) = 0
write(2, "eth0      no wireless extensions"..., 35eth0      no wireless extensions.

) = 35

请参阅 SIOCGIWNAME使用

#define SIOCGIWNAME 0x8B01 /* get name == wireless protocol */
/* SIOCGIWNAME is used to verify the presence of Wireless Extensions.
* Common values : "IEEE 802.11-DS", "IEEE 802.11-FH", "IEEE 802.11b"...

这篇关于(C,Linux)的了解,如果一个网络接口是无线或有线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆