LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Kernel (https://www.linuxquestions.org/questions/linux-kernel-70/)
-   -   accessing data structure of eth0 from user space???? (https://www.linuxquestions.org/questions/linux-kernel-70/accessing-data-structure-of-eth0-from-user-space-526251/)

raklo 02-06-2007 09:53 PM

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

macemoneta 02-06-2007 10:15 PM

It depends on the data you want. Some of it is accessible through the /proc and /sys pseudo-filesystems.

raklo 02-06-2007 10:58 PM

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

macemoneta 02-06-2007 11:08 PM

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.

raklo 02-06-2007 11:31 PM

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

macemoneta 02-06-2007 11:46 PM

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.

raklo 02-07-2007 12:14 AM

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

nx5000 02-07-2007 07:50 AM

Try digging around this:
http://linux.about.com/library/cmd/b..._netdevice.htm

raklo 02-07-2007 11:02 PM

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??

sundialsvcs 02-08-2007 08:17 PM

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."

nx5000 02-09-2007 04:12 AM

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.


All times are GMT -5. The time now is 10:17 PM.