在Linux上:如何以编程方式确定是否启用并插入了NIC接口? [英] On Linux: how can I programmatically determine if a NIC interface is enabled and plugged in?

查看:73
本文介绍了在Linux上:如何以编程方式确定是否启用并插入了NIC接口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想确定网卡是否已启用,启动和插入.基本上,我想知道网卡是否可以工作.我需要使用C ++程序获取此信息,并且想在网络无法正常工作时显示错误消息.如果可能的话,我想避免使用shell命令来确定此信息.

I want to determine if a network card is enabled, up, and plugged in. Basically, I want to know if the network card will work. I need this information from with a C++ program, and would like to display an error message when the network isn't working properly. If possible I would like to avoid using shell commands to determine this information.

推荐答案

您可以查看/sys/class/net/eth0/operstate,其中eth0是您的界面,以查看其是否可用.

You can look at /sys/class/net/eth0/operstate where eth0 is your interface to see if it's up.

查看/sys/class/net/eth0/carrier看看是否有承运人.

Look at /sys/class/net/eth0/carrier to see if there is a carrier.

尽管我想执行ifconfig,并且朋友会给您* BSD的更多兼容性.

Though I guess executing ifconfig and friends will give you more compatibility to *BSDs.

这篇关于在Linux上:如何以编程方式确定是否启用并插入了NIC接口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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