Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Networking
User Name
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.


  Search this Thread
Old 02-14-2012, 04:13 AM   #1
LQ Newbie
Registered: Jan 2012
Posts: 10

Rep: Reputation: Disabled
/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.

Old 02-14-2012, 03:19 PM   #2
Senior Member
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: CentOS 6 & 7
Posts: 3,209

Rep: Reputation: 871Reputation: 871Reputation: 871Reputation: 871Reputation: 871Reputation: 871Reputation: 871
You want to read the file operstate. Its possible values are defined in RFC 2863.
Old 02-15-2012, 03:25 AM   #3
LQ Newbie
Registered: Jan 2012
Posts: 10

Original Poster
Rep: Reputation: Disabled
Originally Posted by smallpond View Post
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:

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.



Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
reference for object types for /sys/class/net objects? joeldavis Linux - Networking 1 11-06-2011 11:45 AM
sys/class/net/ethx/type What is it? tank junior Linux - Newbie 1 05-03-2011 08:23 PM
/sys/class/net/ Is this is the correct place for eth info tank junior Linux - Newbie 1 04-14-2011 02:58 AM
Giving user access to files in /sys/class/ subdirectory and /dev/video0 DiBosco Programming 1 12-01-2008 03:11 AM
Blank /sys/power/state file dizzi Slackware 12 11-20-2007 01:17 PM > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 04:55 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration