LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 02-06-2007, 09:53 PM   #1
raklo
Member
 
Registered: Apr 2006
Posts: 143

Rep: Reputation: 15
accessing data structure of eth0 from user space????


hi all,
i want to access the data structure corresponding to eth0 from user space,is it possible to do it thru a user space program??
i know i can do it thru struct net_device,in <linux/netdevice.h>,but this is possible only in kernel space.
can i do the same thing thru a user space program???

any input is appreciated
 
Old 02-06-2007, 10:15 PM   #2
macemoneta
Senior Member
 
Registered: Jan 2005
Location: Manalapan, NJ
Distribution: Fedora x86 and x86_64, Debian PPC and ARM, Android
Posts: 4,593
Blog Entries: 2

Rep: Reputation: 344Reputation: 344Reputation: 344Reputation: 344
It depends on the data you want. Some of it is accessible through the /proc and /sys pseudo-filesystems.
 
Old 02-06-2007, 10:58 PM   #3
raklo
Member
 
Registered: Apr 2006
Posts: 143

Original Poster
Rep: Reputation: 15
but i want to access the data structure(to be specific,the pointer to structure that contains details about eth0)
i dont want to write to the datastructure,i just want to display it.
but ONLY thru data structures.
thanx for reply
 
Old 02-06-2007, 11:08 PM   #4
macemoneta
Senior Member
 
Registered: Jan 2005
Location: Manalapan, NJ
Distribution: Fedora x86 and x86_64, Debian PPC and ARM, Android
Posts: 4,593
Blog Entries: 2

Rep: Reputation: 344Reputation: 344Reputation: 344Reputation: 344
A text file, that contains the information you want, is a data structure (though a simple one). On Linux, the /proc and /sys filesystems are the userland interface to system data.
 
Old 02-06-2007, 11:31 PM   #5
raklo
Member
 
Registered: Apr 2006
Posts: 143

Original Poster
Rep: Reputation: 15
u mst be knowing that header file
#include <linux/netdevice.h> contains structure definition
struct net_device {
...
...
};
the pointer to structure eth0 is of type ' struct net_device'
i want to access this data structure from a user space program.
i DONT want to use data in /proc or /sys.
i just wanna know whether this is possible from a user space program??
i dont want to write a module(a kernel space module) to do taht work.

thanx a lot for replies
 
Old 02-06-2007, 11:46 PM   #6
macemoneta
Senior Member
 
Registered: Jan 2005
Location: Manalapan, NJ
Distribution: Fedora x86 and x86_64, Debian PPC and ARM, Android
Posts: 4,593
Blog Entries: 2

Rep: Reputation: 344Reputation: 344Reputation: 344Reputation: 344
You'll write a kernel module, but you won't read records from the /sys/class/net/eth0/ hierarchy? I think you need to examine your priorities.
 
Old 02-07-2007, 12:14 AM   #7
raklo
Member
 
Registered: Apr 2006
Posts: 143

Original Poster
Rep: Reputation: 15
i m using a filesystem created by buildroot,which does nt have sysfs and /sys directory,so i wanna do it thru a user space program,i.e display the details of eth0.
i dont wanna use /proc details.
i hope u can get wot i wanna do
 
Old 02-07-2007, 07:50 AM   #8
nx5000
Senior Member
 
Registered: Sep 2005
Location: Out
Posts: 3,307

Rep: Reputation: 57
Try digging around this:
http://linux.about.com/library/cmd/b..._netdevice.htm
 
Old 02-07-2007, 11:02 PM   #9
raklo
Member
 
Registered: Apr 2006
Posts: 143

Original Poster
Rep: Reputation: 15
the article was really good,but i cdnt get from where(from which user space api)will i be able to access structure corresponding to eth0 interface??
 
Old 02-08-2007, 08:17 PM   #10
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3939Reputation: 3939Reputation: 3939Reputation: 3939Reputation: 3939Reputation: 3939Reputation: 3939Reputation: 3939Reputation: 3939Reputation: 3939Reputation: 3939
Basically, you can't.

Not only is that area of memory off-limits to you, but there are timing-related issues as well. Your program executes in a virtual storage environment; hardware does not.

So you have to make a system-call that will copy what you want to know into a buffer in userland. By far the easiest way to do that is "/proc."
 
Old 02-09-2007, 04:12 AM   #11
nx5000
Senior Member
 
Registered: Sep 2005
Location: Out
Posts: 3,307

Rep: Reputation: 57
Ah now I get what you mean by structure (also have reread your posts).
You want access to the complete kernel object?
Well, its going be hard work eh!

The kernel space is separated from user space. Currently the kernel space provides "statistical output" to user space through proc filesystem. It also provides input from api like the one I mentionned.

But you can't easily access directly a kernel object from userspace (hence the procfs and sysfs philosophy for non-kernel developpers)
Either you modify your kernel by recoding the outputed information in procfs or you develop a kernel module (its harder that what you think because of what sundialsvcs said, concurrency, timing, sleeping ..) that will put a lock on the netdevice (or device list), read its fields and export them to userspace memory.

In general the ioctl gateway have sufficient information.
 
  


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
c++ data structure libraries kpachopoulos Programming 2 01-16-2007 04:22 PM
How to share data b/w user space and kernel space nandac Linux - Kernel 1 11-28-2006 10:15 PM
accessing tty_struct structure of a terminal(say tty1) raklo Programming 0 08-21-2006 03:33 AM
Data structure trie spank Programming 7 05-21-2006 07:21 AM
error in accessing structure variable in kernel modules dypgrp Programming 3 01-17-2005 07:42 AM

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

All times are GMT -5. The time now is 08:44 PM.

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