• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How to get the Mac address of a host on LAN by its IP on MAC-OS-X
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to get the Mac address of a host on LAN by its IP on MAC-OS-X


  • Subject: Re: How to get the Mac address of a host on LAN by its IP on MAC-OS-X
  • From: Quinn <email@hidden>
  • Date: Tue, 23 Oct 2007 10:27:27 +0100

Title: Re: How to get the Mac address of a host on LAN by its IP
At 23:29 -0700 22/10/07, Kan Cheng wrote:
when I was constructing the socket on Mac-OS-X , like doing the same thing on Linux:
Š
     int fd_arp;
     if((fd_arp = socket(AF_INET, SOCK_SEQPACKET, htons(0x0806))) < 0)
     {
           perror("socket error");
           goto _ERROR_HANDLER;
     }
                Š
I got the error message on console: 'socket error: Protocol not supported'. But when I open /etc/protocols, I found that NARP & LARP were declared.
 
Does it means Mac-OS-X socket does not support ARP?

Pretty much.

Is there any way to make it work?

Of course (-:
When I trying to use the command "arp -a" on the terminal, I can get some of the hosts on the LAN cannot get all of them.

That's because "arp -a" displays the current ARP cache.  If you haven't communicated with a particular machine recently, there's no entry in the cache.

You can force an entry into the cache by communicating with the machine.  Send it a ping.

In general the technique I recommend for this is:

repeat
  do an "arp -an"
  break if the target is in the list
  ping the target
  delay for a short while
end

You can do the ping and the ARP probe by either running the tools, or by writing the equivalent code in C.  Two things to consider:

o Implementing ping traditionally requires elevated privileges (because it requires a raw IP socket), but this is not so on Mac OS X.

<http://developer.apple.com/samplecode/SimplePing/index.html>

o Implementing the equivalent of "arp -an" is not much fun, but you can look at the Darwin code for ideas.

<http://www.opensource.apple.com/darwinsource/Current/network_cmds-245.16/arp.tproj/>

[This link requires an APSL <http://www.opensource.apple.com/apsl/>
account.]

Finally, this is not the first time I've been asked this question, so I filed a bug requesting a nicer solution to this problem <rdar://problem/5554400>.  If you forward me information about /why/ you need to do IP -> MAC translation, I'll add that to the bug.

Share and Enjoy
--
Quinn "The Eskimo!"                    <http://www.apple.com/developer/>
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Prev by Date: Re: MoreSCF 1.1 and Cross-Development
  • Next by Date: Re: MoreSCF 1.1 and Cross-Development
  • Previous by thread: How to get the Mac address of a host on LAN by its IP on MAC-OS-X
  • Next by thread: Re: How to get the Mac address of a host on LAN by its IP on MAC-OS-X
  • Index(es):
    • Date
    • Thread