How to find the hardware MAC address of a remote host from IP Address

882 views
Skip to first unread message

Ash

unread,
May 16, 2011, 11:44:39 PM5/16/11
to android-ndk
Hi,

I am developing a C++ network protocol stack on Android, there is a
requirement in which the server needs to know about the remote end's
MAC Address(client's). The communication channel is over UDP. The
only way to obtain the remote hardware address is to either do arp
lookup or send arp 'who' request. This could be done from Linux/
Windows using several APIs. On Windows there is an API SendARP
http://msdn.microsoft.com/en-us/library/aa366358(v=vs.85).aspx.

Is there any way on Android to get the same 'SendARP' functionality of
Windows? What are the possible ways to find out the remote MAC/
Hardware address using the remote IP Address on Android?

Looks like the use of RAW sockets requires root permission. Which
would not allow the applications built on top my network protocol
stack to be downloaded.

Thanks In Advance
Ash

Chris Stratton

unread,
May 17, 2011, 1:26:16 AM5/17/11
to andro...@googlegroups.com
On Monday, May 16, 2011 11:44:39 PM UTC-4, Ash wrote:
 
I am developing a C++ network protocol stack on Android, there is a
requirement in which the server needs to know about the remote end's
MAC Address(client's). The communication channel is over UDP.  The
only way to obtain the remote hardware address is to either do arp
lookup or send arp 'who' request. This could be done from Linux/
Windows using several APIs. On Windows there is an API SendARP
http://msdn.microsoft.com/en-us/library/aa366358(v=vs.85).aspx.

You do know this will only work if the remote end is one the same subnet, right?
 
Is there any way on Android to get the same 'SendARP' functionality of
Windows? What are the possible ways to find out the remote MAC/
Hardware address using the remote IP Address on Android?

Well, you could just politely ask whatever application-level software you are talking to on the other end to tell you (assuming it is capable of find out its own MAC address)
 
Or, if you simply trigger network interaction with the remote device you should be able to look in /proc/net/arp and see that the network stack has accomplished the resolution for you.

Ash

unread,
May 17, 2011, 3:28:52 AM5/17/11
to android-ndk
Thanks for the reply.

My network protocol stack is only for same subnet.

Protocol specification doesn't allow out of band message exchange, so
Applications can't provide their own MAC address. Also the application
session gets established only after remote/client MAC address bindings
with Server.
The protocol specification is for routers where the IPAddress of the
remote systems keep on changing (DHCP) but the MAC Address remains
same.

I am looking at the implementation level solution for obtaining the
remote MAC address through their IP Addresses.

Reading /proc/net/arp wouldn't be reliable as the ARP Table cache can
be flushed irrespective of the usage. BTW, can native code access /
proc/net/arp without special permissions like root?
Reply all
Reply to author
Forward
0 new messages