|
From: | Nicolas Pinault |
Subject: | Re: RE : [lwip-users] Source MAC address |
Date: | Thu, 20 Dec 2007 10:20:17 +0100 |
User-agent: | Thunderbird 2.0.0.9 (Windows/20071031) |
Hello Jonathan,Thank you for your help. It is an interresting solution. I have not tested it yet.Nicolas Pinault wrote:Hi Per, Thank's for your answer but that is not what I need. In my case, I need to know the MAC address of the sender.It's a bit unofficial, but for ethernet, assuming PBUF_RAM or PBUF_POOL pbufs, you should be able to look at the start of the pbuf (of the first pbuf in the packet chain). The payload pointer in that first pbuf which you will have been given will have skipped over the IP and UDP headers. You could use something like the following. Note that at this point it's hard to work out whether the IP header had options or not, so a little guesswork is required. Something like the following (untested) code: #include "lwip/pbuf.h" #include "netif/etharp.h" #include "lwip/ip.h" #include "lwip/udp.h" const u8_t *p = pbuf->payload; const u8_t *udp_hdr, *ip_hdr; const struct eth_hdr *eth_hdr; struct eth_addr src_eth_mac; udp_hdr = p - UDP_HLEN; ip_hdr = udp_hdr - IP_HLEN; /* Does it have options that make the header longer? * Could also check header checksum; */ while ( (IPH_V(ip_hdr) != 4) || (ip_hdr + IPH_HL(ip_hdr) != udp_hdr) ) { ip_hdr--; if (ip_hdr <= (u8_t*)pbuf+sizeof(struct pbuf)) return SOME_ERR; /* reached start of pbuf without finding header */ } eth_hdr = (const struct eth_hdr*)(ip_hdr - sizeof(struct eth_hdr)); src_eth_mac = eth_hdr->src; An alternative would be to jump directly to: eth_hdr = (const struct eth_hdr*)(pbuf+sizeof(pbuf)); But I feel a bit more uneasy about that. Hope this helps, Jifl I use Frédéric solution (searching arp table) with ETHARP_TRUST_IP_MAC set to 1. This way, I don't need to modify lwip code. If I have problem with this solution, I use your's. Thank you again. Nicolas |
[Prev in Thread] | Current Thread | [Next in Thread] |