Domanda

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?

È stato utile?

Soluzione

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

Altri suggerimenti

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.

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

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

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top