void ethernetif_input(struct netif *netif)
{
struct ethernetif *ethernetif;
struct eth_hdr *ethhdr;
struct pbuf *p;
while(1)
{
ethernetif = netif->state;
do{
p = low_level_input(netif);
if (p == NULL)
OSTimeDlyHMSM(0,0,0,100);
}while(p == NULL);
lwip_stats.link.recv++;
#endif
switch (htons(ethhdr->type)) {
#if 1
etharp_ip_input(netif, p); //更新ARP表
#endif
//跳过以太网头部字段
pbuf_header(p, -sizeof(struct eth_hdr));
//传递到网络层
netif->input(p, netif);
break;
case ETHTYPE_ARP:
//将netif传递到ARP模块
p = etharp_arp_input(netif, ethernetif->ethaddr, p);
if(p != NULL) {
low_level_output(netif, p);
pbuf_free(p);
p = NULL;
}
break;
default:
pbuf_free(p);
p = NULL;
break;
}
}
}
在上面函数中用到了p = etharp_arp_input(netif, ethernetif->ethaddr, p);但是在etharp.c中找到etharp_arp_input函数原型,它为void etharp_arp_input(struct netif *netif, struct eth_addr *ethaddr, struct pbuf *p),是无返回值类型,大哥应该是对函数etharp_arp_input()进行了修改的,能将修改后的函数给我看看吗,返回的是什么呢?
答:原函数如下->
etharp_arp_input(struct netif *netif, struct eth_addr *ethaddr, struct pbuf *p)
{
struct etharp_hdr *hdr;
/* these are aligned properly, whereas the ARP header fields might not be */
struct ip_addr sipaddr, dipaddr;
u8_t i;
u8_t for_us;
/* drop short ARP packets */
if (p->tot_len < sizeof(struct etharp_hdr)) {
LWIP_DEBUGF(ETHARP_DEBUG | DBG_TRACE | 1, ("etharp_arp_input: packet dropped, too short (%"S16_F"/%"S16_F") ", p->tot_len, (s16_t)sizeof(struct etharp_hdr)));
pbuf_free(p);
return;
}
/* Copy struct ip_addr2 to aligned ip_addr, to support compilers without
* structure packing (not using structure copy which breaks strict-aliasing rules). */
memcpy((void *)&sipaddr, (void *)&hdr->sipaddr, sizeof(sipaddr));
memcpy((void *)&dipaddr,(void *) &hdr->dipaddr, sizeof(dipaddr));
if (netif->ip_addr.addr == 0) {
for_us = 0;
} else {
/* ARP packet directed to us? */
for_us = ip_addr_cmp(&dipaddr, &(netif->ip_addr));
}
if (for_us) {
/* add IP address in ARP cache; assume requester wants to talk to us.
* can result in directly sending the queued packets for this host. */
update_arp_entry(netif, &sipaddr, &(hdr->shwaddr), ETHARP_TRY_HARD);
/* ARP message not directed to us? */
} else {
/* update the source IP address in the cache, if present */
update_arp_entry(netif, &sipaddr, &(hdr->shwaddr), 0);
}
switch (htons(hdr->opcode)) {
/* ARP request? */
case ARP_REQUEST:
/* ARP request. If it asked for our address, we send out a
* reply. In any case, we time-stamp any existing ARP entry,
* and possiby send out an IP packet that was queued on it. */
/* ARP request for our address? */
if (for_us) {
/* re-use pbuf to send ARP reply */
hdr->opcode = htons(ARP_REPLY);
hdr->sipaddr = *(struct ip_addr2 *)&netif->ip_addr;
while(i > 0) {
i--;
hdr->dhwaddr.addr[i] = hdr->shwaddr.addr[i];
hdr->shwaddr.addr[i] = ethaddr->addr[i];
hdr->ethhdr.dest.addr[i] = hdr->dhwaddr.addr[i];
hdr->ethhdr.src.addr[i] = ethaddr->addr[i];
}
ARPH_HWLEN_SET(hdr, netif->hwaddr_len);
ARPH_PROTOLEN_SET(hdr, sizeof(struct ip_addr));
/* return ARP reply */
netif->linkoutput(netif, p);
/* we are not configured? */
} else if (netif->ip_addr.addr == 0) {
/* { for_us == 0 and netif->ip_addr.addr == 0 } */
LWIP_DEBUGF(ETHARP_DEBUG | DBG_TRACE, ("etharp_arp_input: we are unconfigured, ARP request ignored. "));
/* request was not directed to us */
} else {
/* { for_us == 0 and netif->ip_addr.addr != 0 } */
LWIP_DEBUGF(ETHARP_DEBUG | DBG_TRACE, ("etharp_arp_input: ARP request was not for us. "));
}
break;
case ARP_REPLY:
/* ARP reply. We already updated the ARP cache earlier. */
LWIP_DEBUGF(ETHARP_DEBUG | DBG_TRACE, ("etharp_arp_input: incoming ARP reply "));
#if (LWIP_DHCP && DHCP_DOES_ARP_CHECK)
/* DHCP wants to know about ARP replies from any host with an
* IP address also offered to us by the DHCP server. We do not
* want to take a duplicate IP address on a single network.
* @todo How should we handle redundant (fail-over) interfaces?
* */
dhcp_arp_reply(netif, &sipaddr);
#endif
break;
default:
LWIP_DEBUGF(ETHARP_DEBUG | DBG_TRACE, ("etharp_arp_input: ARP unknown opcode type %"S16_F" ", htons(hdr->opcode)));
break;
}
/* free ARP packet */
pbuf_free(p);
p =NULL;
return NULL;
}
3501



被折叠的 条评论
为什么被折叠?



