144 |
/* We allocate a pbuf chain of pbufs from the pool. */ |
/* We allocate a pbuf chain of pbufs from the pool. */ |
145 |
p = pbuf_alloc(PBUF_RAW, len, PBUF_POOL); |
p = pbuf_alloc(PBUF_RAW, len, PBUF_POOL); |
146 |
|
|
147 |
if(p != NULL) { |
if (p != NULL) { |
148 |
/* We iterate over the pbuf chain until we have read the entire |
/* We iterate over the pbuf chain until we have read the entire |
149 |
packet into the pbuf. */ |
packet into the pbuf. */ |
150 |
for(q = p; q != NULL; q = q->next) { |
for(q = p; q != NULL; q = q->next) { |
192 |
ethernetif = netif->state; |
ethernetif = netif->state; |
193 |
|
|
194 |
/* Make room for Ethernet header. */ |
/* Make room for Ethernet header. */ |
195 |
if(pbuf_header(p, 14) != 0) { |
if (pbuf_header(p, 14) != 0) { |
196 |
/* The pbuf_header() call shouldn't fail, but we allocate an extra |
/* The pbuf_header() call shouldn't fail, but we allocate an extra |
197 |
pbuf just in case. */ |
pbuf just in case. */ |
198 |
q = pbuf_alloc(PBUF_LINK, 14, PBUF_RAM); |
q = pbuf_alloc(PBUF_LINK, 14, PBUF_RAM); |
199 |
if(q == NULL) { |
if (q == NULL) { |
200 |
#ifdef LINK_STATS |
#ifdef LINK_STATS |
201 |
lwip_stats.link.drop++; |
lwip_stats.link.drop++; |
202 |
lwip_stats.link.memerr++; |
lwip_stats.link.memerr++; |
212 |
multicasts are special, all other addresses are looked up in the |
multicasts are special, all other addresses are looked up in the |
213 |
ARP table. */ |
ARP table. */ |
214 |
queryaddr = ipaddr; |
queryaddr = ipaddr; |
215 |
if(ip_addr_isany(ipaddr) || |
if (ip_addr_isany(ipaddr) || |
216 |
ip_addr_isbroadcast(ipaddr, &(netif->netmask))) { |
ip_addr_isbroadcast(ipaddr, &(netif->netmask))) { |
217 |
dest = (struct eth_addr *)ðbroadcast; |
dest = (struct eth_addr *)ðbroadcast; |
218 |
} else if(ip_addr_ismulticast(ipaddr)) { |
} else if (ip_addr_ismulticast(ipaddr)) { |
219 |
/* Hash IP multicast address to MAC address. */ |
/* Hash IP multicast address to MAC address. */ |
220 |
mcastaddr.addr[0] = 0x01; |
mcastaddr.addr[0] = 0x01; |
221 |
mcastaddr.addr[1] = 0x0; |
mcastaddr.addr[1] = 0x0; |
226 |
dest = &mcastaddr; |
dest = &mcastaddr; |
227 |
} else { |
} else { |
228 |
|
|
229 |
if(ip_addr_maskcmp(ipaddr, &(netif->ip_addr), &(netif->netmask))) { |
if (ip_addr_maskcmp(ipaddr, &(netif->ip_addr), &(netif->netmask))) { |
230 |
/* Use destination IP address if the destination is on the same |
/* Use destination IP address if the destination is on the same |
231 |
subnet as we are. */ |
subnet as we are. */ |
232 |
queryaddr = ipaddr; |
queryaddr = ipaddr; |
241 |
|
|
242 |
/* If the arp_lookup() didn't find an address, we send out an ARP |
/* If the arp_lookup() didn't find an address, we send out an ARP |
243 |
query for the IP address. */ |
query for the IP address. */ |
244 |
if(dest == NULL) { |
if (dest == NULL) { |
245 |
q = arp_query(netif, ethernetif->ethaddr, queryaddr); |
q = arp_query(netif, ethernetif->ethaddr, queryaddr); |
246 |
if(q != NULL) { |
if (q != NULL) { |
247 |
err = low_level_output(ethernetif, q); |
err = low_level_output(ethernetif, q); |
248 |
pbuf_free(q); |
pbuf_free(q); |
249 |
return err; |
return err; |
289 |
|
|
290 |
p = low_level_input(ethernetif); |
p = low_level_input(ethernetif); |
291 |
|
|
292 |
if(p != NULL) { |
if (p != NULL) { |
293 |
|
|
294 |
#ifdef LINK_STATS |
#ifdef LINK_STATS |
295 |
lwip_stats.link.recv++; |
lwip_stats.link.recv++; |
297 |
|
|
298 |
ethhdr = p->payload; |
ethhdr = p->payload; |
299 |
|
|
300 |
switch(htons(ethhdr->type)) { |
switch (htons(ethhdr->type)) { |
301 |
case ETHTYPE_IP: |
case ETHTYPE_IP: |
302 |
arp_ip_input(netif, p); |
arp_ip_input(netif, p); |
303 |
pbuf_header(p, -14); |
pbuf_header(p, -14); |
305 |
break; |
break; |
306 |
case ETHTYPE_ARP: |
case ETHTYPE_ARP: |
307 |
p = arp_arp_input(netif, ethernetif->ethaddr, p); |
p = arp_arp_input(netif, ethernetif->ethaddr, p); |
308 |
if(p != NULL) { |
if (p != NULL) { |
309 |
low_level_output(ethernetif, p); |
low_level_output(ethernetif, p); |
310 |
pbuf_free(p); |
pbuf_free(p); |
311 |
} |
} |