0

i have two network card on my device.user can insert cable to anyone of network card,so i want to know which network card user is used.because i only know eth0 or eth1 is used,i can set it.

    DevInfo.setGateWay("192.168.85.255");
    DevInfo.setIfName("eth0");
    DevInfo.setIpAddress("192.168.84.134");
    DevInfo.setNetMask("255.255.254.0");

you can see the above code,i Hard coded using eth0。 is there a method to check user use eth0 or eth1?

edit:use mean,user insert the cable,in other words, how to know which network card is insert the cable. i can modify the firmware,but i donot know where is code i can modify.

pengwang
  • 19,536
  • 34
  • 119
  • 168

1 Answers1

0

I don't think so, because to query the physical state of the network card you'd need to access operating system interfaces, and I don't think they are visible to the Android Java API. But if you really need it, and especially if you target a small set of devices, you may be able to develop the native parts, possibly by modifying the firmware.

Note that the question itself, "is there a method to check user use eth0 or eth1" is too vague: user may use both eth0 and eth1, or neither. The names of the interfaces may change. And what does use mean? The routing table of the device may be configured so that both are used to access different networks. I guess you are interested in the iface used to connect to the default gateway, but this is just an assumption and you should really clarify what you need to understand:

  • if what you want to do can be done
  • if it can be done with a simple app

Take a look at this question for how to query the status of network cards (basically by polling /sys/class/net, but I don't know if it's working on your target devices) and how to intercept the plug/unplug event (by using rtnetlink and udev, again not sure it will work on your devices). I just want to stress once again that knowing the physical state of the cards may not be enough to fulfil your high-level requirements

Community
  • 1
  • 1
Raffaele
  • 20,627
  • 6
  • 47
  • 86