]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/lwip/lib/contrib/src/core/udp.c
update
[l4.git] / l4 / pkg / lwip / lib / contrib / src / core / udp.c
1 /**
2  * @file
3  * User Datagram Protocol module
4  *
5  */
6
7 /*
8  * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
9  * All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without modification,
12  * are permitted provided that the following conditions are met:
13  *
14  * 1. Redistributions of source code must retain the above copyright notice,
15  *    this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright notice,
17  *    this list of conditions and the following disclaimer in the documentation
18  *    and/or other materials provided with the distribution.
19  * 3. The name of the author may not be used to endorse or promote products
20  *    derived from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
23  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
24  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
25  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
27  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
30  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
31  * OF SUCH DAMAGE.
32  *
33  * This file is part of the lwIP TCP/IP stack.
34  *
35  * Author: Adam Dunkels <adam@sics.se>
36  *
37  */
38
39
40 /* udp.c
41  *
42  * The code for the User Datagram Protocol UDP & UDPLite (RFC 3828).
43  *
44  */
45
46 /* @todo Check the use of '(struct udp_pcb).chksum_len_rx'!
47  */
48
49 #include "lwip/opt.h"
50
51 #if LWIP_UDP /* don't build if not configured for use in lwipopts.h */
52
53 #include "lwip/udp.h"
54 #include "lwip/def.h"
55 #include "lwip/memp.h"
56 #include "lwip/inet_chksum.h"
57 #include "lwip/ip_addr.h"
58 #include "lwip/ip6.h"
59 #include "lwip/ip6_addr.h"
60 #include "lwip/inet_chksum.h"
61 #include "lwip/netif.h"
62 #include "lwip/icmp.h"
63 #include "lwip/icmp6.h"
64 #include "lwip/stats.h"
65 #include "lwip/snmp.h"
66 #include "arch/perf.h"
67 #include "lwip/dhcp.h"
68
69 #include <string.h>
70
71 /* The list of UDP PCBs */
72 /* exported in udp.h (was static) */
73 struct udp_pcb *udp_pcbs;
74
75 /**
76  * Process an incoming UDP datagram.
77  *
78  * Given an incoming UDP datagram (as a chain of pbufs) this function
79  * finds a corresponding UDP PCB and hands over the pbuf to the pcbs
80  * recv function. If no pcb is found or the datagram is incorrect, the
81  * pbuf is freed.
82  *
83  * @param p pbuf to be demultiplexed to a UDP PCB (p->payload pointing to the UDP header)
84  * @param inp network interface on which the datagram was received.
85  *
86  */
87 void
88 udp_input(struct pbuf *p, struct netif *inp)
89 {
90   struct udp_hdr *udphdr;
91   struct udp_pcb *pcb, *prev;
92   struct udp_pcb *uncon_pcb;
93   u16_t src, dest;
94   u8_t local_match;
95   u8_t broadcast;
96   u8_t for_us;
97
98   PERF_START;
99
100   UDP_STATS_INC(udp.recv);
101
102   /* Check minimum length (UDP header) */
103   if (p->len < UDP_HLEN) {
104     /* drop short packets */
105     LWIP_DEBUGF(UDP_DEBUG,
106                 ("udp_input: short UDP datagram (%"U16_F" bytes) discarded\n", p->tot_len));
107     UDP_STATS_INC(udp.lenerr);
108     UDP_STATS_INC(udp.drop);
109     snmp_inc_udpinerrors();
110     pbuf_free(p);
111     goto end;
112   }
113
114   udphdr = (struct udp_hdr *)p->payload;
115
116   /* is broadcast packet ? */
117 #if LWIP_IPV6
118   broadcast = !ip_current_is_v6() && ip_addr_isbroadcast(ip_current_dest_addr(), inp);
119 #else /* LWIP_IPV6 */
120   broadcast = ip_addr_isbroadcast(ip_current_dest_addr(), inp);
121 #endif /* LWIP_IPV6 */
122
123   LWIP_DEBUGF(UDP_DEBUG, ("udp_input: received datagram of length %"U16_F"\n", p->tot_len));
124
125   /* convert src and dest ports to host byte order */
126   src = ntohs(udphdr->src);
127   dest = ntohs(udphdr->dest);
128
129   udp_debug_print(udphdr);
130
131   /* print the UDP source and destination */
132   LWIP_DEBUGF(UDP_DEBUG, ("udp ("));
133   ipX_addr_debug_print(ip_current_is_v6(), UDP_DEBUG, ipX_current_dest_addr());
134   LWIP_DEBUGF(UDP_DEBUG, (", %"U16_F") <-- (", ntohs(udphdr->dest)));
135   ipX_addr_debug_print(ip_current_is_v6(), UDP_DEBUG, ipX_current_src_addr());
136   LWIP_DEBUGF(UDP_DEBUG, (", %"U16_F")\n", ntohs(udphdr->src)));
137
138 #if LWIP_DHCP
139   pcb = NULL;
140   /* when LWIP_DHCP is active, packets to DHCP_CLIENT_PORT may only be processed by
141      the dhcp module, no other UDP pcb may use the local UDP port DHCP_CLIENT_PORT */
142   if (dest == DHCP_CLIENT_PORT) {
143     /* all packets for DHCP_CLIENT_PORT not coming from DHCP_SERVER_PORT are dropped! */
144     if (src == DHCP_SERVER_PORT) {
145       if ((inp->dhcp != NULL) && (inp->dhcp->pcb != NULL)) {
146         /* accept the packe if 
147            (- broadcast or directed to us) -> DHCP is link-layer-addressed, local ip is always ANY!
148            - inp->dhcp->pcb->remote == ANY or iphdr->src
149            (no need to check for IPv6 since the dhcp struct always uses IPv4) */
150         if (ipX_addr_isany(0, &inp->dhcp->pcb->remote_ip) ||
151             ip_addr_cmp(ipX_2_ip(&(inp->dhcp->pcb->remote_ip)), ip_current_src_addr())) {
152           pcb = inp->dhcp->pcb;
153         }
154       }
155     }
156   } else
157 #endif /* LWIP_DHCP */
158   {
159     prev = NULL;
160     local_match = 0;
161     uncon_pcb = NULL;
162     /* Iterate through the UDP pcb list for a matching pcb.
163      * 'Perfect match' pcbs (connected to the remote port & ip address) are
164      * preferred. If no perfect match is found, the first unconnected pcb that
165      * matches the local port and ip address gets the datagram. */
166     for (pcb = udp_pcbs; pcb != NULL; pcb = pcb->next) {
167       local_match = 0;
168       /* print the PCB local and remote address */
169       LWIP_DEBUGF(UDP_DEBUG, ("pcb ("));
170       ipX_addr_debug_print(PCB_ISIPV6(pcb), UDP_DEBUG, &pcb->local_ip);
171       LWIP_DEBUGF(UDP_DEBUG, (", %"U16_F") <-- (", pcb->local_port));
172       ipX_addr_debug_print(PCB_ISIPV6(pcb), UDP_DEBUG, &pcb->remote_ip);
173       LWIP_DEBUGF(UDP_DEBUG, (", %"U16_F")\n", pcb->remote_port));
174
175       /* compare PCB local addr+port to UDP destination addr+port */
176       if ((pcb->local_port == dest) &&
177 #if LWIP_IPV6
178           ((PCB_ISIPV6(pcb) && (ip_current_is_v6()) &&
179             (ip6_addr_isany(ipX_2_ip6(&pcb->local_ip)) ||
180 #if LWIP_IPV6_MLD
181             ip6_addr_ismulticast(ip6_current_dest_addr()) ||
182 #endif /* LWIP_IPV6_MLD */
183             ip6_addr_cmp(ipX_2_ip6(&pcb->local_ip), ip6_current_dest_addr()))) ||
184            (!PCB_ISIPV6(pcb) &&
185             (ip_current_header() != NULL) &&
186 #else /* LWIP_IPV6 */
187            ((
188 #endif /* LWIP_IPV6 */
189             ((!broadcast && ipX_addr_isany(0, &pcb->local_ip)) ||
190             ip_addr_cmp(ipX_2_ip(&pcb->local_ip), ip_current_dest_addr()) ||
191 #if LWIP_IGMP
192             ip_addr_ismulticast(ip_current_dest_addr()) ||
193 #endif /* LWIP_IGMP */
194 #if IP_SOF_BROADCAST_RECV
195             (broadcast && (pcb->so_options & SOF_BROADCAST)))))) {
196 #else  /* IP_SOF_BROADCAST_RECV */
197             (broadcast))))) {
198 #endif /* IP_SOF_BROADCAST_RECV */
199         local_match = 1;
200         if ((uncon_pcb == NULL) && 
201             ((pcb->flags & UDP_FLAGS_CONNECTED) == 0)) {
202           /* the first unconnected matching PCB */
203           uncon_pcb = pcb;
204         }
205       }
206       /* compare PCB remote addr+port to UDP source addr+port */
207       if ((local_match != 0) &&
208           (pcb->remote_port == src) && IP_PCB_IPVER_INPUT_MATCH(pcb) &&
209             (ipX_addr_isany(PCB_ISIPV6(pcb), &pcb->remote_ip) ||
210               ipX_addr_cmp(PCB_ISIPV6(pcb), &pcb->remote_ip, ipX_current_src_addr()))) {
211         /* the first fully matching PCB */
212         if (prev != NULL) {
213           /* move the pcb to the front of udp_pcbs so that is
214              found faster next time */
215           prev->next = pcb->next;
216           pcb->next = udp_pcbs;
217           udp_pcbs = pcb;
218         } else {
219           UDP_STATS_INC(udp.cachehit);
220         }
221         break;
222       }
223       prev = pcb;
224     }
225     /* no fully matching pcb found? then look for an unconnected pcb */
226     if (pcb == NULL) {
227       pcb = uncon_pcb;
228     }
229   }
230
231   /* Check checksum if this is a match or if it was directed at us. */
232   if (pcb != NULL) {
233     for_us = 1;
234   } else {
235 #if LWIP_IPV6
236     if (ip_current_is_v6()) {
237       for_us = netif_matches_ip6_addr(inp, ip6_current_dest_addr());
238     } else
239 #endif /* LWIP_IPV6 */
240     {
241       for_us = ip_addr_cmp(&inp->ip_addr, ip_current_dest_addr());
242     }
243   }
244   if (for_us) {
245     LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE, ("udp_input: calculating checksum\n"));
246 #if CHECKSUM_CHECK_UDP
247 #if LWIP_UDPLITE
248     if (ip_current_header_proto() == IP_PROTO_UDPLITE) {
249       /* Do the UDP Lite checksum */
250       u16_t chklen = ntohs(udphdr->len);
251       if (chklen < sizeof(struct udp_hdr)) {
252         if (chklen == 0) {
253           /* For UDP-Lite, checksum length of 0 means checksum
254              over the complete packet (See RFC 3828 chap. 3.1) */
255           chklen = p->tot_len;
256         } else {
257           /* At least the UDP-Lite header must be covered by the
258              checksum! (Again, see RFC 3828 chap. 3.1) */
259           goto chkerr;
260         }
261       }
262       if (ipX_chksum_pseudo_partial(ip_current_is_v6(), p, IP_PROTO_UDPLITE,
263                    p->tot_len, chklen,
264                    ipX_current_src_addr(), ipX_current_dest_addr()) != 0) {
265         goto chkerr;
266       }
267     } else
268 #endif /* LWIP_UDPLITE */
269     {
270       if (udphdr->chksum != 0) {
271         if (ipX_chksum_pseudo(ip_current_is_v6(), p, IP_PROTO_UDP, p->tot_len,
272                               ipX_current_src_addr(),
273                               ipX_current_dest_addr()) != 0) {
274           goto chkerr;
275         }
276       }
277     }
278 #endif /* CHECKSUM_CHECK_UDP */
279     if(pbuf_header(p, -UDP_HLEN)) {
280       /* Can we cope with this failing? Just assert for now */
281       LWIP_ASSERT("pbuf_header failed\n", 0);
282       UDP_STATS_INC(udp.drop);
283       snmp_inc_udpinerrors();
284       pbuf_free(p);
285       goto end;
286     }
287     if (pcb != NULL) {
288       snmp_inc_udpindatagrams();
289 #if SO_REUSE && SO_REUSE_RXTOALL
290       if ((broadcast ||
291 #if LWIP_IPV6
292           ip6_addr_ismulticast(ip6_current_dest_addr()) ||
293 #endif /* LWIP_IPV6 */
294            ip_addr_ismulticast(ip_current_dest_addr())) &&
295           ((pcb->so_options & SOF_REUSEADDR) != 0)) {
296         /* pass broadcast- or multicast packets to all multicast pcbs
297            if SOF_REUSEADDR is set on the first match */
298         struct udp_pcb *mpcb;
299         u8_t p_header_changed = 0;
300         s16_t hdrs_len = (s16_t)(ip_current_header_tot_len() + UDP_HLEN);
301         for (mpcb = udp_pcbs; mpcb != NULL; mpcb = mpcb->next) {
302           if (mpcb != pcb) {
303             /* compare PCB local addr+port to UDP destination addr+port */
304             if ((mpcb->local_port == dest) &&
305 #if LWIP_IPV6
306                 ((PCB_ISIPV6(mpcb) &&
307                   (ip6_addr_ismulticast(ip6_current_dest_addr()) ||
308                    ip6_addr_cmp(ipX_2_ip6(&mpcb->local_ip), ip6_current_dest_addr()))) ||
309                  (!PCB_ISIPV6(mpcb) &&
310 #else /* LWIP_IPV6 */
311                 ((
312 #endif /* LWIP_IPV6 */
313                   ((!broadcast && ipX_addr_isany(0, &mpcb->local_ip)) ||
314                    ip_addr_cmp(ipX_2_ip(&mpcb->local_ip), ip_current_dest_addr()) ||
315 #if LWIP_IGMP
316                    ip_addr_ismulticast(ip_current_dest_addr()) ||
317 #endif /* LWIP_IGMP */
318 #if IP_SOF_BROADCAST_RECV
319                    (broadcast && (mpcb->so_options & SOF_BROADCAST)))))) {
320 #else  /* IP_SOF_BROADCAST_RECV */
321                    (broadcast))))) {
322 #endif /* IP_SOF_BROADCAST_RECV */
323               /* pass a copy of the packet to all local matches */
324               if (mpcb->recv.ip4 != NULL) {
325                 struct pbuf *q;
326                 /* for that, move payload to IP header again */
327                 if (p_header_changed == 0) {
328                   pbuf_header(p, hdrs_len);
329                   p_header_changed = 1;
330                 }
331                 q = pbuf_alloc(PBUF_RAW, p->tot_len, PBUF_RAM);
332                 if (q != NULL) {
333                   err_t err = pbuf_copy(q, p);
334                   if (err == ERR_OK) {
335                     /* move payload to UDP data */
336                     pbuf_header(q, -hdrs_len);
337 #if LWIP_IPV6
338                     if (PCB_ISIPV6(mpcb)) {
339                       mpcb->recv.ip6(mpcb->recv_arg, mpcb, q, ip6_current_src_addr(), src);
340                     }
341                     else
342 #endif /* LWIP_IPV6 */
343                     {
344                       mpcb->recv.ip4(mpcb->recv_arg, mpcb, q, ip_current_src_addr(), src);
345                     }
346                   }
347                 }
348               }
349             }
350           }
351         }
352         if (p_header_changed) {
353           /* and move payload to UDP data again */
354           pbuf_header(p, -hdrs_len);
355         }
356       }
357 #endif /* SO_REUSE && SO_REUSE_RXTOALL */
358       /* callback */
359       if (pcb->recv.ip4 != NULL) {
360         /* now the recv function is responsible for freeing p */
361 #if LWIP_IPV6
362         if (PCB_ISIPV6(pcb)) {
363           pcb->recv.ip6(pcb->recv_arg, pcb, p, ip6_current_src_addr(), src);
364         }
365         else
366 #endif /* LWIP_IPV6 */
367         {
368           pcb->recv.ip4(pcb->recv_arg, pcb, p, ip_current_src_addr(), src);
369         }
370       } else {
371         /* no recv function registered? then we have to free the pbuf! */
372         pbuf_free(p);
373         goto end;
374       }
375     } else {
376       LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE, ("udp_input: not for us.\n"));
377
378 #if LWIP_ICMP || LWIP_ICMP6
379       /* No match was found, send ICMP destination port unreachable unless
380          destination address was broadcast/multicast. */
381       if (!broadcast &&
382 #if LWIP_IPV6
383           !ip6_addr_ismulticast(ip6_current_dest_addr()) &&
384 #endif /* LWIP_IPV6 */
385           !ip_addr_ismulticast(ip_current_dest_addr())) {
386         /* move payload pointer back to ip header */
387         pbuf_header(p, ip_current_header_tot_len() + UDP_HLEN);
388         icmp_port_unreach(ip_current_is_v6(), p);
389       }
390 #endif /* LWIP_ICMP || LWIP_ICMP6 */
391       UDP_STATS_INC(udp.proterr);
392       UDP_STATS_INC(udp.drop);
393       snmp_inc_udpnoports();
394       pbuf_free(p);
395     }
396   } else {
397     pbuf_free(p);
398   }
399 end:
400   PERF_STOP("udp_input");
401   return;
402 chkerr:
403   LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_LEVEL_SERIOUS,
404               ("udp_input: UDP (or UDP Lite) datagram discarded due to failing checksum\n"));
405   UDP_STATS_INC(udp.chkerr);
406   UDP_STATS_INC(udp.drop);
407   snmp_inc_udpinerrors();
408   pbuf_free(p);
409   PERF_STOP("udp_input");
410 }
411
412 /**
413  * Send data using UDP.
414  *
415  * @param pcb UDP PCB used to send the data.
416  * @param p chain of pbuf's to be sent.
417  *
418  * The datagram will be sent to the current remote_ip & remote_port
419  * stored in pcb. If the pcb is not bound to a port, it will
420  * automatically be bound to a random port.
421  *
422  * @return lwIP error code.
423  * - ERR_OK. Successful. No error occured.
424  * - ERR_MEM. Out of memory.
425  * - ERR_RTE. Could not find route to destination address.
426  * - More errors could be returned by lower protocol layers.
427  *
428  * @see udp_disconnect() udp_sendto()
429  */
430 err_t
431 udp_send(struct udp_pcb *pcb, struct pbuf *p)
432 {
433   /* send to the packet using remote ip and port stored in the pcb */
434   return udp_sendto(pcb, p, ipX_2_ip(&pcb->remote_ip), pcb->remote_port);
435 }
436
437 #if LWIP_CHECKSUM_ON_COPY
438 /** Same as udp_send() but with checksum
439  */
440 err_t
441 udp_send_chksum(struct udp_pcb *pcb, struct pbuf *p,
442                 u8_t have_chksum, u16_t chksum)
443 {
444   /* send to the packet using remote ip and port stored in the pcb */
445   return udp_sendto_chksum(pcb, p, ipX_2_ip(&pcb->remote_ip), pcb->remote_port,
446     have_chksum, chksum);
447 }
448 #endif /* LWIP_CHECKSUM_ON_COPY */
449
450 /**
451  * Send data to a specified address using UDP.
452  *
453  * @param pcb UDP PCB used to send the data.
454  * @param p chain of pbuf's to be sent.
455  * @param dst_ip Destination IP address.
456  * @param dst_port Destination UDP port.
457  *
458  * dst_ip & dst_port are expected to be in the same byte order as in the pcb.
459  *
460  * If the PCB already has a remote address association, it will
461  * be restored after the data is sent.
462  * 
463  * @return lwIP error code (@see udp_send for possible error codes)
464  *
465  * @see udp_disconnect() udp_send()
466  */
467 err_t
468 udp_sendto(struct udp_pcb *pcb, struct pbuf *p,
469   ip_addr_t *dst_ip, u16_t dst_port)
470 {
471 #if LWIP_CHECKSUM_ON_COPY
472   return udp_sendto_chksum(pcb, p, dst_ip, dst_port, 0, 0);
473 }
474
475 /** Same as udp_sendto(), but with checksum */
476 err_t
477 udp_sendto_chksum(struct udp_pcb *pcb, struct pbuf *p, ip_addr_t *dst_ip,
478                   u16_t dst_port, u8_t have_chksum, u16_t chksum)
479 {
480 #endif /* LWIP_CHECKSUM_ON_COPY */
481   struct netif *netif;
482   ipX_addr_t *dst_ip_route = ip_2_ipX(dst_ip);
483
484   LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE, ("udp_send\n"));
485
486 #if LWIP_IPV6 || LWIP_IGMP
487   if (ipX_addr_ismulticast(PCB_ISIPV6(pcb), dst_ip_route)) {
488     /* For multicast, find a netif based on source address. */
489 #if LWIP_IPV6
490     if (PCB_ISIPV6(pcb)) {
491       dst_ip_route = &pcb->local_ip;
492     } else
493 #endif /* LWIP_IPV6 */
494     {
495 #if LWIP_IGMP
496       dst_ip_route = ip_2_ipX(&pcb->multicast_ip);
497 #endif /* LWIP_IGMP */
498     }
499   }
500 #endif /* LWIP_IPV6 || LWIP_IGMP */
501
502   /* find the outgoing network interface for this packet */
503   netif = ipX_route(PCB_ISIPV6(pcb), &pcb->local_ip, dst_ip_route);
504
505   /* no outgoing network interface could be found? */
506   if (netif == NULL) {
507     LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_LEVEL_SERIOUS, ("udp_send: No route to "));
508     ipX_addr_debug_print(PCB_ISIPV6(pcb), UDP_DEBUG | LWIP_DBG_LEVEL_SERIOUS, ip_2_ipX(dst_ip));
509     LWIP_DEBUGF(UDP_DEBUG, ("\n"));
510     UDP_STATS_INC(udp.rterr);
511     return ERR_RTE;
512   }
513 #if LWIP_CHECKSUM_ON_COPY
514   return udp_sendto_if_chksum(pcb, p, dst_ip, dst_port, netif, have_chksum, chksum);
515 #else /* LWIP_CHECKSUM_ON_COPY */
516   return udp_sendto_if(pcb, p, dst_ip, dst_port, netif);
517 #endif /* LWIP_CHECKSUM_ON_COPY */
518 }
519
520 /**
521  * Send data to a specified address using UDP.
522  * The netif used for sending can be specified.
523  *
524  * This function exists mainly for DHCP, to be able to send UDP packets
525  * on a netif that is still down.
526  *
527  * @param pcb UDP PCB used to send the data.
528  * @param p chain of pbuf's to be sent.
529  * @param dst_ip Destination IP address.
530  * @param dst_port Destination UDP port.
531  * @param netif the netif used for sending.
532  *
533  * dst_ip & dst_port are expected to be in the same byte order as in the pcb.
534  *
535  * @return lwIP error code (@see udp_send for possible error codes)
536  *
537  * @see udp_disconnect() udp_send()
538  */
539 err_t
540 udp_sendto_if(struct udp_pcb *pcb, struct pbuf *p,
541   ip_addr_t *dst_ip, u16_t dst_port, struct netif *netif)
542 {
543 #if LWIP_CHECKSUM_ON_COPY
544   return udp_sendto_if_chksum(pcb, p, dst_ip, dst_port, netif, 0, 0);
545 }
546
547 /** Same as udp_sendto_if(), but with checksum */
548 err_t
549 udp_sendto_if_chksum(struct udp_pcb *pcb, struct pbuf *p, ip_addr_t *dst_ip,
550                      u16_t dst_port, struct netif *netif, u8_t have_chksum,
551                      u16_t chksum)
552 {
553 #endif /* LWIP_CHECKSUM_ON_COPY */
554   struct udp_hdr *udphdr;
555   ip_addr_t *src_ip;
556   err_t err;
557   struct pbuf *q; /* q will be sent down the stack */
558   u8_t ip_proto;
559
560 #if IP_SOF_BROADCAST
561   /* broadcast filter? */
562   if ( ((pcb->so_options & SOF_BROADCAST) == 0) &&
563 #if LWIP_IPV6
564       !PCB_ISIPV6(pcb) &&
565 #endif /* LWIP_IPV6 */
566       ip_addr_isbroadcast(dst_ip, netif) ) {
567     LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_LEVEL_SERIOUS,
568       ("udp_sendto_if: SOF_BROADCAST not enabled on pcb %p\n", (void *)pcb));
569     return ERR_VAL;
570   }
571 #endif /* IP_SOF_BROADCAST */
572
573   /* if the PCB is not yet bound to a port, bind it here */
574   if (pcb->local_port == 0) {
575     LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE, ("udp_send: not yet bound to a port, binding now\n"));
576     err = udp_bind(pcb, ipX_2_ip(&pcb->local_ip), pcb->local_port);
577     if (err != ERR_OK) {
578       LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_LEVEL_SERIOUS, ("udp_send: forced port bind failed\n"));
579       return err;
580     }
581   }
582
583   /* not enough space to add an UDP header to first pbuf in given p chain? */
584   if (pbuf_header(p, UDP_HLEN)) {
585     /* allocate header in a separate new pbuf */
586     q = pbuf_alloc(PBUF_IP, UDP_HLEN, PBUF_RAM);
587     /* new header pbuf could not be allocated? */
588     if (q == NULL) {
589       LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_LEVEL_SERIOUS, ("udp_send: could not allocate header\n"));
590       return ERR_MEM;
591     }
592     if (p->tot_len != 0) {
593       /* chain header q in front of given pbuf p (only if p contains data) */
594       pbuf_chain(q, p);
595     }
596     /* first pbuf q points to header pbuf */
597     LWIP_DEBUGF(UDP_DEBUG,
598                 ("udp_send: added header pbuf %p before given pbuf %p\n", (void *)q, (void *)p));
599   } else {
600     /* adding space for header within p succeeded */
601     /* first pbuf q equals given pbuf */
602     q = p;
603     LWIP_DEBUGF(UDP_DEBUG, ("udp_send: added header in given pbuf %p\n", (void *)p));
604   }
605   LWIP_ASSERT("check that first pbuf can hold struct udp_hdr",
606               (q->len >= sizeof(struct udp_hdr)));
607   /* q now represents the packet to be sent */
608   udphdr = (struct udp_hdr *)q->payload;
609   udphdr->src = htons(pcb->local_port);
610   udphdr->dest = htons(dst_port);
611   /* in UDP, 0 checksum means 'no checksum' */
612   udphdr->chksum = 0x0000; 
613
614   /* Multicast Loop? */
615 #if LWIP_IGMP
616   if (((pcb->flags & UDP_FLAGS_MULTICAST_LOOP) != 0) &&
617 #if LWIP_IPV6
618       (
619 #if LWIP_IPV6_MLD
620        (PCB_ISIPV6(pcb) &&
621         ip6_addr_ismulticast(ip_2_ip6(dst_ip))) ||
622 #endif /* LWIP_IPV6_MLD */
623        (!PCB_ISIPV6(pcb) &&
624 #else /* LWIP_IPV6 */
625       ((
626 #endif /* LWIP_IPV6 */
627         ip_addr_ismulticast(dst_ip)))) {
628     q->flags |= PBUF_FLAG_MCASTLOOP;
629   }
630 #endif /* LWIP_IGMP */
631
632
633   /* PCB local address is IP_ANY_ADDR? */
634 #if LWIP_IPV6
635   if (PCB_ISIPV6(pcb)) {
636     if (ip6_addr_isany(ipX_2_ip6(&pcb->local_ip))) {
637       src_ip = ip6_2_ip(ip6_select_source_address(netif, ip_2_ip6(dst_ip)));
638       if (src_ip == NULL) {
639         /* No suitable source address was found. */
640         if (q != p) {
641           /* free the header pbuf */
642           pbuf_free(q);
643           /* p is still referenced by the caller, and will live on */
644         }
645         return ERR_RTE;
646       }
647     } else {
648       /* use UDP PCB local IPv6 address as source address, if still valid. */
649       if (netif_matches_ip6_addr(netif, ipX_2_ip6(&pcb->local_ip)) < 0) {
650         /* Address isn't valid anymore. */
651         if (q != p) {
652           /* free the header pbuf */
653           pbuf_free(q);
654           /* p is still referenced by the caller, and will live on */
655         }
656         return ERR_RTE;
657       }
658       src_ip = ipX_2_ip(&pcb->local_ip);
659     }
660   }
661   else
662 #endif /* LWIP_IPV6 */
663   if (ip_addr_isany(ipX_2_ip(&pcb->local_ip))) {
664     /* use outgoing network interface IP address as source address */
665     src_ip = &(netif->ip_addr);
666   } else {
667     /* check if UDP PCB local IP address is correct
668      * this could be an old address if netif->ip_addr has changed */
669     if (!ip_addr_cmp(ipX_2_ip(&(pcb->local_ip)), &(netif->ip_addr))) {
670       /* local_ip doesn't match, drop the packet */
671       if (q != p) {
672         /* free the header pbuf */
673         pbuf_free(q);
674         q = NULL;
675         /* p is still referenced by the caller, and will live on */
676       }
677       return ERR_VAL;
678     }
679     /* use UDP PCB local IP address as source address */
680     src_ip = ipX_2_ip(&(pcb->local_ip));
681   }
682
683   LWIP_DEBUGF(UDP_DEBUG, ("udp_send: sending datagram of length %"U16_F"\n", q->tot_len));
684
685 #if LWIP_UDPLITE
686   /* UDP Lite protocol? */
687   if (pcb->flags & UDP_FLAGS_UDPLITE) {
688     u16_t chklen, chklen_hdr;
689     LWIP_DEBUGF(UDP_DEBUG, ("udp_send: UDP LITE packet length %"U16_F"\n", q->tot_len));
690     /* set UDP message length in UDP header */
691     chklen_hdr = chklen = pcb->chksum_len_tx;
692     if ((chklen < sizeof(struct udp_hdr)) || (chklen > q->tot_len)) {
693       if (chklen != 0) {
694         LWIP_DEBUGF(UDP_DEBUG, ("udp_send: UDP LITE pcb->chksum_len is illegal: %"U16_F"\n", chklen));
695       }
696       /* For UDP-Lite, checksum length of 0 means checksum
697          over the complete packet. (See RFC 3828 chap. 3.1)
698          At least the UDP-Lite header must be covered by the
699          checksum, therefore, if chksum_len has an illegal
700          value, we generate the checksum over the complete
701          packet to be safe. */
702       chklen_hdr = 0;
703       chklen = q->tot_len;
704     }
705     udphdr->len = htons(chklen_hdr);
706     /* calculate checksum */
707 #if CHECKSUM_GEN_UDP
708 #if LWIP_CHECKSUM_ON_COPY
709     if (have_chksum) {
710       chklen = UDP_HLEN;
711     }
712 #endif /* LWIP_CHECKSUM_ON_COPY */
713     udphdr->chksum = ipX_chksum_pseudo_partial(PCB_ISIPV6(pcb), q, IP_PROTO_UDPLITE,
714       q->tot_len, chklen, ip_2_ipX(src_ip), ip_2_ipX(dst_ip));
715 #if LWIP_CHECKSUM_ON_COPY
716     if (have_chksum) {
717       u32_t acc;
718       acc = udphdr->chksum + (u16_t)~(chksum);
719       udphdr->chksum = FOLD_U32T(acc);
720     }
721 #endif /* LWIP_CHECKSUM_ON_COPY */
722
723     /* chksum zero must become 0xffff, as zero means 'no checksum' */
724     if (udphdr->chksum == 0x0000) {
725       udphdr->chksum = 0xffff;
726     }
727 #endif /* CHECKSUM_GEN_UDP */
728
729     ip_proto = IP_PROTO_UDPLITE;
730   } else
731 #endif /* LWIP_UDPLITE */
732   {      /* UDP */
733     LWIP_DEBUGF(UDP_DEBUG, ("udp_send: UDP packet length %"U16_F"\n", q->tot_len));
734     udphdr->len = htons(q->tot_len);
735     /* calculate checksum */
736 #if CHECKSUM_GEN_UDP
737     /* Checksum is mandatory over IPv6. */
738     if (PCB_ISIPV6(pcb) || (pcb->flags & UDP_FLAGS_NOCHKSUM) == 0) {
739       u16_t udpchksum;
740 #if LWIP_CHECKSUM_ON_COPY
741       if (have_chksum) {
742         u32_t acc;
743         udpchksum = ipX_chksum_pseudo_partial(PCB_ISIPV6(pcb), q, IP_PROTO_UDP,
744           q->tot_len, UDP_HLEN, ip_2_ipX(src_ip), ip_2_ipX(dst_ip));
745         acc = udpchksum + (u16_t)~(chksum);
746         udpchksum = FOLD_U32T(acc);
747       } else
748 #endif /* LWIP_CHECKSUM_ON_COPY */
749       {
750         udpchksum = ipX_chksum_pseudo(PCB_ISIPV6(pcb), q, IP_PROTO_UDP, q->tot_len,
751           ip_2_ipX(src_ip), ip_2_ipX(dst_ip));
752       }
753
754       /* chksum zero must become 0xffff, as zero means 'no checksum' */
755       if (udpchksum == 0x0000) {
756         udpchksum = 0xffff;
757       }
758       udphdr->chksum = udpchksum;
759     }
760 #endif /* CHECKSUM_GEN_UDP */
761     ip_proto = IP_PROTO_UDP;
762   }
763
764   LWIP_DEBUGF(UDP_DEBUG, ("udp_send: UDP checksum 0x%04"X16_F"\n", udphdr->chksum));
765   LWIP_DEBUGF(UDP_DEBUG, ("udp_send: ip_output_if (,,,,0x%02"X16_F",)\n", (u16_t)ip_proto));
766   /* output to IP */
767   NETIF_SET_HWADDRHINT(netif, &(pcb->addr_hint));
768   err = ipX_output_if(PCB_ISIPV6(pcb), q, src_ip, dst_ip, pcb->ttl, pcb->tos, ip_proto, netif);
769   NETIF_SET_HWADDRHINT(netif, NULL);
770
771   /* TODO: must this be increased even if error occured? */
772   snmp_inc_udpoutdatagrams();
773
774   /* did we chain a separate header pbuf earlier? */
775   if (q != p) {
776     /* free the header pbuf */
777     pbuf_free(q);
778     q = NULL;
779     /* p is still referenced by the caller, and will live on */
780   }
781
782   UDP_STATS_INC(udp.xmit);
783   return err;
784 }
785
786 /**
787  * Bind an UDP PCB.
788  *
789  * @param pcb UDP PCB to be bound with a local address ipaddr and port.
790  * @param ipaddr local IP address to bind with. Use IP_ADDR_ANY to
791  * bind to all local interfaces.
792  * @param port local UDP port to bind with. Use 0 to automatically bind
793  * to a random port between UDP_LOCAL_PORT_RANGE_START and
794  * UDP_LOCAL_PORT_RANGE_END.
795  *
796  * ipaddr & port are expected to be in the same byte order as in the pcb.
797  *
798  * @return lwIP error code.
799  * - ERR_OK. Successful. No error occured.
800  * - ERR_USE. The specified ipaddr and port are already bound to by
801  * another UDP PCB.
802  *
803  * @see udp_disconnect()
804  */
805 err_t
806 udp_bind(struct udp_pcb *pcb, ip_addr_t *ipaddr, u16_t port)
807 {
808   struct udp_pcb *ipcb;
809   u8_t rebind;
810
811   LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE, ("udp_bind(ipaddr = "));
812   ipX_addr_debug_print(PCB_ISIPV6(pcb), UDP_DEBUG | LWIP_DBG_TRACE, ip_2_ipX(ipaddr));
813   LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE, (", port = %"U16_F")\n", port));
814
815   rebind = 0;
816   /* Check for double bind and rebind of the same pcb */
817   for (ipcb = udp_pcbs; ipcb != NULL; ipcb = ipcb->next) {
818     /* is this UDP PCB already on active list? */
819     if (pcb == ipcb) {
820       /* pcb may occur at most once in active list */
821       LWIP_ASSERT("rebind == 0", rebind == 0);
822       /* pcb already in list, just rebind */
823       rebind = 1;
824     }
825
826     /* By default, we don't allow to bind to a port that any other udp
827        PCB is alread bound to, unless *all* PCBs with that port have tha
828        REUSEADDR flag set. */
829 #if SO_REUSE
830     else if (((pcb->so_options & SOF_REUSEADDR) == 0) &&
831              ((ipcb->so_options & SOF_REUSEADDR) == 0)) {
832 #else /* SO_REUSE */
833     /* port matches that of PCB in list and REUSEADDR not set -> reject */
834     else {
835 #endif /* SO_REUSE */
836       if ((ipcb->local_port == port) && IP_PCB_IPVER_EQ(pcb, ipcb) &&
837           /* IP address matches, or one is IP_ADDR_ANY? */
838             (ipX_addr_isany(PCB_ISIPV6(ipcb), &(ipcb->local_ip)) ||
839              ipX_addr_isany(PCB_ISIPV6(ipcb), ip_2_ipX(ipaddr)) ||
840              ipX_addr_cmp(PCB_ISIPV6(ipcb), &(ipcb->local_ip), ip_2_ipX(ipaddr)))) {
841         /* other PCB already binds to this local IP and port */
842         LWIP_DEBUGF(UDP_DEBUG,
843                     ("udp_bind: local port %"U16_F" already bound by another pcb\n", port));
844         return ERR_USE;
845       }
846     }
847   }
848
849   ipX_addr_set_ipaddr(PCB_ISIPV6(pcb), &pcb->local_ip, ipaddr);
850
851   /* no port specified? */
852   if (port == 0) {
853 #ifndef UDP_LOCAL_PORT_RANGE_START
854 /* From http://www.iana.org/assignments/port-numbers:
855    "The Dynamic and/or Private Ports are those from 49152 through 65535" */
856 #define UDP_LOCAL_PORT_RANGE_START  0xc000
857 #define UDP_LOCAL_PORT_RANGE_END    0xffff
858 #endif
859     port = UDP_LOCAL_PORT_RANGE_START;
860     ipcb = udp_pcbs;
861     while ((ipcb != NULL) && (port != UDP_LOCAL_PORT_RANGE_END)) {
862       if (ipcb->local_port == port) {
863         /* port is already used by another udp_pcb */
864         port++;
865         /* restart scanning all udp pcbs */
866         ipcb = udp_pcbs;
867       } else {
868         /* go on with next udp pcb */
869         ipcb = ipcb->next;
870       }
871     }
872     if (ipcb != NULL) {
873       /* no more ports available in local range */
874       LWIP_DEBUGF(UDP_DEBUG, ("udp_bind: out of free UDP ports\n"));
875       return ERR_USE;
876     }
877   }
878   pcb->local_port = port;
879   snmp_insert_udpidx_tree(pcb);
880   /* pcb not active yet? */
881   if (rebind == 0) {
882     /* place the PCB on the active list if not already there */
883     pcb->next = udp_pcbs;
884     udp_pcbs = pcb;
885   }
886   LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("udp_bind: bound to "));
887   ipX_addr_debug_print(PCB_ISIPV6(pcb), UDP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, &pcb->local_ip);
888   LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, (", port %"U16_F")\n", pcb->local_port));
889   return ERR_OK;
890 }
891
892 /**
893  * Connect an UDP PCB.
894  *
895  * This will associate the UDP PCB with the remote address.
896  *
897  * @param pcb UDP PCB to be connected with remote address ipaddr and port.
898  * @param ipaddr remote IP address to connect with.
899  * @param port remote UDP port to connect with.
900  *
901  * @return lwIP error code
902  *
903  * ipaddr & port are expected to be in the same byte order as in the pcb.
904  *
905  * The udp pcb is bound to a random local port if not already bound.
906  *
907  * @see udp_disconnect()
908  */
909 err_t
910 udp_connect(struct udp_pcb *pcb, ip_addr_t *ipaddr, u16_t port)
911 {
912   struct udp_pcb *ipcb;
913
914   if (pcb->local_port == 0) {
915     err_t err = udp_bind(pcb, ipX_2_ip(&pcb->local_ip), pcb->local_port);
916     if (err != ERR_OK) {
917       return err;
918     }
919   }
920
921   ipX_addr_set_ipaddr(PCB_ISIPV6(pcb), &pcb->remote_ip, ipaddr);
922   pcb->remote_port = port;
923   pcb->flags |= UDP_FLAGS_CONNECTED;
924 /** TODO: this functionality belongs in upper layers */
925 #ifdef LWIP_UDP_TODO
926 #if LWIP_IPV6
927   if (!PCB_ISIPV6(pcb))
928 #endif /* LWIP_IPV6 */
929   {
930     /* Nail down local IP for netconn_addr()/getsockname() */
931     if (ip_addr_isany(ipX_2_ip(&pcb->local_ip)) && !ip_addr_isany(ipX_2_ip(&pcb->remote_ip))) {
932       struct netif *netif;
933
934       if ((netif = ip_route(ipX_2_ip(&pcb->remote_ip))) == NULL) {
935         LWIP_DEBUGF(UDP_DEBUG, ("udp_connect: No route to 0x%lx\n",
936                     ip4_addr_get_u32(ipX_2_ip(&pcb->remote_ip))));
937         UDP_STATS_INC(udp.rterr);
938         return ERR_RTE;
939       }
940       /** TODO: this will bind the udp pcb locally, to the interface which
941           is used to route output packets to the remote address. However, we
942           might want to accept incoming packets on any interface! */
943       ipX_addr_copy(0, pcb->local_ip, netif->ip_addr);
944     } else if (ip_addr_isany(ipX_2_ip(&pcb->remote_ip))) {
945       ipX_addr_set_any(0, &pcb->local_ip);
946     }
947   }
948 #endif
949   LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("udp_connect: connected to "));
950   ipX_addr_debug_print(PCB_ISIPV6(pcb), UDP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE,
951                        &pcb->remote_ip);
952   LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, (", port %"U16_F")\n", pcb->remote_port));
953
954   /* Insert UDP PCB into the list of active UDP PCBs. */
955   for (ipcb = udp_pcbs; ipcb != NULL; ipcb = ipcb->next) {
956     if (pcb == ipcb) {
957       /* already on the list, just return */
958       return ERR_OK;
959     }
960   }
961   /* PCB not yet on the list, add PCB now */
962   pcb->next = udp_pcbs;
963   udp_pcbs = pcb;
964   return ERR_OK;
965 }
966
967 /**
968  * Disconnect a UDP PCB
969  *
970  * @param pcb the udp pcb to disconnect.
971  */
972 void
973 udp_disconnect(struct udp_pcb *pcb)
974 {
975   /* reset remote address association */
976   ipX_addr_set_any(PCB_ISIPV6(pcb), &pcb->remote_ip);
977   pcb->remote_port = 0;
978   /* mark PCB as unconnected */
979   pcb->flags &= ~UDP_FLAGS_CONNECTED;
980 }
981
982 /**
983  * Set a receive callback for a UDP PCB
984  *
985  * This callback will be called when receiving a datagram for the pcb.
986  *
987  * @param pcb the pcb for wich to set the recv callback
988  * @param recv function pointer of the callback function
989  * @param recv_arg additional argument to pass to the callback function
990  */
991 void
992 udp_recv(struct udp_pcb *pcb, udp_recv_fn recv, void *recv_arg)
993 {
994   /* remember recv() callback and user data */
995   pcb->recv.ip4 = recv;
996   pcb->recv_arg = recv_arg;
997 }
998
999 /**
1000  * Remove an UDP PCB.
1001  *
1002  * @param pcb UDP PCB to be removed. The PCB is removed from the list of
1003  * UDP PCB's and the data structure is freed from memory.
1004  *
1005  * @see udp_new()
1006  */
1007 void
1008 udp_remove(struct udp_pcb *pcb)
1009 {
1010   struct udp_pcb *pcb2;
1011
1012   snmp_delete_udpidx_tree(pcb);
1013   /* pcb to be removed is first in list? */
1014   if (udp_pcbs == pcb) {
1015     /* make list start at 2nd pcb */
1016     udp_pcbs = udp_pcbs->next;
1017     /* pcb not 1st in list */
1018   } else {
1019     for (pcb2 = udp_pcbs; pcb2 != NULL; pcb2 = pcb2->next) {
1020       /* find pcb in udp_pcbs list */
1021       if (pcb2->next != NULL && pcb2->next == pcb) {
1022         /* remove pcb from list */
1023         pcb2->next = pcb->next;
1024       }
1025     }
1026   }
1027   memp_free(MEMP_UDP_PCB, pcb);
1028 }
1029
1030 /**
1031  * Create a UDP PCB.
1032  *
1033  * @return The UDP PCB which was created. NULL if the PCB data structure
1034  * could not be allocated.
1035  *
1036  * @see udp_remove()
1037  */
1038 struct udp_pcb *
1039 udp_new(void)
1040 {
1041   struct udp_pcb *pcb;
1042   pcb = (struct udp_pcb *)memp_malloc(MEMP_UDP_PCB);
1043   /* could allocate UDP PCB? */
1044   if (pcb != NULL) {
1045     /* UDP Lite: by initializing to all zeroes, chksum_len is set to 0
1046      * which means checksum is generated over the whole datagram per default
1047      * (recommended as default by RFC 3828). */
1048     /* initialize PCB to all zeroes */
1049     memset(pcb, 0, sizeof(struct udp_pcb));
1050     pcb->ttl = UDP_TTL;
1051   }
1052   return pcb;
1053 }
1054
1055 #if LWIP_IPV6
1056 /**
1057  * Create a UDP PCB for IPv6.
1058  *
1059  * @return The UDP PCB which was created. NULL if the PCB data structure
1060  * could not be allocated.
1061  *
1062  * @see udp_remove()
1063  */
1064 struct udp_pcb *
1065 udp_new_ip6(void)
1066 {
1067   struct udp_pcb *pcb;
1068   pcb = udp_new();
1069   ip_set_v6(pcb, 1);
1070   return pcb;
1071 }
1072 #endif /* LWIP_IPV6 */
1073
1074 #if UDP_DEBUG
1075 /**
1076  * Print UDP header information for debug purposes.
1077  *
1078  * @param udphdr pointer to the udp header in memory.
1079  */
1080 void
1081 udp_debug_print(struct udp_hdr *udphdr)
1082 {
1083   LWIP_DEBUGF(UDP_DEBUG, ("UDP header:\n"));
1084   LWIP_DEBUGF(UDP_DEBUG, ("+-------------------------------+\n"));
1085   LWIP_DEBUGF(UDP_DEBUG, ("|     %5"U16_F"     |     %5"U16_F"     | (src port, dest port)\n",
1086                           ntohs(udphdr->src), ntohs(udphdr->dest)));
1087   LWIP_DEBUGF(UDP_DEBUG, ("+-------------------------------+\n"));
1088   LWIP_DEBUGF(UDP_DEBUG, ("|     %5"U16_F"     |     0x%04"X16_F"    | (len, chksum)\n",
1089                           ntohs(udphdr->len), ntohs(udphdr->chksum)));
1090   LWIP_DEBUGF(UDP_DEBUG, ("+-------------------------------+\n"));
1091 }
1092 #endif /* UDP_DEBUG */
1093
1094 #endif /* LWIP_UDP */