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.
Share
You can look at
/sys/class/net/eth0/operstatewhere eth0 is your interface to see if it’s up.Look at
/sys/class/net/eth0/carrierto see if there is a carrier.Though I guess executing
ifconfigand friends will give you more compatibility to *BSDs.