Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get peer device's IP address in wifi-direct p2p connection [duplicate]

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?

like image 377
SS. Avatar asked Jun 20 '12 19:06

SS.


People also ask

Does Wi-Fi Direct have IP address?

In Android devices, once a Wi-Fi Direct connection is established, the GO automatically runs the DHCP to assign IP addresses to itself (192.168. 49.1/24) as well as to the P2P clients or legacy clients in its own group (192.168. 49.

Is Wi-Fi Direct P2P?

Wi-Fi Direct (also known as peer-to-peer or P2P) allows your application to quickly find and interact with nearby devices, at a range beyond the capabilities of Bluetooth. The Wi-Fi Direct (P2P) APIs allow applications to connect to nearby devices without needing to connect to a network or hotspot.

How do I get a peer IP address?

To get a peer address you have to have a peer, and to have a peer you have to have a connected socket, with which you can call getpeername() . Or, if you're a server, you can get it as a side-effect of accept() via the second and third arguments. Save this answer.

What is P2P connect mode?

In its simplest form, a peer-to-peer (P2P) network is created when two or more PCs are connected and share resources without going through a separate server computer. A P2P network can be an ad hoc connection—a couple of computers connected via a Universal Serial Bus to transfer files.


1 Answers

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.

like image 161
damian Avatar answered Sep 23 '22 20:09

damian