1

1. I am testing with a rooted nexus 5 operating on lollipop 5.1.

2. This is all with no wifi connection.

I am trying to send UDP packets between a PC and an android device with an otg cable and ethernet dongle. When connected the PC thinks the android is an unidentified network(No internet access) and the android recognizes the device as eth0 with an IP of 0.0.0.0.

eth0   UP   0.0.0.0

I add an IP to the eth0 by running the following unix script:

#!/bin/sh
netcfg eth0 up
ifconfig eth0 192.168.1.200 netmask 255.255.255.0
route add default gw 192.168.1.1 dev eth0
ping -c 1 192.168.1.1

After running the script eth0 appears in the command line as:

eth0   UP   192.168.1.200

I am using wireshark to track packets and when I try to open an interface between the PC and android I get an error as follows:

(Error opening adapter: The system cannot find the device specified. (20)).

Also, when I try to PING the PC from the android I get 100% packet lost.

So it seems like I don't have a connection between PC and android. Any input on the topic would be very helpful.

  • Are you connecting the N5 and PC directly or via a router? IP information about the PC would also be helpful, like its IP, netmask, and whether it's DHCP or static. – Mr. Buster May 22 '15 at 17:11
  • N5 and PC are connected directly. End game is to use it as a hardware interface, no different then say I2C or RX. DHCP is enabled, IP 169.254.57.56, Netmask 255.255.255.0 – Cody Emerson May 22 '15 at 17:32
  • I used 169.254.57.55 in the script. – Cody Emerson May 22 '15 at 17:36
  • Makes sense, though if you're looking to connect the two via IP networking they'll need to be in the same subnet. Your PC is self-assigning an IP address because it can't find a DHCP server. Try statically assigning your PC 192.168.1.1 with the same 255.255.255.0 subnet. – Mr. Buster May 22 '15 at 17:50
  • Yes! Just had to set IPs and default gateways correctly. Thanks for the help, I don't have much of a networking background. More of a hardware guy. – Cody Emerson May 22 '15 at 18:11
0

[From Comments:] If you're looking to connect the two via IP networking they'll need to be in the same subnet. Your PC is self-assigning an IP address because it can't find a DHCP server. Try statically assigning your PC 192.168.1.1 with the same 255.255.255.0 subnet.

0

I think reverse tethering would solve your problem.

Android reverse tethering steps:

Note: Works only in a rooted Android phone.

  1. Connect Android device via USB.
  2. Enable USB tethering. To do so, go to Settings → More... → Tethering & mobile hotspot → Usb tethering.

  3. On host machine, type:

    $ ifconfig usb0 10.42.0.1 netmask 255.255.255.0 
    $ echo 1 > /proc/sys/net/ipv4/ip_forward 
    

    Command for sudo will be:

    $ sudo 'echo 1 > /proc/sys/net/ipv4/ip_forward' 
    
  4. On Android device (for this step you must install ADB on host PC), type:

    $ adb shell 
    $ su 
    $ netcfg rndis0 dhcp
    

    If it does'nt get the IP address then assign it manually:

    $ netcfg rndis0 10.42.0.2 netmask 255.255.255.0 
    $ route add default gw 10.42.0.1 dev rndis0 
    

Now internet would be working in the Android phone.

To check , try the command ping www.google.com.

It works for me.

  • Android will not give the option to turn USB tethering on with the Ethernet dongle/otg cable combinations i.e it's not a USB type connection. – Cody Emerson May 22 '15 at 15:31
  • I tried with Rooted phone & PC with Ethernet connection & it work for me fine. – DreamCoder May 22 '15 at 15:39
  • You are using an otg with an ethernet adapter? Here's an example plugable.com/products/usb2-otge100. And there will be no internet connection. UDP is being used as a hardware interface. – Cody Emerson May 22 '15 at 16:18
  • I connected my phone with PC using usb – DreamCoder May 22 '15 at 16:19
  • About 4., should it not be "On PC" because you run ADB shell from the PC. – Firelord May 22 '15 at 20:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.