LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (https://www.linuxquestions.org/questions/linux-networking-3/)
-   -   /sys/class/net files and state of network interfaces (https://www.linuxquestions.org/questions/linux-networking-3/sys-class-net-files-and-state-of-network-interfaces-929247/)

turkejd 02-14-2012 04:13 AM

/sys/class/net files and state of network interfaces
 
Hi all,

I am writing a little C program that need to know the state of network interfaces.
I saw that in /sys/class/net directory and subdirectories there are a lot of useful files concerning network interfaces.

The problem is that I can't find the related documentation and sometimes I don't know what a file does represent (i.e. the file carrier).

What I need to know is the state of every network interface at a certain moment. I assume that there are three possible (big) states:
- down
- up but not connected
- up and connected

Can you help find a way to retrieve those informations?
I also appreciate simply some documentation or explanation on /sys/class/net files.

Thanks

smallpond 02-14-2012 03:19 PM

You want to read the file operstate. Its possible values are defined in RFC 2863.

turkejd 02-15-2012 03:25 AM

Quote:

Originally Posted by smallpond (Post 4602392)
You want to read the file operstate. Its possible values are defined in RFC 2863.

Hi, and thanks for the answer.

I had a look at that RFC, but it concerns SNMP and I didn't found anything about the file operstate.
I, instead, found somethin about ifOperStatus, but it does not seem the same exact thing.

I run a few tests and I came up with this result:

http://i.imgur.com/WOLv1.png

As you see, the operstate value could be used to see if an interface is connected (and ready to work) or not, except for the "eth0: up + cable + NOT connected" case.
I'd like to know if exists something that tell me universally if an interface is ready to use or not.

Cheers


All times are GMT -5. The time now is 03:35 AM.