28 |
* |
* |
29 |
* Author: Adam Dunkels <adam@sics.se> |
* Author: Adam Dunkels <adam@sics.se> |
30 |
* |
* |
31 |
|
* $Id$ |
32 |
*/ |
*/ |
33 |
|
|
34 |
/*-----------------------------------------------------------------------------------*/ |
/*-----------------------------------------------------------------------------------*/ |
50 |
#include "lwip/stats.h" |
#include "lwip/stats.h" |
51 |
|
|
52 |
#include "arch/perf.h" |
#include "arch/perf.h" |
53 |
|
#if LWIP_SNMP > 0 |
54 |
|
# include "snmp.h" |
55 |
|
#endif |
56 |
|
|
57 |
/*-----------------------------------------------------------------------------------*/ |
/*-----------------------------------------------------------------------------------*/ |
58 |
|
|
223 |
++stats.udp.chkerr; |
++stats.udp.chkerr; |
224 |
++stats.udp.drop; |
++stats.udp.drop; |
225 |
#endif /* UDP_STATS */ |
#endif /* UDP_STATS */ |
226 |
|
#if LWIP_SNMP > 0 |
227 |
|
snmp_inc_udpinerrors(); |
228 |
|
#endif |
229 |
pbuf_free(p); |
pbuf_free(p); |
230 |
goto end; |
goto end; |
231 |
} |
} |
240 |
++stats.udp.chkerr; |
++stats.udp.chkerr; |
241 |
++stats.udp.drop; |
++stats.udp.drop; |
242 |
#endif /* UDP_STATS */ |
#endif /* UDP_STATS */ |
243 |
|
#if LWIP_SNMP > 0 |
244 |
|
snmp_inc_udpinerrors(); |
245 |
|
#endif |
246 |
pbuf_free(p); |
pbuf_free(p); |
247 |
goto end; |
goto end; |
248 |
} |
} |
250 |
} |
} |
251 |
pbuf_header(p, -UDP_HLEN); |
pbuf_header(p, -UDP_HLEN); |
252 |
if(pcb != NULL) { |
if(pcb != NULL) { |
253 |
|
#if LWIP_SNMP > 0 |
254 |
|
snmp_inc_udpindatagrams(); |
255 |
|
#endif |
256 |
pcb->recv(pcb->recv_arg, pcb, p, &(iphdr->src), src); |
pcb->recv(pcb->recv_arg, pcb, p, &(iphdr->src), src); |
257 |
} else { |
} else { |
258 |
DEBUGF(UDP_DEBUG, ("udp_input: not for us.\n")); |
DEBUGF(UDP_DEBUG, ("udp_input: not for us.\n")); |
275 |
++stats.udp.proterr; |
++stats.udp.proterr; |
276 |
++stats.udp.drop; |
++stats.udp.drop; |
277 |
#endif /* UDP_STATS */ |
#endif /* UDP_STATS */ |
278 |
|
#if LWIP_SNMP > 0 |
279 |
|
snmp_inc_udpnoports(); |
280 |
|
#endif |
281 |
pbuf_free(p); |
pbuf_free(p); |
282 |
} |
} |
283 |
} else { |
} else { |
297 |
err_t err; |
err_t err; |
298 |
struct pbuf *hdr; |
struct pbuf *hdr; |
299 |
|
|
300 |
|
|
301 |
|
DEBUGF(UDP_DEBUG, ("udp_send")); |
302 |
/* hdr will point to the UDP header pbuf if an extra header pbuf has |
/* hdr will point to the UDP header pbuf if an extra header pbuf has |
303 |
to be allocated. */ |
to be allocated. */ |
304 |
hdr = NULL; |
hdr = NULL; |
311 |
pbuf_chain(hdr, p); |
pbuf_chain(hdr, p); |
312 |
p = hdr; |
p = hdr; |
313 |
} |
} |
314 |
|
DEBUGF(UDP_DEBUG, ("udp_send: got pbuf")); |
315 |
|
|
316 |
udphdr = p->payload; |
udphdr = p->payload; |
317 |
udphdr->src = htons(pcb->local_port); |
udphdr->src = htons(pcb->local_port); |
335 |
DEBUGF(UDP_DEBUG, ("udp_send: sending datagram of length %d\n", p->tot_len)); |
DEBUGF(UDP_DEBUG, ("udp_send: sending datagram of length %d\n", p->tot_len)); |
336 |
|
|
337 |
if(pcb->flags & UDP_FLAGS_UDPLITE) { |
if(pcb->flags & UDP_FLAGS_UDPLITE) { |
338 |
|
DEBUGF(UDP_DEBUG, ("udp_send: UDP LITE packet length %u", p->tot_len)); |
339 |
udphdr->len = htons(pcb->chksum_len); |
udphdr->len = htons(pcb->chksum_len); |
340 |
/* calculate checksum */ |
/* calculate checksum */ |
341 |
udphdr->chksum = inet_chksum_pseudo(p, src_ip, &(pcb->remote_ip), |
udphdr->chksum = inet_chksum_pseudo(p, src_ip, &(pcb->remote_ip), |
344 |
udphdr->chksum = 0xffff; |
udphdr->chksum = 0xffff; |
345 |
} |
} |
346 |
err = ip_output_if(p, src_ip, &pcb->remote_ip, UDP_TTL, IP_PROTO_UDPLITE, netif); |
err = ip_output_if(p, src_ip, &pcb->remote_ip, UDP_TTL, IP_PROTO_UDPLITE, netif); |
347 |
|
#if LWIP_SNMP > 0 |
348 |
|
snmp_inc_udpoutdatagrams(); |
349 |
|
#endif |
350 |
} else { |
} else { |
351 |
|
DEBUGF(UDP_DEBUG, ("udp_send: UDP packet length %u", p->tot_len)); |
352 |
udphdr->len = htons(p->tot_len); |
udphdr->len = htons(p->tot_len); |
353 |
/* calculate checksum */ |
/* calculate checksum */ |
354 |
if((pcb->flags & UDP_FLAGS_NOCHKSUM) == 0) { |
if((pcb->flags & UDP_FLAGS_NOCHKSUM) == 0) { |
358 |
udphdr->chksum = 0xffff; |
udphdr->chksum = 0xffff; |
359 |
} |
} |
360 |
} |
} |
361 |
|
DEBUGF(UDP_DEBUG, ("udp_send: UDP checksum %x", udphdr->chksum)); |
362 |
|
#if LWIP_SNMP > 0 |
363 |
|
snmp_inc_udpoutdatagrams(); |
364 |
|
#endif |
365 |
|
DEBUGF(UDP_DEBUG, ("udp_send: ip_output_if(,,,,IP_PROTO_UDP,)")); |
366 |
err = ip_output_if(p, src_ip, &pcb->remote_ip, UDP_TTL, IP_PROTO_UDP, netif); |
err = ip_output_if(p, src_ip, &pcb->remote_ip, UDP_TTL, IP_PROTO_UDP, netif); |
367 |
} |
} |
368 |
|
|