Translate MAC address to IP address

Nick Barnes Nick.Barnes at pobox.com
Fri Aug 15 04:16:37 PDT 2003


At 2003-08-13 15:43:51+0000, Lars Eggert writes:
> This is a cryptographically signed message in MIME format.
> 
> --------------ms070709090404010406080107
> Content-Type: text/plain; charset=us-ascii; format=flowed
> Content-Transfer-Encoding: 7bit
> 
> Nick Barnes wrote:
> 
> > [-net seems to be the right forum for this.]
> > 
> > I have some MAC addresses from a local Ethernet segment.  I want to
> > convert them into IP addresses.  How can I do that programmatically?
> 
> net/arping from port:

Thanks for the reference.  I had a look at arping. It works by sending
a broadcast ping to the specified MAC address (not to the broadcast
MAC).  I note that FreeBSD machines do respond to such pings (unlike
regular broadcast pings), but some machines do not (e.g. WinXPPro,
NT4).

Since asking the question, I have been rummaging around in user-space
network code (e.g. in the sources for arp, ping, and ifconfig) and
have written a couple of little utilities:

- "ifget" lists IP addresses accessible on local subnets via active
   network interfaces (in fact I have two implementations of this, one
   written before I discovered getifaddrs() and one written after).
   This is all possible IP addresses (in the range defined by the
   netmask, for broadcast interfaces). It skips interfaces which are
   loopback, down, not running, not AF_INET, or not IFM_ACTIVE.

- "pingall" sends a single ping packet to all such IP addresses and
  then exits.  This causes an ARP exchange for any such address not
  currently in the local ARP table, so populates that table (including
  a lot of "incomplete" entries, for unassigned IP addresses).

Next week I may spend the time to extend my "ethercount" program,
using the "pingall" code and the guts of "arp -a", to report using IP
addresses instead of MACs.

I can provide sources on request any time; once these things are a bit
more polished I will put them on the web.

Nick B


More information about the freebsd-net mailing list