Is it possible to access a device (e.g. a Sonos box) from an emulated android phone via network bridge?
added tap0 and br0 to my Network configuration
from here:
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp2s0f0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq master br0 state UP group default qlen 1000
link/ether dc:0e:a1:29:5a:04 brd ff:ff:ff:ff:ff:ff
inet6 fe80::de0e:a1ff:fe29:5a04/64 scope link
valid_lft forever preferred_lft forever
3: tap0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast master br0 state DOWN group default qlen 1000
link/ether 92:24:b9:90:cc:52 brd ff:ff:ff:ff:ff:ff
4: br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
link/ether 0a:f8:c3:53:5b:d2 brd ff:ff:ff:ff:ff:ff
inet 192.168.100.14/24 brd 192.168.100.255 scope global dynamic br0
valid_lft 7183sec preferred_lft 7183sec
inet6 fe80::8f8:c3ff:fe53:5bd2/64 scope link
valid_lft forever preferred_lft forever
started avd with:
./emulator
-avd Nexus_5_API_26
-verbose
-qemu
-device virtio-net-pci,netdev=hn0,mac=52:55:00:d1:55:51
-netdev tap,id=hn0,ifname=tap0,script=no,downscript=no
Network configuration from emulated Device :
$ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/ether 52:55:00:d1:55:51 brd ff:ff:ff:ff:ff:ff
4: wlan0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/ether 02:00:00:44:55:66 brd ff:ff:ff:ff:ff:ff
6: hwsim0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default
link/ieee802.11/radiotap 12:00:00:00:00:00 brd ff:ff:ff:ff:ff:ff
7: sit0#NONE: mtu 1480 qdisc noop state DOWN group default
link/sit 0.0.0.0 brd 0.0.0.0
9: radio0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 0e:86:a3:d8:13:47 brd ff:ff:ff:ff:ff:ff
inet 192.168.200.2/24 brd 192.168.200.255 scope global
radio0
valid_lft forever preferred_lft forever
inet6 fec0::6d8a:a6a1:3127:532c/64 scope site temporary dynamic
valid_lft 86213sec preferred_lft 14213sec
inet6 fec0::c86:a3ff:fed8:1347/64 scope site mngtmpaddr dynamic
valid_lft 86213sec preferred_lft 14213sec
inet6 fe80::c86:a3ff:fed8:1347/64 scope link
valid_lft forever preferred_lft forever
status of emulated Device:
Device shows IP Address from radio0: 192.168.200.2
eth1 shows the MAC Address (52:55:00:d1:55:51) i gave with the arguments
Is there a change to change the IP-range to 192.168.100.x?
Related
I have a STB 7445 device to which our wlan chip is connected via usb.
After loading driver and firmware for wlan0 interface, IP address is assigned to wlan0 interface.
IP Address:
# ifconfig wlan0 192.168.1.2
Thereafter I am running loopback throughput test on a dummy address added in arp entry.
ARP Entry:
# /system/xbin/busybox/arp -s 192.168.1.4 11:22:33:44:55:66
Run iperf to measure UDP TPUT:
# iperf -c 192.168.1.4 -i1 -w2M -b1000M -t 60
.
.
[ 3] 4.0- 5.0 sec 32.5 MBytes 273 Mbits/sec
[ ID] Interval Transfer Bandwidth
[ 3] 59.0-60.0 sec 32.5 MBytes 273 Mbits/sec
[ ID] Interval Transfer Bandwidth
[ 3] 0.0-60.0 sec 1.90 GBytes 273 Mbits/sec
[ 3] Sent 1390851 datagrams
[ 3] WARNING: did not receive ack of last datagram after 10 tries.
root#bcm_platform:/system/bin/amar/43569a2 #
I am getting throughput of only 273 Mbps, whereas the bus speed is 480 Mbps.
usb bus speed:
#cat /sys/bus/usb/devices/usb1/speed
480
The ip stack will notice that the destination is the same machine, so no packets are sent out to the hardware. You are just measureing the software performance of the linux IP stack, and your CPU is a bit slow.
USB 2.0 high speed is 480 MBit/s, but it cannot send and receive at the same time. That means if you send packets to hardware and receive them again, you cannot exeed 240 MBit/s - in practice even lower since there will be some overhead.
I hooked into the /system/bin/netd binary to log all of the commands that are sent by the Android framework when it puts up a hotspot via clicking buttons in the system settings menu. (I needed to be able to bring up the hotspot up from shell & ADB without bringing up the settings menu.)
This returned all of the commands that are used to put up the hotspot.
interface clearaddrs wlan0
interface ipv6 wlan0 disable
resolver flushif wlan0
bandwidth setglobalalert 2097152
bandwidth setglobalalert 2097152
softap fwreload wlan0 AP
softap set wlan0 asdfa wpa2-psk 12345678
softap startap
interface getcfg wlan0
interface setcfg wlan0 192.168.43.1 24 running multicast broadcast up
tether interface add wlan0
ipfwd enable
tether start 192.168.42.2 192.168.42.254 192.168.43.2 192.168.43.254 192.168.44.2 192.168.44.254 192.168.45.2 192.168.45.254 192.168.46.2 192.168.46.254 192.168.47.2 192.168.47.254 192.168.48.2 192.168.48.254
tether dns set 8.8.8.8 8.8.4.4
Seems OK.
When I issue those commands through /system/bin/ndc from shell, nothing returns an error and claims that it succeeded. Great. Fantastic. Wonderful.
200 0 Interface IP addresses cleared
200 0 IPv6 state changed
200 0 Resolver command succeeded
200 0 Bandwidth command succeeeded
200 0 Bandwidth command succeeeded
200 0 Softap operation succeeded
200 0 Softap operation succeeded
600 Iface linkstate wlan0 down
600 Iface linkstate wlan0 down
200 0 Softap operation succeeded
213 0 44:33:4c:3d:98:dc 0.0.0.0 0 down broadcast multicast
200 0 Interface configuration set
200 0 Tether operation succeeded
200 0 ipfwd operation succeeded
200 0 Tether operation succeeded
200 0 Tether operation succeeded
Super! Except for the little trivial fact that the hotspot cannot be seen afterwards and it doesn't even kick me off the wireless connection, so obviously I am missing something.
It might be useful to note that in Android 4.1.1 the following works (as expected), but in 4.2.2 it does not; I have tried endless combinations of the logged commands and the 4.1.1 commands to very little avail.
softap stopap
softap stop wlan0
softap fwreload ap0 AP
softap start wlan0
softap set wlan0 ap0 SSID wpa2-psk 12345678 11 0 8
softap startap
interface setcfg ap0 192.168.2.254 255.255.255.0 up
Here is what happens when the hotspot is taken down via the system settings menu, maybe it will be helpful:
interface getcfg wlan0
interface setcfg wlan0 0.0.0.0 0 running multicast broadcast up
tether interface remove wlan0
tether stop
ipfwd disable
softap stopap
softap fwreload wlan0 STA
softap fwreload wlan0 STA
interface getcfg wlan0
interface setcfg wlan0 0.0.0.0 0 multicast broadcast down
interface ipv6privacyextensions wlan0 enable
interface getcfg p2p0
interface setcfg p2p0 0.0.0.0 0 multicast broadcast up
interface ipv6 wlan0 enable
interface route add wlan0 default 192.168.2.254 32 0.0.0.0
interface route add wlan0 default 0.0.0.0 0 192.168.2.254
resolver flushif wlan0
interface route add wlan0 default 192.168.2.254 32 0.0.0.0
bandwidth setglobalalert 2097152
interface route add wlan0 default 0.0.0.0 0 192.168.2.254
bandwidth setglobalalert 2097152
This is what is logged during system startup before any user input is possible:
interface list
interface getcfg eth0
interface ipv6 wlan0 disable
interface list
bandwidth enable
softap fwreload wlan0 STA
firewall disable
interface getcfg wlan0
interface setcfg wlan0 0.0.0.0 0 multicast broadcast down
interface ipv6privacyextensions wlan0 enable
bandwidth setglobalalert 2097152
firewall disable
interface setthrottle rmnet0 -1 -1
interface getcfg p2p0
interface setcfg p2p0 0.0.0.0 0 multicast broadcast up
interface ipv6 wlan0 enable
resolver setifdns wlan0 192.168.2.254
resolver setdefaultif wlan0
interface route add wlan0 default 192.168.2.254 32 0.0.0.0
interface route add wlan0 default 0.0.0.0 0 192.168.2.254
resolver flushif wlan0
interface route add wlan0 default 192.168.2.254 32 0.0.0.0
interface route add wlan0 default 0.0.0.0 0 192.168.2.254
The only thing I do know for sure is that I can trigger the hotspot to come up in 4.4.3 when I issue commands to netd prior to the bootanimation completion.
Where did I go wrong?
-Environment-
VPN connection(OpenVPN)
-Default gateway is changed into VPN server IP
-Virtual interface(tunXX) for VPN connection directly connects to a default gateway
Interfaces & default gateway
interfaces :
lo inet addr:127.0.0.1
wlan0 inet addr:150.149.131.5
tun0 inet addr:10.8.0.14
default gateway : 10.8.0.2
In this environment, I want to know "10.8.0.14" regardless of the interface name using Android API.
I cound find only a way to get default route IP address below
mSocket = new Socket(dstAddress, peerPortNum);
mStrMyIPAddr = mSocket.getLocalAddress().getHostAddress();
But, I don not want to use Socket
I'm having issues with using some sockets in C++ code with Android NDK. Two sockets are created, and one reads from the other. This works with a network connection on Android, both with and without a network connection on another machine, but NOT on Android without a network connection.
Here is a netstat output before the socket closes. The line of interest is
tcp 0 0 127.0.0.1:32993 127.0.0.1:46810 ESTABLISHED
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:32993 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:45549 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:5037 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:5555 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:46811 127.0.0.1:32993 ESTABLISHED
tcp 0 0 127.0.0.1:32993 127.0.0.1:46811 ESTABLISHED
tcp 0 0 127.0.0.1:46810 127.0.0.1:32993 ESTABLISHED
tcp 0 0 127.0.0.1:32993 127.0.0.1:46810 ESTABLISHED
tcp 0 0 10.0.2.15:5555 10.0.2.2:34217 ESTABLISHED
udp 0 0 10.0.2.15:49667 10.0.2.3:53
udp 0 0 0.0.0.0:60262 0.0.0.0:*
I then attempt to read 10 bytes from the socket 127.0.0.1:46810 (header_length - filled = 10):
bytes = read(fd, header, header_length - filled);
However, 0 bytes are read. TCP_NODELAY has been set on the socket. This is the netstat output after the read.
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:32993 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:5037 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:5555 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:46811 127.0.0.1:32993 FIN_WAIT2
tcp 0 1 127.0.0.1:32993 127.0.0.1:46811 CLOSE_WAIT
tcp 0 0 127.0.0.1:46810 127.0.0.1:32993 FIN_WAIT2
tcp 0 0 127.0.0.1:32993 127.0.0.1:46810 CLOSE_WAIT
tcp 0 0 10.0.2.15:5555 10.0.2.2:34217 ESTABLISHED
udp 0 0 0.0.0.0:60262 0.0.0.0:*
There are no problems when there is a network connection, and the addresses used are still 127.0.0.1. Why would it fail to read any bytes on localhost when there is no network connection?
Turns out that this was being caused by another issue. Some time after resolving the IP address into a char array, delete[] was being called on the array. When there was no network connection, the pointer was being reassigned directly to 127.0.0.1, so the program was crashing on the delete[]. Copying the IP into the array using
strcpy(ip, "127.0.0.1");
means that the pointer still points at the array, and the program does not crash when calling delete[].
I connect my Android phone with my PC through USB. And open the usb tether option on the phone.
So, there is a new remote NDIS network adapter displayed in the PC's network connections, and there is a rnndis0 IFface on the android.
I do the following configurations:
PC: ip: 192.168.42.1 netmask: 255.255.255.0
Phone: ip 192.168.42.2 netmask: 255.255.255.0
And when ping each other, both work ok.
But when I configure the default gateway of my phone to be the address of the PC, it failed.
busybox route add default gw 192.168.42.1
busybox route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default bogon 0.0.0.0 UG 0 0 0 rndis0
192.168.42.0 * 255.255.255.0 U 0 0 0 rndis0
can anyone tell me the reason?
I believe it's marked as bogon as it is an address which should not appear in a routing table, ie a bogon route.
This is because it is a private network address. It's only a warning though.
see http://packetlife.net/blog/2009/jan/21/whats-bogon/
What is the output of
$ ip route
on Android?
SivlerZhao
Yesterday, I was unable to reproduce the problem.
Now, it reproduced.
busybox route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default bogon 0.0.0.0 UG 0 0 0 rndis0
192.168.137.0 * 255.255.255.0 U 0 0 0 rndis0
And the output of ip route is:
busybox ip route
default via 192.168.137.1 dev rndis0
192.168.137.0/24 dev rndis0 src 192.168.137.2
Actually, it works ok, but the "bogon" word apears