LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 01-24-2014, 10:55 AM   #1
RET80
LQ Newbie
 
Registered: Dec 2013
Posts: 13

Rep: Reputation: Disabled
ifconfig.c -- parsing a specific piece of data


Hello all,

So I've been trying to make an tiny linux application that parses the RX bytes and TX bytes of an interface.

So as of right now my small application calls ifconfig every 0.5 seconds and just parses ASCII data, which is slow and costly.

So I decided to look up ifconfig.c's source to see where and how the interfaces are being brought up and how the data is being gathered, however I am having a difficult time doing so or where to look.

In ifconfig, there is a function called void printall(const *ifname) however I'm not seeing where exactly those Send/Receive bytes are being put together from? is it from the structs? if so which one and which variables from the struct?

This one is a toughy guys! Please help, I've been scratching my head with this one.
 
Old 01-24-2014, 12:52 PM   #2
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: Fedora
Posts: 4,140

Rep: Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263
Most utilities read kernel driver values through the /sys virtual file system. The files you want to read in this case are:

Code:
 cat /sys/class/net/eth0/statistics/tx_bytes
 cat /sys/class/net/eth0/statistics/rx_bytes
Technically, you should determine where sysfs is mounted by parsing /proc/mounts but that means you need to know where proc is mounted, so I usually don't bother.
 
1 members found this post helpful.
Old 01-24-2014, 01:02 PM   #3
RET80
LQ Newbie
 
Registered: Dec 2013
Posts: 13

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by smallpond View Post
Most utilities read kernel driver values through the /sys virtual file system. The files you want to read in this case are:

Code:
 cat /sys/class/net/eth0/statistics/tx_bytes
 cat /sys/class/net/eth0/statistics/rx_bytes
Technically, you should determine where sysfs is mounted by parsing /proc/mounts but that means you need to know where proc is mounted, so I usually don't bother.
Holy cow, I can't explain how much this actually blew my mind! Thank you SO much! This just saved a lot of code traversal! I would like to know how you came about this answer as I'm still understanding the Linux filesystem architecture.
 
Old 01-24-2014, 02:01 PM   #4
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: Fedora
Posts: 4,140

Rep: Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263
One of the original ideas of Unix is that everything is a file accessible through a single hierarchical namespace.
/sys extends that for kernel data. /proc for process information.
Look around in /proc and you will find everything the ps command returns.
Look in the Documentation directory of the kernel source and you will find lots of things to "blow your mind".

http://lxr.free-electrons.com/source/Documentation/
 
1 members found this post helpful.
  


Reply



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
what's a good piece of software to extract data from xml files? clemensclemens Linux - Newbie 3 03-05-2013 10:53 AM
Quiz: Why did gzip, bzip2 and lzma fail on this piece of data? What is it? irmin General 7 07-20-2010 02:06 PM
building shell command piece by piece aunquarra Linux - General 7 05-02-2006 06:43 AM
How do I cut out a specific piece of a html page (using sed/awk or similar)? bomix Linux - General 2 10-08-2005 04:30 PM
Annoying network card piece of data Musikolo Linux - Networking 5 07-19-2004 01:14 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 06:00 AM.

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