LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-23-2008, 12:22 AM   #1
frostecheg
LQ Newbie
 
Registered: Apr 2008
Posts: 8

Rep: Reputation: 0
discovering eth interface speed?


Hi, i need my program to know the speed of the eth0 interface.
Currently im parsing answer of
dmesg | grep "eth0: Speed"
But this is not the best solution possible.
Is there any ioctl or some kernel api for this?
PS. I am talking about embedded linux, but i dont think there is much difference.. Except i dont have the mii-tools and such
 
Old 04-23-2008, 02:20 AM   #2
salasi
Senior Member
 
Registered: Jul 2007
Location: Directly above centre of the earth, UK
Distribution: SuSE, plus some hopping
Posts: 4,062

Rep: Reputation: 893Reputation: 893Reputation: 893Reputation: 893Reputation: 893Reputation: 893Reputation: 893
Quote:
Originally Posted by frostecheg View Post
Hi, i need my program to know the speed of the eth0 interface.
Currently im parsing answer of
dmesg | grep "eth0: Speed"
But this is not the best solution possible.
Is there any ioctl or some kernel api for this?
PS. I am talking about embedded linux, but i dont think there is much difference.. Except i dont have the mii-tools and such
What do you mean by speed? do you mean the nominal bit rate of the interface card? do you mean the maximum data throughput at the lowest level in the 'pyramid'? do you mean actual throughut at the lowest level? do you mean actual throughput at some higher (e.g., application) level?

These will be quite different numbers and I'm not sure what you are trying to measure.
 
Old 04-23-2008, 02:35 AM   #3
frostecheg
LQ Newbie
 
Registered: Apr 2008
Posts: 8

Original Poster
Rep: Reputation: 0
I mean 10/100/1000MBps
 
Old 04-23-2008, 03:55 AM   #4
tanveer
Member
 
Registered: Feb 2004
Location: e@rth
Distribution: RHEL-3/4/5,Gloria,opensolaris
Posts: 525

Rep: Reputation: 37
# mii-tool
 
Old 04-23-2008, 04:00 AM   #5
frostecheg
LQ Newbie
 
Registered: Apr 2008
Posts: 8

Original Poster
Rep: Reputation: 0
I have specifically written,that it is not an option.
Unless you can describe me,how mii-tool works
 
Old 04-23-2008, 04:49 AM   #6
tanveer
Member
 
Registered: Feb 2004
Location: e@rth
Distribution: RHEL-3/4/5,Gloria,opensolaris
Posts: 525

Rep: Reputation: 37
Quote:
PS. I am talking about embedded linux, but i dont think there is much difference.. Except i dont have the mii-tools and such
oops sorry, didn't notice that. Limitation of my Memory now
 
Old 04-23-2008, 08:42 AM   #7
this213
Member
 
Registered: Dec 2001
Location: ./
Distribution: Fedora, CentOS, RHEL, Gentoo
Posts: 167

Rep: Reputation: 34
Maybe this will help you?
/sbin/ethtool -g eth0
 
Old 04-24-2008, 12:29 AM   #8
frostecheg
LQ Newbie
 
Registered: Apr 2008
Posts: 8

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by this213 View Post
Maybe this will help you?
/sbin/ethtool -g eth0
Indeed, it gives me information to parse, but it seems more reliable ,that dmesg.

PS. i will use
/sbin/ethtool eth0
without the -g , the "-g" gives
something like
Quote:
Current hardware settings:
RX: 256
RX Mini: 256
RX Jumbo: 256
TX: 256
Thank you alot :-)

PS. I still would like to know,whether there is some programmatic way to do this. Like - how ethtool knows the speed?

Last edited by frostecheg; 04-24-2008 at 12:58 AM.
 
Old 04-24-2008, 01:19 AM   #9
frostecheg
LQ Newbie
 
Registered: Apr 2008
Posts: 8

Original Poster
Rep: Reputation: 0
Ok,as ethtool's source code implies, it uses
SIOCETHTOOL ioctl call to get the data.


Quote:
/* Open control socket. */
fd = socket(AF_INET, SOCK_DGRAM, 0);
if (fd < 0) {
perror("Cannot get control socket");
return 70;
}
...
...
ifr->ifr_data = (caddr_t)&ecmd;
err = ioctl(fd, SIOCETHTOOL, ifr);
..
and later on some more parsing.
But google does not show me this call description.
Any chance one has it,or i have to dig through ethtool code?
 
Old 04-24-2008, 02:33 AM   #10
muthu@sanatdata.net
LQ Newbie
 
Registered: Jan 2008
Posts: 2

Rep: Reputation: 0
ethtool eth0 | grep Speed | awk '{print $2}';
use this it will work...........
 
  


Reply


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
Identify eth interface used by each pppoe link noisebleed Linux - Networking 6 04-19-2007 04:59 AM
Packets just don't reach eth interface g00nie Linux - Networking 2 02-17-2006 09:11 AM
v-noob: connecting two pc's through eth interface garba Linux - Networking 3 06-14-2005 07:12 AM
How to bring eth interface up correctly? cold Linux - Networking 2 06-18-2004 02:40 AM
multiple ip address for single eth interface blackhound Linux - Networking 2 02-25-2004 06:02 AM


All times are GMT -5. The time now is 11:13 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration