-2

Do you know a manner to access and manage in c interface eth0 without socket???

Gottox
  • 682
  • 6
  • 15
user1307697
  • 15
  • 1
  • 10

2 Answers2

0

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.

Community
  • 1
  • 1
littleadv
  • 20,100
  • 2
  • 36
  • 50
0

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

Sean Flynn
  • 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