Do you know a manner to access and manage in c interface eth0 without socket???
2 Answers
Yes, you can talk directly to the network interface driver through the appropriate ioctl
calls. Refer to your driver API reference for details. Some OS may provide access through their own API as well, see for example this question.
-
Ok but in the ioctl i send the file descriptor. Without socket which fd should i use? – user1307697 Apr 02 '12 at 09:52
-
@user1307697 you realize that noone can answer you without you telling us at least what operating system you're using, right? Try /dev/eth0, to begin with. – littleadv Apr 02 '12 at 09:54
-
@user1307697 then /dev/eth0 it is:-) Won't help you much without knowing how to talk to the driver though. – littleadv Apr 02 '12 at 10:00
-
excuse for my confusion information but i a novel user of programming in linux :) however thank you :) – user1307697 Apr 02 '12 at 10:09
-
Another problem, in /dev/ i don't have eth0...where are is it? – user1307697 Apr 02 '12 at 12:30
-
@user1307697 try /sys/class/net – littleadv Apr 02 '12 at 17:09
Why don't you do something along the lines of invoking the ifconfig command on the shell within your C code:
system("ifconfig eth0 ...");
This will eliminate the need to have a file descriptor but allows you to manage the device using the command. Do a man ifconfig to see how to structure your ifconfig request to manage whatever you need to do with the interface.
If you need to go lower level than that, then you could simply open up a raw socket...assign the index of the Ethernet device you want to manipulate...and then use your ioctl()'s to configure as required:
if ((fd = socket(AF_PACKET, SOCK_RAW, IPPROTO_RAW)) == -1) {
perror("socket");
}
struct ifreq req;
strncpy(req.ifr_name, "eth0", IFNAMSIZ-1);
if (ioctl(fd, SIOCGIFINDEX, &ifreq) < 0)
perror("SIOCGIFINDEX");
Then you have your handle to eth0...

- 81
- 2
-
Agreed...but I don't understand the aversion to using file descriptors here...anyways the first snippet of code (sans socket implementation) could be all he needs to do. – Sean Flynn Apr 02 '12 at 17:52
-
Agreed, the OP doesn't seem to want to share enough information to really answer the question... – littleadv Apr 02 '12 at 17:55
-
i want create a gateway for permitt to interact a 6lowpan network and bluetooth network. For this project i must access to eth0 to lower level. I know the solution with raw socket but i ask another solution if exist. Excusme for my confusion information! – user1307697 Apr 03 '12 at 11:39