arp question

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

arp question

Etienne Lanoy


Hi LWIP community,

I just want to know the ethernet adress (MAC) of one host of my network.
I know its IP address.

I correctly send arp queries with the function (etharp_query(...)) but I
haven't understand how can I get
the mac adress of the host ? does LWIP has some functions to do that ?
Must I modify etherarp.c to do that ?

I thank you a lot for your help.

Etienne






_______________________________________________
lwip-users mailing list
[hidden email]
http://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

RE: arp question

Steve Chinatti
Normally you don't care about the layer-2 address, this is handled by the
TCP/IP stack.  Basically you send a packet to the layer-3 address, and the
stack figures out what the layer-2 address is (using ARP), and encapsulates
the packet accordingly.  The layer-2 address is stored internally in the arp
cache, and used for any subsequent correspondence with that host (until the
arp cache entry expires).

With that said, I had this same issue because I am working on a project
where I needed the layer-2 address of a peer in order to program some
hardware function in my project that was sending high data-rate traffic
directly (i.e. not through lwIP).  I was not able to find a function in LWIP
that provided the layer-2 address given the layer-3 address, so I wrote one.
I added the following function at the end of
lwip/src/lwip/src/netif/etharp.c:

struct eth_addr *
etharp_find(struct ip_addr *ipaddr)
{
    s8_t i;

    /* Ethernet address for IP destination address is in ARP cache? */
    for (i = 0; i < ARP_TABLE_SIZE; ++i) {
        /* match found? */
        if (arp_table[i].state == ETHARP_STATE_STABLE &&
            ip_addr_cmp(ipaddr, &arp_table[i].ipaddr)) {
            return &arp_table[i].ethaddr;
        }
    }
   
    return NULL;
}

It takes an IP address pointer and returns a pointer to the ethaddr
structure in the arp cache if it exists, and NULL if not.

---
Steve Chinatti
Innovative Communications Engineering, LLC
[hidden email]

> -----Original Message-----
> From: lwip-users-bounces+chinatti=[hidden email] [mailto:lwip-
> users-bounces+chinatti=[hidden email]] On Behalf Of Etienne Lanoy
> Sent: Tuesday, November 08, 2005 7:12 AM
> To: [hidden email]
> Subject: [lwip-users] arp question
>
>
>
> Hi LWIP community,
>
> I just want to know the ethernet adress (MAC) of one host of my network.
> I know its IP address.
>
> I correctly send arp queries with the function (etharp_query(...)) but I
> haven't understand how can I get
> the mac adress of the host ? does LWIP has some functions to do that ?
> Must I modify etherarp.c to do that ?
>
> I thank you a lot for your help.
>
> Etienne
>
>
>
>
>
>
> _______________________________________________
> lwip-users mailing list
> [hidden email]
> http://lists.nongnu.org/mailman/listinfo/lwip-users



_______________________________________________
lwip-users mailing list
[hidden email]
http://lists.nongnu.org/mailman/listinfo/lwip-users