8

My app needs to know the peer device’s IP address when my device is a group owner (GO) in a wifi-direct P2P connection (usually GO acts as DHCP server and peer station receives the IP from the server). I figured out that the DHCP client list is stored in /data/misc/dhcp/dnsmasq.leases file, but the app has to be part of “dhcp” group to read that file and I am getting EACCES (Permission denied) when trying to read it.

Is there a permission that I can add in the manifest to read that file? Or is there any other way to get this DHCP client list from java/native Android framework without root?

SS.
  • 171
  • 2
  • 12

4 Answers4

2

I solved this by sending out the peer's local ip address (starting with 192.168.x.x) to the group owner. After this "handshake", which doesn't really take time, it's all good to go. Did not find any other way to get the peer's ip addresses, the only information provided by GroupListener/PeerListener/... is the mac address.

damian
  • 2,001
  • 20
  • 38
2

I got the GO's ip addresse in the onConnectionInfoAvailable, which is what you get from your BroadcastReceiver .WIFI_P2P_CONNECTION_CHANGED_ACTION event, which is triggered once you have connected.
So you call requestConnectionInfo(mChannel, mMyWiFiActivity) after connection, then hook into the callback, onConnectionInfoAvailable(WifiP2pInfo info).

This then with give you the address of the group owner.info.groupOwnerAddress.getHostAddress();

Hope this helps

Bluemoon10
  • 89
  • 5
  • 2
    Well, this will give you GO's IP address. If your code is already running on GO and you want to know the peer's IP address, this will not help. – SS. Jul 26 '14 at 00:22
  • 1
    I don't know if this would help or not but in my project I have a ServerSocket running on the GO, (which I start once I know that device is the GO from onConnectionInfoAvailable callback). Then when I get my peerlist, on my client device, connect to the serverSocket on the GO and the serverSocket request the ip of the device that has just connected to it. I then send this back to the client. – Bluemoon10 Jul 28 '14 at 20:13
0

If you have adb root access, you can get access DHCP client list which is stored in ./data/misc/dhcp/dnsmasq.leases

Programatically,

on the server side or GO side:

1) Open a Socket on port (say port:9999)

2) Invoke Accept() & wait for the client or GC to connect (Socket clientSocket = Socket.accept();)

3) Once client/GC connects, GC IP address can be found using "clientSocket.getInetAddress().toString()"

on the client side or GC side:

1) Trigger a connection from client (GC) to Group Owner

2) Open & connect socket to Group Owner's IP address

3) P2P GO IP address is available through "info.groupOwnerAddress.getHostAddress()" (WifiP2pInfo info;)

4) Connect to same port say 9999

-2

There isnt. YOu need to use a service discovery protocol.

Irfan
  • 138
  • 3
  • Is service discovery supported in ICS? – SS. Jun 22 '12 at 00:07
  • No. It is supported in JB as part of platform. You could try using something like JmDNS as part of the app. – Irfan Jul 02 '12 at 22:55
  • 3
    Is there a reason it is so difficult to do this? Why would you make a DHCP server and then have no access to what it's giving out? This is needlessly complicated... – Mgamerz Jan 27 '13 at 07:32