lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [lwip-users] arp question


From: Steve Chinatti
Subject: RE: [lwip-users] arp question
Date: Tue, 8 Nov 2005 08:46:46 -0500

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
address@hidden

> -----Original Message-----
> From: address@hidden [mailto:lwip-
> address@hidden On Behalf Of Etienne Lanoy
> Sent: Tuesday, November 08, 2005 7:12 AM
> To: address@hidden
> 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
> address@hidden
> http://lists.nongnu.org/mailman/listinfo/lwip-users





reply via email to

[Prev in Thread] Current Thread [Next in Thread]