ReactOS 0.4.16-dev-550-g2186ce3
udp.c
Go to the documentation of this file.
1
13/*
14 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
15 * All rights reserved.
16 *
17 * Redistribution and use in source and binary forms, with or without modification,
18 * are permitted provided that the following conditions are met:
19 *
20 * 1. Redistributions of source code must retain the above copyright notice,
21 * this list of conditions and the following disclaimer.
22 * 2. Redistributions in binary form must reproduce the above copyright notice,
23 * this list of conditions and the following disclaimer in the documentation
24 * and/or other materials provided with the distribution.
25 * 3. The name of the author may not be used to endorse or promote products
26 * derived from this software without specific prior written permission.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
29 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
30 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
31 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
32 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
33 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
36 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
37 * OF SUCH DAMAGE.
38 *
39 * This file is part of the lwIP TCP/IP stack.
40 *
41 * Author: Adam Dunkels <adam@sics.se>
42 *
43 */
44
45/* @todo Check the use of '(struct udp_pcb).chksum_len_rx'!
46 */
47
48#include "lwip/opt.h"
49
50#if LWIP_UDP /* don't build if not configured for use in lwipopts.h */
51
52#include "lwip/udp.h"
53#include "lwip/def.h"
54#include "lwip/memp.h"
55#include "lwip/inet_chksum.h"
56#include "lwip/ip_addr.h"
57#include "lwip/ip6.h"
58#include "lwip/ip6_addr.h"
59#include "lwip/netif.h"
60#include "lwip/icmp.h"
61#include "lwip/icmp6.h"
62#include "lwip/stats.h"
63#include "lwip/snmp.h"
64#include "lwip/dhcp.h"
65
66#include <string.h>
67
68#ifndef UDP_LOCAL_PORT_RANGE_START
69/* From http://www.iana.org/assignments/port-numbers:
70 "The Dynamic and/or Private Ports are those from 49152 through 65535" */
71#define UDP_LOCAL_PORT_RANGE_START 0xc000
72#define UDP_LOCAL_PORT_RANGE_END 0xffff
73#define UDP_ENSURE_LOCAL_PORT_RANGE(port) ((u16_t)(((port) & (u16_t)~UDP_LOCAL_PORT_RANGE_START) + UDP_LOCAL_PORT_RANGE_START))
74#endif
75
76/* last local UDP port */
77static u16_t udp_port = UDP_LOCAL_PORT_RANGE_START;
78
79/* The list of UDP PCBs */
80/* exported in udp.h (was static) */
81struct udp_pcb *udp_pcbs;
82
86void
87udp_init(void)
88{
89#ifdef LWIP_RAND
90 udp_port = UDP_ENSURE_LOCAL_PORT_RANGE(LWIP_RAND());
91#endif /* LWIP_RAND */
92}
93
99static u16_t
100udp_new_port(void)
101{
102 u16_t n = 0;
103 struct udp_pcb *pcb;
104
105again:
106 if (udp_port++ == UDP_LOCAL_PORT_RANGE_END) {
107 udp_port = UDP_LOCAL_PORT_RANGE_START;
108 }
109 /* Check all PCBs. */
110 for (pcb = udp_pcbs; pcb != NULL; pcb = pcb->next) {
111 if (pcb->local_port == udp_port) {
112 if (++n > (UDP_LOCAL_PORT_RANGE_END - UDP_LOCAL_PORT_RANGE_START)) {
113 return 0;
114 }
115 goto again;
116 }
117 }
118 return udp_port;
119}
120
129static u8_t
130udp_input_local_match(struct udp_pcb *pcb, struct netif *inp, u8_t broadcast)
131{
132 LWIP_UNUSED_ARG(inp); /* in IPv6 only case */
133 LWIP_UNUSED_ARG(broadcast); /* in IPv6 only case */
134
135 LWIP_ASSERT("udp_input_local_match: invalid pcb", pcb != NULL);
136 LWIP_ASSERT("udp_input_local_match: invalid netif", inp != NULL);
137
138 /* check if PCB is bound to specific netif */
139 if ((pcb->netif_idx != NETIF_NO_INDEX) &&
140 (pcb->netif_idx != netif_get_index(ip_data.current_input_netif))) {
141 return 0;
142 }
143
144 /* Dual-stack: PCBs listening to any IP type also listen to any IP address */
145 if (IP_IS_ANY_TYPE_VAL(pcb->local_ip)) {
146#if LWIP_IPV4 && IP_SOF_BROADCAST_RECV
147 if ((broadcast != 0) && !ip_get_option(pcb, SOF_BROADCAST)) {
148 return 0;
149 }
150#endif /* LWIP_IPV4 && IP_SOF_BROADCAST_RECV */
151 return 1;
152 }
153
154 /* Only need to check PCB if incoming IP version matches PCB IP version */
156#if LWIP_IPV4
157 /* Special case: IPv4 broadcast: all or broadcasts in my subnet
158 * Note: broadcast variable can only be 1 if it is an IPv4 broadcast */
159 if (broadcast != 0) {
160#if IP_SOF_BROADCAST_RECV
162#endif /* IP_SOF_BROADCAST_RECV */
163 {
164 if (ip4_addr_isany(ip_2_ip4(&pcb->local_ip)) ||
165 ((ip4_current_dest_addr()->addr == IPADDR_BROADCAST)) ||
166 ip4_addr_net_eq(ip_2_ip4(&pcb->local_ip), ip4_current_dest_addr(), netif_ip4_netmask(inp))) {
167 return 1;
168 }
169 }
170 } else
171#endif /* LWIP_IPV4 */
172 /* Handle IPv4 and IPv6: all or exact match */
173 if (ip_addr_isany(&pcb->local_ip) || ip_addr_eq(&pcb->local_ip, ip_current_dest_addr())) {
174 return 1;
175 }
176 }
177
178 return 0;
179}
180
193void
194udp_input(struct pbuf *p, struct netif *inp)
195{
196 struct udp_hdr *udphdr;
197 struct udp_pcb *pcb, *prev;
198 struct udp_pcb *uncon_pcb;
199 u16_t src, dest;
201 u8_t for_us = 0;
202
203 LWIP_UNUSED_ARG(inp);
204
206
207 LWIP_ASSERT("udp_input: invalid pbuf", p != NULL);
208 LWIP_ASSERT("udp_input: invalid netif", inp != NULL);
209
211
212 UDP_STATS_INC(udp.recv);
213
214 /* Check minimum length (UDP header) */
215 if (p->len < UDP_HLEN) {
216 /* drop short packets */
218 ("udp_input: short UDP datagram (%"U16_F" bytes) discarded\n", p->tot_len));
219 UDP_STATS_INC(udp.lenerr);
220 UDP_STATS_INC(udp.drop);
221 MIB2_STATS_INC(mib2.udpinerrors);
222 pbuf_free(p);
223 goto end;
224 }
225
226 udphdr = (struct udp_hdr *)p->payload;
227
228 /* is broadcast packet ? */
230
231 LWIP_DEBUGF(UDP_DEBUG, ("udp_input: received datagram of length %"U16_F"\n", p->tot_len));
232
233 /* convert src and dest ports to host byte order */
234 src = lwip_ntohs(udphdr->src);
235 dest = lwip_ntohs(udphdr->dest);
236
237 udp_debug_print(udphdr);
238
239 /* print the UDP source and destination */
240 LWIP_DEBUGF(UDP_DEBUG, ("udp ("));
242 LWIP_DEBUGF(UDP_DEBUG, (", %"U16_F") <-- (", lwip_ntohs(udphdr->dest)));
244 LWIP_DEBUGF(UDP_DEBUG, (", %"U16_F")\n", lwip_ntohs(udphdr->src)));
245
246 pcb = NULL;
247 prev = NULL;
248 uncon_pcb = NULL;
249 /* Iterate through the UDP pcb list for a matching pcb.
250 * 'Perfect match' pcbs (connected to the remote port & ip address) are
251 * preferred. If no perfect match is found, the first unconnected pcb that
252 * matches the local port and ip address gets the datagram. */
253 for (pcb = udp_pcbs; pcb != NULL; pcb = pcb->next) {
254 /* print the PCB local and remote address */
255 LWIP_DEBUGF(UDP_DEBUG, ("pcb ("));
256 ip_addr_debug_print_val(UDP_DEBUG, pcb->local_ip);
257 LWIP_DEBUGF(UDP_DEBUG, (", %"U16_F") <-- (", pcb->local_port));
258 ip_addr_debug_print_val(UDP_DEBUG, pcb->remote_ip);
259 LWIP_DEBUGF(UDP_DEBUG, (", %"U16_F")\n", pcb->remote_port));
260
261 /* compare PCB local addr+port to UDP destination addr+port */
262 if ((pcb->local_port == dest) &&
263 (udp_input_local_match(pcb, inp, broadcast) != 0)) {
264 if ((pcb->flags & UDP_FLAGS_CONNECTED) == 0) {
265 if (uncon_pcb == NULL) {
266 /* the first unconnected matching PCB */
267 uncon_pcb = pcb;
268#if LWIP_IPV4
269 } else if (broadcast && ip4_current_dest_addr()->addr == IPADDR_BROADCAST) {
270 /* global broadcast address (only valid for IPv4; match was checked before) */
271 if (!IP_IS_V4_VAL(uncon_pcb->local_ip) || !ip4_addr_eq(ip_2_ip4(&uncon_pcb->local_ip), netif_ip4_addr(inp))) {
272 /* uncon_pcb does not match the input netif, check this pcb */
273 if (IP_IS_V4_VAL(pcb->local_ip) && ip4_addr_eq(ip_2_ip4(&pcb->local_ip), netif_ip4_addr(inp))) {
274 /* better match */
275 uncon_pcb = pcb;
276 }
277 }
278#endif /* LWIP_IPV4 */
279 }
280#if SO_REUSE
281 else if (!ip_addr_isany(&pcb->local_ip)) {
282 /* prefer specific IPs over catch-all */
283 uncon_pcb = pcb;
284 }
285#endif /* SO_REUSE */
286 }
287
288 /* compare PCB remote addr+port to UDP source addr+port */
289 if ((pcb->remote_port == src) &&
290 (ip_addr_isany_val(pcb->remote_ip) ||
291 ip_addr_eq(&pcb->remote_ip, ip_current_src_addr()))) {
292 /* the first fully matching PCB */
293 if (prev != NULL) {
294 /* move the pcb to the front of udp_pcbs so that is
295 found faster next time */
296 prev->next = pcb->next;
297 pcb->next = udp_pcbs;
298 udp_pcbs = pcb;
299 } else {
300 UDP_STATS_INC(udp.cachehit);
301 }
302 break;
303 }
304 }
305
306 prev = pcb;
307 }
308 /* no fully matching pcb found? then look for an unconnected pcb */
309 if (pcb == NULL) {
310 pcb = uncon_pcb;
311 }
312
313 /* Check checksum if this is a match or if it was directed at us. */
314 if (pcb != NULL) {
315 for_us = 1;
316 } else {
317#if LWIP_IPV6
318 if (ip_current_is_v6()) {
319 for_us = netif_get_ip6_addr_match(inp, ip6_current_dest_addr()) >= 0;
320 }
321#endif /* LWIP_IPV6 */
322#if LWIP_IPV4
323 if (!ip_current_is_v6()) {
324 for_us = ip4_addr_eq(netif_ip4_addr(inp), ip4_current_dest_addr());
325 }
326#endif /* LWIP_IPV4 */
327 }
328
329 if (for_us) {
330 LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE, ("udp_input: calculating checksum\n"));
331#if CHECKSUM_CHECK_UDP
332 IF__NETIF_CHECKSUM_ENABLED(inp, NETIF_CHECKSUM_CHECK_UDP) {
333#if LWIP_UDPLITE
334 if (ip_current_header_proto() == IP_PROTO_UDPLITE) {
335 /* Do the UDP Lite checksum */
336 u16_t chklen = lwip_ntohs(udphdr->len);
337 if (chklen < sizeof(struct udp_hdr)) {
338 if (chklen == 0) {
339 /* For UDP-Lite, checksum length of 0 means checksum
340 over the complete packet (See RFC 3828 chap. 3.1) */
341 chklen = p->tot_len;
342 } else {
343 /* At least the UDP-Lite header must be covered by the
344 checksum! (Again, see RFC 3828 chap. 3.1) */
345 goto chkerr;
346 }
347 }
349 p->tot_len, chklen,
351 goto chkerr;
352 }
353 } else
354#endif /* LWIP_UDPLITE */
355 {
356 if (udphdr->chksum != 0) {
357 if (ip_chksum_pseudo(p, IP_PROTO_UDP, p->tot_len,
359 ip_current_dest_addr()) != 0) {
360 goto chkerr;
361 }
362 }
363 }
364 }
365#endif /* CHECKSUM_CHECK_UDP */
367 /* Can we cope with this failing? Just assert for now */
368 LWIP_ASSERT("pbuf_remove_header failed", 0);
369 UDP_STATS_INC(udp.drop);
370 MIB2_STATS_INC(mib2.udpinerrors);
371 pbuf_free(p);
372 goto end;
373 }
374
375 if (pcb != NULL) {
376 MIB2_STATS_INC(mib2.udpindatagrams);
377#if SO_REUSE && SO_REUSE_RXTOALL
378 if (ip_get_option(pcb, SOF_REUSEADDR) &&
380 /* pass broadcast- or multicast packets to all multicast pcbs
381 if SOF_REUSEADDR is set on the first match */
382 struct udp_pcb *mpcb;
383 for (mpcb = udp_pcbs; mpcb != NULL; mpcb = mpcb->next) {
384 if (mpcb != pcb) {
385 /* compare PCB local addr+port to UDP destination addr+port */
386 if ((mpcb->local_port == dest) &&
387 (udp_input_local_match(mpcb, inp, broadcast) != 0)) {
388 /* pass a copy of the packet to all local matches */
389 if (mpcb->recv != NULL) {
390 struct pbuf *q;
392 if (q != NULL) {
393 mpcb->recv(mpcb->recv_arg, mpcb, q, ip_current_src_addr(), src);
394 }
395 }
396 }
397 }
398 }
399 }
400#endif /* SO_REUSE && SO_REUSE_RXTOALL */
401 /* callback */
402 if (pcb->recv != NULL) {
403 /* now the recv function is responsible for freeing p */
404 pcb->recv(pcb->recv_arg, pcb, p, ip_current_src_addr(), src);
405 } else {
406 /* no recv function registered? then we have to free the pbuf! */
407 pbuf_free(p);
408 goto end;
409 }
410 } else {
411 LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE, ("udp_input: not for us.\n"));
412
413#if LWIP_ICMP || LWIP_ICMP6
414 /* No match was found, send ICMP destination port unreachable unless
415 destination address was broadcast/multicast. */
417 /* move payload pointer back to ip header */
419 icmp_port_unreach(ip_current_is_v6(), p);
420 }
421#endif /* LWIP_ICMP || LWIP_ICMP6 */
422 UDP_STATS_INC(udp.proterr);
423 UDP_STATS_INC(udp.drop);
424 MIB2_STATS_INC(mib2.udpnoports);
425 pbuf_free(p);
426 }
427 } else {
428 pbuf_free(p);
429 }
430end:
431 PERF_STOP("udp_input");
432 return;
433#if CHECKSUM_CHECK_UDP
434chkerr:
436 ("udp_input: UDP (or UDP Lite) datagram discarded due to failing checksum\n"));
437 UDP_STATS_INC(udp.chkerr);
438 UDP_STATS_INC(udp.drop);
439 MIB2_STATS_INC(mib2.udpinerrors);
440 pbuf_free(p);
441 PERF_STOP("udp_input");
442#endif /* CHECKSUM_CHECK_UDP */
443}
444
466err_t
467udp_send(struct udp_pcb *pcb, struct pbuf *p)
468{
469 LWIP_ERROR("udp_send: invalid pcb", pcb != NULL, return ERR_ARG);
470 LWIP_ERROR("udp_send: invalid pbuf", p != NULL, return ERR_ARG);
471
472 if (IP_IS_ANY_TYPE_VAL(pcb->remote_ip)) {
473 return ERR_VAL;
474 }
475
476 /* send to the packet using remote ip and port stored in the pcb */
477 return udp_sendto(pcb, p, &pcb->remote_ip, pcb->remote_port);
478}
479
480#if LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP
484err_t
485udp_send_chksum(struct udp_pcb *pcb, struct pbuf *p,
486 u8_t have_chksum, u16_t chksum)
487{
488 LWIP_ERROR("udp_send_chksum: invalid pcb", pcb != NULL, return ERR_ARG);
489 LWIP_ERROR("udp_send_chksum: invalid pbuf", p != NULL, return ERR_ARG);
490
491 if (IP_IS_ANY_TYPE_VAL(pcb->remote_ip)) {
492 return ERR_VAL;
493 }
494
495 /* send to the packet using remote ip and port stored in the pcb */
496 return udp_sendto_chksum(pcb, p, &pcb->remote_ip, pcb->remote_port,
497 have_chksum, chksum);
498}
499#endif /* LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP */
500
519err_t
520udp_sendto(struct udp_pcb *pcb, struct pbuf *p,
521 const ip_addr_t *dst_ip, u16_t dst_port)
522{
523#if LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP
524 return udp_sendto_chksum(pcb, p, dst_ip, dst_port, 0, 0);
525}
526
529err_t
530udp_sendto_chksum(struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *dst_ip,
531 u16_t dst_port, u8_t have_chksum, u16_t chksum)
532{
533#endif /* LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP */
534 struct netif *netif;
535
536 LWIP_ERROR("udp_sendto: invalid pcb", pcb != NULL, return ERR_ARG);
537 LWIP_ERROR("udp_sendto: invalid pbuf", p != NULL, return ERR_ARG);
538 LWIP_ERROR("udp_sendto: invalid dst_ip", dst_ip != NULL, return ERR_ARG);
539
540 if (!IP_ADDR_PCB_VERSION_MATCH(pcb, dst_ip)) {
541 return ERR_VAL;
542 }
543
544 LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE, ("udp_send\n"));
545
546 if (pcb->netif_idx != NETIF_NO_INDEX) {
547 netif = netif_get_by_index(pcb->netif_idx);
548 } else {
549#if LWIP_MULTICAST_TX_OPTIONS
550 netif = NULL;
551 if (ip_addr_ismulticast(dst_ip)) {
552 /* For IPv6, the interface to use for packets with a multicast destination
553 * is specified using an interface index. The same approach may be used for
554 * IPv4 as well, in which case it overrides the IPv4 multicast override
555 * address below. Here we have to look up the netif by going through the
556 * list, but by doing so we skip a route lookup. If the interface index has
557 * gone stale, we fall through and do the regular route lookup after all. */
558 if (pcb->mcast_ifindex != NETIF_NO_INDEX) {
559 netif = netif_get_by_index(pcb->mcast_ifindex);
560 }
561#if LWIP_IPV4
562 else
563#if LWIP_IPV6
564 if (IP_IS_V4(dst_ip))
565#endif /* LWIP_IPV6 */
566 {
567 /* IPv4 does not use source-based routing by default, so we use an
568 administratively selected interface for multicast by default.
569 However, this can be overridden by setting an interface address
570 in pcb->mcast_ip4 that is used for routing. If this routing lookup
571 fails, we try regular routing as though no override was set. */
572 if (!ip4_addr_isany_val(pcb->mcast_ip4) &&
573 !ip4_addr_eq(&pcb->mcast_ip4, IP4_ADDR_BROADCAST)) {
574 netif = ip4_route_src(ip_2_ip4(&pcb->local_ip), &pcb->mcast_ip4);
575 }
576 }
577#endif /* LWIP_IPV4 */
578 }
579
580 if (netif == NULL)
581#endif /* LWIP_MULTICAST_TX_OPTIONS */
582 {
583 /* find the outgoing network interface for this packet */
584 netif = ip_route(&pcb->local_ip, dst_ip);
585 }
586 }
587
588 /* no outgoing network interface could be found? */
589 if (netif == NULL) {
590 LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_LEVEL_SERIOUS, ("udp_send: No route to "));
592 LWIP_DEBUGF(UDP_DEBUG, ("\n"));
593 UDP_STATS_INC(udp.rterr);
594 return ERR_RTE;
595 }
596#if LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP
597 return udp_sendto_if_chksum(pcb, p, dst_ip, dst_port, netif, have_chksum, chksum);
598#else /* LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP */
599 return udp_sendto_if(pcb, p, dst_ip, dst_port, netif);
600#endif /* LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP */
601}
602
623err_t
624udp_sendto_if(struct udp_pcb *pcb, struct pbuf *p,
625 const ip_addr_t *dst_ip, u16_t dst_port, struct netif *netif)
626{
627#if LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP
628 return udp_sendto_if_chksum(pcb, p, dst_ip, dst_port, netif, 0, 0);
629}
630
632err_t
633udp_sendto_if_chksum(struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *dst_ip,
634 u16_t dst_port, struct netif *netif, u8_t have_chksum,
635 u16_t chksum)
636{
637#endif /* LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP */
638 const ip_addr_t *src_ip;
639
640 LWIP_ERROR("udp_sendto_if: invalid pcb", pcb != NULL, return ERR_ARG);
641 LWIP_ERROR("udp_sendto_if: invalid pbuf", p != NULL, return ERR_ARG);
642 LWIP_ERROR("udp_sendto_if: invalid dst_ip", dst_ip != NULL, return ERR_ARG);
643 LWIP_ERROR("udp_sendto_if: invalid netif", netif != NULL, return ERR_ARG);
644
645 if (!IP_ADDR_PCB_VERSION_MATCH(pcb, dst_ip)) {
646 return ERR_VAL;
647 }
648
649 /* PCB local address is IP_ANY_ADDR or multicast? */
650#if LWIP_IPV6
651 if (IP_IS_V6(dst_ip)) {
652 if (ip6_addr_isany(ip_2_ip6(&pcb->local_ip)) ||
653 ip6_addr_ismulticast(ip_2_ip6(&pcb->local_ip))) {
654 src_ip = ip6_select_source_address(netif, ip_2_ip6(dst_ip));
655 if (src_ip == NULL) {
656 /* No suitable source address was found. */
657 return ERR_RTE;
658 }
659 } else {
660 /* use UDP PCB local IPv6 address as source address, if still valid. */
661 if (netif_get_ip6_addr_match(netif, ip_2_ip6(&pcb->local_ip)) < 0) {
662 /* Address isn't valid anymore. */
663 return ERR_RTE;
664 }
665 src_ip = &pcb->local_ip;
666 }
667 }
668#endif /* LWIP_IPV6 */
669#if LWIP_IPV4 && LWIP_IPV6
670 else
671#endif /* LWIP_IPV4 && LWIP_IPV6 */
672#if LWIP_IPV4
673 if (ip4_addr_isany(ip_2_ip4(&pcb->local_ip)) ||
674 ip4_addr_ismulticast(ip_2_ip4(&pcb->local_ip))) {
675 /* if the local_ip is any or multicast
676 * use the outgoing network interface IP address as source address */
677 src_ip = netif_ip_addr4(netif);
678 } else {
679 /* check if UDP PCB local IP address is correct
680 * this could be an old address if netif->ip_addr has changed */
681 if (!ip4_addr_eq(ip_2_ip4(&(pcb->local_ip)), netif_ip4_addr(netif))) {
682 /* local_ip doesn't match, drop the packet */
683 return ERR_RTE;
684 }
685 /* use UDP PCB local IP address as source address */
686 src_ip = &pcb->local_ip;
687 }
688#endif /* LWIP_IPV4 */
689#if LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP
690 return udp_sendto_if_src_chksum(pcb, p, dst_ip, dst_port, netif, have_chksum, chksum, src_ip);
691#else /* LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP */
692 return udp_sendto_if_src(pcb, p, dst_ip, dst_port, netif, src_ip);
693#endif /* LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP */
694}
695
698err_t
699udp_sendto_if_src(struct udp_pcb *pcb, struct pbuf *p,
700 const ip_addr_t *dst_ip, u16_t dst_port, struct netif *netif, const ip_addr_t *src_ip)
701{
702#if LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP
703 return udp_sendto_if_src_chksum(pcb, p, dst_ip, dst_port, netif, 0, 0, src_ip);
704}
705
707err_t
708udp_sendto_if_src_chksum(struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *dst_ip,
709 u16_t dst_port, struct netif *netif, u8_t have_chksum,
710 u16_t chksum, const ip_addr_t *src_ip)
711{
712#endif /* LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP */
713 struct udp_hdr *udphdr;
714 err_t err;
715 struct pbuf *q; /* q will be sent down the stack */
716 u8_t ip_proto;
717 u8_t ttl;
718
720
721 LWIP_ERROR("udp_sendto_if_src: invalid pcb", pcb != NULL, return ERR_ARG);
722 LWIP_ERROR("udp_sendto_if_src: invalid pbuf", p != NULL, return ERR_ARG);
723 LWIP_ERROR("udp_sendto_if_src: invalid dst_ip", dst_ip != NULL, return ERR_ARG);
724 LWIP_ERROR("udp_sendto_if_src: invalid src_ip", src_ip != NULL, return ERR_ARG);
725 LWIP_ERROR("udp_sendto_if_src: invalid netif", netif != NULL, return ERR_ARG);
726
727 if (!IP_ADDR_PCB_VERSION_MATCH(pcb, src_ip) ||
728 !IP_ADDR_PCB_VERSION_MATCH(pcb, dst_ip)) {
729 return ERR_VAL;
730 }
731
732#if LWIP_IPV4 && IP_SOF_BROADCAST
733 /* broadcast filter? */
734 if (!ip_get_option(pcb, SOF_BROADCAST) &&
735#if LWIP_IPV6
736 IP_IS_V4(dst_ip) &&
737#endif /* LWIP_IPV6 */
738 ip_addr_isbroadcast(dst_ip, netif)) {
740 ("udp_sendto_if: SOF_BROADCAST not enabled on pcb %p\n", (void *)pcb));
741 return ERR_VAL;
742 }
743#endif /* LWIP_IPV4 && IP_SOF_BROADCAST */
744
745 /* if the PCB is not yet bound to a port, bind it here */
746 if (pcb->local_port == 0) {
747 LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE, ("udp_send: not yet bound to a port, binding now\n"));
748 err = udp_bind(pcb, &pcb->local_ip, pcb->local_port);
749 if (err != ERR_OK) {
750 LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_LEVEL_SERIOUS, ("udp_send: forced port bind failed\n"));
751 return err;
752 }
753 }
754
755 /* packet too large to add a UDP header without causing an overflow? */
756 if ((u16_t)(p->tot_len + UDP_HLEN) < p->tot_len) {
757 return ERR_MEM;
758 }
759 /* not enough space to add an UDP header to first pbuf in given p chain? */
760 if (pbuf_add_header(p, UDP_HLEN)) {
761 /* allocate header in a separate new pbuf */
763 /* new header pbuf could not be allocated? */
764 if (q == NULL) {
765 LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_LEVEL_SERIOUS, ("udp_send: could not allocate header\n"));
766 return ERR_MEM;
767 }
768 if (p->tot_len != 0) {
769 /* chain header q in front of given pbuf p (only if p contains data) */
770 pbuf_chain(q, p);
771 }
772 /* first pbuf q points to header pbuf */
774 ("udp_send: added header pbuf %p before given pbuf %p\n", (void *)q, (void *)p));
775 } else {
776 /* adding space for header within p succeeded */
777 /* first pbuf q equals given pbuf */
778 q = p;
779 LWIP_DEBUGF(UDP_DEBUG, ("udp_send: added header in given pbuf %p\n", (void *)p));
780 }
781 LWIP_ASSERT("check that first pbuf can hold struct udp_hdr",
782 (q->len >= sizeof(struct udp_hdr)));
783 /* q now represents the packet to be sent */
784 udphdr = (struct udp_hdr *)q->payload;
785 udphdr->src = lwip_htons(pcb->local_port);
786 udphdr->dest = lwip_htons(dst_port);
787 /* in UDP, 0 checksum means 'no checksum' */
788 udphdr->chksum = 0x0000;
789
790 /* Multicast Loop? */
791#if LWIP_MULTICAST_TX_OPTIONS
792 if (((pcb->flags & UDP_FLAGS_MULTICAST_LOOP) != 0) && ip_addr_ismulticast(dst_ip)) {
793 q->flags |= PBUF_FLAG_MCASTLOOP;
794 }
795#endif /* LWIP_MULTICAST_TX_OPTIONS */
796
797 LWIP_DEBUGF(UDP_DEBUG, ("udp_send: sending datagram of length %"U16_F"\n", q->tot_len));
798
799#if LWIP_UDPLITE
800 /* UDP Lite protocol? */
801 if (pcb->flags & UDP_FLAGS_UDPLITE) {
802 u16_t chklen, chklen_hdr;
803 LWIP_DEBUGF(UDP_DEBUG, ("udp_send: UDP LITE packet length %"U16_F"\n", q->tot_len));
804 /* set UDP message length in UDP header */
805 chklen_hdr = chklen = pcb->chksum_len_tx;
806 if ((chklen < sizeof(struct udp_hdr)) || (chklen > q->tot_len)) {
807 if (chklen != 0) {
808 LWIP_DEBUGF(UDP_DEBUG, ("udp_send: UDP LITE pcb->chksum_len is illegal: %"U16_F"\n", chklen));
809 }
810 /* For UDP-Lite, checksum length of 0 means checksum
811 over the complete packet. (See RFC 3828 chap. 3.1)
812 At least the UDP-Lite header must be covered by the
813 checksum, therefore, if chksum_len has an illegal
814 value, we generate the checksum over the complete
815 packet to be safe. */
816 chklen_hdr = 0;
817 chklen = q->tot_len;
818 }
819 udphdr->len = lwip_htons(chklen_hdr);
820 /* calculate checksum */
821#if CHECKSUM_GEN_UDP
822 IF__NETIF_CHECKSUM_ENABLED(netif, NETIF_CHECKSUM_GEN_UDP) {
823#if LWIP_CHECKSUM_ON_COPY
824 if (have_chksum) {
825 chklen = UDP_HLEN;
826 }
827#endif /* LWIP_CHECKSUM_ON_COPY */
829 q->tot_len, chklen, src_ip, dst_ip);
830#if LWIP_CHECKSUM_ON_COPY
831 if (have_chksum) {
832 u32_t acc;
833 acc = udphdr->chksum + (u16_t)~(chksum);
834 udphdr->chksum = FOLD_U32T(acc);
835 }
836#endif /* LWIP_CHECKSUM_ON_COPY */
837
838 /* chksum zero must become 0xffff, as zero means 'no checksum' */
839 if (udphdr->chksum == 0x0000) {
840 udphdr->chksum = 0xffff;
841 }
842 }
843#endif /* CHECKSUM_GEN_UDP */
844
845 ip_proto = IP_PROTO_UDPLITE;
846 } else
847#endif /* LWIP_UDPLITE */
848 { /* UDP */
849 LWIP_DEBUGF(UDP_DEBUG, ("udp_send: UDP packet length %"U16_F"\n", q->tot_len));
850 udphdr->len = lwip_htons(q->tot_len);
851 /* calculate checksum */
852#if CHECKSUM_GEN_UDP
853 IF__NETIF_CHECKSUM_ENABLED(netif, NETIF_CHECKSUM_GEN_UDP) {
854 /* Checksum is mandatory over IPv6. */
855 if (IP_IS_V6(dst_ip) || (pcb->flags & UDP_FLAGS_NOCHKSUM) == 0) {
856 u16_t udpchksum;
857#if LWIP_CHECKSUM_ON_COPY
858 if (have_chksum) {
859 u32_t acc;
861 q->tot_len, UDP_HLEN, src_ip, dst_ip);
862 acc = udpchksum + (u16_t)~(chksum);
863 udpchksum = FOLD_U32T(acc);
864 } else
865#endif /* LWIP_CHECKSUM_ON_COPY */
866 {
867 udpchksum = ip_chksum_pseudo(q, IP_PROTO_UDP, q->tot_len,
868 src_ip, dst_ip);
869 }
870
871 /* chksum zero must become 0xffff, as zero means 'no checksum' */
872 if (udpchksum == 0x0000) {
873 udpchksum = 0xffff;
874 }
875 udphdr->chksum = udpchksum;
876 }
877 }
878#endif /* CHECKSUM_GEN_UDP */
879 ip_proto = IP_PROTO_UDP;
880 }
881
882 /* Determine TTL to use */
883#if LWIP_MULTICAST_TX_OPTIONS
884 ttl = (ip_addr_ismulticast(dst_ip) ? udp_get_multicast_ttl(pcb) : pcb->ttl);
885#else /* LWIP_MULTICAST_TX_OPTIONS */
886 ttl = pcb->ttl;
887#endif /* LWIP_MULTICAST_TX_OPTIONS */
888
889 LWIP_DEBUGF(UDP_DEBUG, ("udp_send: UDP checksum 0x%04"X16_F"\n", udphdr->chksum));
890 LWIP_DEBUGF(UDP_DEBUG, ("udp_send: ip_output_if (,,,,0x%02"X16_F",)\n", (u16_t)ip_proto));
891 /* output to IP */
892 NETIF_SET_HINTS(netif, &(pcb->netif_hints));
893 err = ip_output_if_src(q, src_ip, dst_ip, ttl, pcb->tos, ip_proto, netif);
895
896 /* @todo: must this be increased even if error occurred? */
897 MIB2_STATS_INC(mib2.udpoutdatagrams);
898
899 /* did we chain a separate header pbuf earlier? */
900 if (q != p) {
901 /* free the header pbuf */
902 pbuf_free(q);
903 q = NULL;
904 /* p is still referenced by the caller, and will live on */
905 }
906
907 UDP_STATS_INC(udp.xmit);
908 return err;
909}
910
931err_t
932udp_bind(struct udp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port)
933{
934 struct udp_pcb *ipcb;
935 u8_t rebind;
936#if LWIP_IPV6 && LWIP_IPV6_SCOPES
937 ip_addr_t zoned_ipaddr;
938#endif /* LWIP_IPV6 && LWIP_IPV6_SCOPES */
939
941
942#if LWIP_IPV4
943 /* Don't propagate NULL pointer (IPv4 ANY) to subsequent functions */
944 if (ipaddr == NULL) {
945 ipaddr = IP4_ADDR_ANY;
946 }
947#else /* LWIP_IPV4 */
948 LWIP_ERROR("udp_bind: invalid ipaddr", ipaddr != NULL, return ERR_ARG);
949#endif /* LWIP_IPV4 */
950
951 LWIP_ERROR("udp_bind: invalid pcb", pcb != NULL, return ERR_ARG);
952
953 LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE, ("udp_bind(ipaddr = "));
955 LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE, (", port = %"U16_F")\n", port));
956
957 rebind = 0;
958 /* Check for double bind and rebind of the same pcb */
959 for (ipcb = udp_pcbs; ipcb != NULL; ipcb = ipcb->next) {
960 /* is this UDP PCB already on active list? */
961 if (pcb == ipcb) {
962 rebind = 1;
963 break;
964 }
965 }
966
967#if LWIP_IPV6 && LWIP_IPV6_SCOPES
968 /* If the given IP address should have a zone but doesn't, assign one now.
969 * This is legacy support: scope-aware callers should always provide properly
970 * zoned source addresses. Do the zone selection before the address-in-use
971 * check below; as such we have to make a temporary copy of the address. */
972 if (IP_IS_V6(ipaddr) && ip6_addr_lacks_zone(ip_2_ip6(ipaddr), IP6_UNKNOWN)) {
973 ip_addr_copy(zoned_ipaddr, *ipaddr);
974 ip6_addr_select_zone(ip_2_ip6(&zoned_ipaddr), ip_2_ip6(&zoned_ipaddr));
975 ipaddr = &zoned_ipaddr;
976 }
977#endif /* LWIP_IPV6 && LWIP_IPV6_SCOPES */
978
979 /* no port specified? */
980 if (port == 0) {
981 port = udp_new_port();
982 if (port == 0) {
983 /* no more ports available in local range */
984 LWIP_DEBUGF(UDP_DEBUG, ("udp_bind: out of free UDP ports\n"));
985 return ERR_USE;
986 }
987 } else {
988 for (ipcb = udp_pcbs; ipcb != NULL; ipcb = ipcb->next) {
989 if (pcb != ipcb) {
990 /* By default, we don't allow to bind to a port that any other udp
991 PCB is already bound to, unless *all* PCBs with that port have tha
992 REUSEADDR flag set. */
993#if SO_REUSE
994 if (!ip_get_option(pcb, SOF_REUSEADDR) ||
996#endif /* SO_REUSE */
997 {
998 /* port matches that of PCB in list and REUSEADDR not set -> reject */
999 if ((ipcb->local_port == port) &&
1000 (((IP_GET_TYPE(&ipcb->local_ip) == IP_GET_TYPE(ipaddr)) &&
1001 /* IP address matches or any IP used? */
1002 (ip_addr_eq(&ipcb->local_ip, ipaddr) ||
1003 ip_addr_isany(ipaddr) ||
1004 ip_addr_isany(&ipcb->local_ip))) ||
1005 (IP_GET_TYPE(&ipcb->local_ip) == IPADDR_TYPE_ANY) ||
1006 (IP_GET_TYPE(ipaddr) == IPADDR_TYPE_ANY))) {
1007 /* other PCB already binds to this local IP and port */
1009 ("udp_bind: local port %"U16_F" already bound by another pcb\n", port));
1010 return ERR_USE;
1011 }
1012 }
1013 }
1014 }
1015 }
1016
1017 ip_addr_set_ipaddr(&pcb->local_ip, ipaddr);
1018
1019 pcb->local_port = port;
1020 mib2_udp_bind(pcb);
1021 /* pcb not active yet? */
1022 if (rebind == 0) {
1023 /* place the PCB on the active list if not already there */
1024 pcb->next = udp_pcbs;
1025 udp_pcbs = pcb;
1026 }
1027 LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("udp_bind: bound to "));
1029 LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, (", port %"U16_F")\n", pcb->local_port));
1030 return ERR_OK;
1031}
1032
1045void
1046udp_bind_netif(struct udp_pcb *pcb, const struct netif *netif)
1047{
1049
1050 if (netif != NULL) {
1051 pcb->netif_idx = netif_get_index(netif);
1052 } else {
1053 pcb->netif_idx = NETIF_NO_INDEX;
1054 }
1055}
1056
1074err_t
1075udp_connect(struct udp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port)
1076{
1077 struct udp_pcb *ipcb;
1078
1080
1081 LWIP_ERROR("udp_connect: invalid pcb", pcb != NULL, return ERR_ARG);
1082 LWIP_ERROR("udp_connect: invalid ipaddr", ipaddr != NULL, return ERR_ARG);
1083
1084 if (pcb->local_port == 0) {
1085 err_t err = udp_bind(pcb, &pcb->local_ip, pcb->local_port);
1086 if (err != ERR_OK) {
1087 return err;
1088 }
1089 }
1090
1091 ip_addr_set_ipaddr(&pcb->remote_ip, ipaddr);
1092#if LWIP_IPV6 && LWIP_IPV6_SCOPES
1093 /* If the given IP address should have a zone but doesn't, assign one now,
1094 * using the bound address to make a more informed decision when possible. */
1095 if (IP_IS_V6(&pcb->remote_ip) &&
1096 ip6_addr_lacks_zone(ip_2_ip6(&pcb->remote_ip), IP6_UNKNOWN)) {
1097 ip6_addr_select_zone(ip_2_ip6(&pcb->remote_ip), ip_2_ip6(&pcb->local_ip));
1098 }
1099#endif /* LWIP_IPV6 && LWIP_IPV6_SCOPES */
1100
1101 pcb->remote_port = port;
1102 pcb->flags |= UDP_FLAGS_CONNECTED;
1103
1104 LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("udp_connect: connected to "));
1106 pcb->remote_ip);
1107 LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, (", port %"U16_F")\n", pcb->remote_port));
1108
1109 /* Insert UDP PCB into the list of active UDP PCBs. */
1110 for (ipcb = udp_pcbs; ipcb != NULL; ipcb = ipcb->next) {
1111 if (pcb == ipcb) {
1112 /* already on the list, just return */
1113 return ERR_OK;
1114 }
1115 }
1116 /* PCB not yet on the list, add PCB now */
1117 pcb->next = udp_pcbs;
1118 udp_pcbs = pcb;
1119 return ERR_OK;
1120}
1121
1129void
1130udp_disconnect(struct udp_pcb *pcb)
1131{
1133
1134 LWIP_ERROR("udp_disconnect: invalid pcb", pcb != NULL, return);
1135
1136 /* reset remote address association */
1137#if LWIP_IPV4 && LWIP_IPV6
1138 if (IP_IS_ANY_TYPE_VAL(pcb->local_ip)) {
1139 ip_addr_copy(pcb->remote_ip, *IP_ANY_TYPE);
1140 } else {
1141#endif
1142 ip_addr_set_any(IP_IS_V6_VAL(pcb->remote_ip), &pcb->remote_ip);
1143#if LWIP_IPV4 && LWIP_IPV6
1144 }
1145#endif
1146 pcb->remote_port = 0;
1147 pcb->netif_idx = NETIF_NO_INDEX;
1148 /* mark PCB as unconnected */
1149 udp_clear_flags(pcb, UDP_FLAGS_CONNECTED);
1150}
1151
1161void
1162udp_recv(struct udp_pcb *pcb, udp_recv_fn recv, void *recv_arg)
1163{
1165
1166 LWIP_ERROR("udp_recv: invalid pcb", pcb != NULL, return);
1167
1168 /* remember recv() callback and user data */
1169 pcb->recv = recv;
1170 pcb->recv_arg = recv_arg;
1171}
1172
1182void
1183udp_remove(struct udp_pcb *pcb)
1184{
1185 struct udp_pcb *pcb2;
1186
1188
1189 LWIP_ERROR("udp_remove: invalid pcb", pcb != NULL, return);
1190
1191 mib2_udp_unbind(pcb);
1192 /* pcb to be removed is first in list? */
1193 if (udp_pcbs == pcb) {
1194 /* make list start at 2nd pcb */
1195 udp_pcbs = udp_pcbs->next;
1196 /* pcb not 1st in list */
1197 } else {
1198 for (pcb2 = udp_pcbs; pcb2 != NULL; pcb2 = pcb2->next) {
1199 /* find pcb in udp_pcbs list */
1200 if (pcb2->next != NULL && pcb2->next == pcb) {
1201 /* remove pcb from list */
1202 pcb2->next = pcb->next;
1203 break;
1204 }
1205 }
1206 }
1207 memp_free(MEMP_UDP_PCB, pcb);
1208}
1209
1222struct udp_pcb *
1223udp_new(void)
1224{
1225 struct udp_pcb *pcb;
1226
1228
1229 pcb = (struct udp_pcb *)memp_malloc(MEMP_UDP_PCB);
1230 /* could allocate UDP PCB? */
1231 if (pcb != NULL) {
1232 /* UDP Lite: by initializing to all zeroes, chksum_len is set to 0
1233 * which means checksum is generated over the whole datagram per default
1234 * (recommended as default by RFC 3828). */
1235 /* initialize PCB to all zeroes */
1236 memset(pcb, 0, sizeof(struct udp_pcb));
1237 pcb->ttl = UDP_TTL;
1238#if LWIP_MULTICAST_TX_OPTIONS
1239 udp_set_multicast_ttl(pcb, UDP_TTL);
1240#endif /* LWIP_MULTICAST_TX_OPTIONS */
1241 pcb_tci_init(pcb);
1242 }
1243 return pcb;
1244}
1245
1261struct udp_pcb *
1262udp_new_ip_type(u8_t type)
1263{
1264 struct udp_pcb *pcb;
1265
1267
1268 pcb = udp_new();
1269#if LWIP_IPV4 && LWIP_IPV6
1270 if (pcb != NULL) {
1271 IP_SET_TYPE_VAL(pcb->local_ip, type);
1272 IP_SET_TYPE_VAL(pcb->remote_ip, type);
1273 }
1274#else
1276#endif /* LWIP_IPV4 && LWIP_IPV6 */
1277 return pcb;
1278}
1279
1285void udp_netif_ip_addr_changed(const ip_addr_t *old_addr, const ip_addr_t *new_addr)
1286{
1287 struct udp_pcb *upcb;
1288
1289 if (!ip_addr_isany(old_addr) && !ip_addr_isany(new_addr)) {
1290 for (upcb = udp_pcbs; upcb != NULL; upcb = upcb->next) {
1291 /* PCB bound to current local interface address? */
1292 if (ip_addr_eq(&upcb->local_ip, old_addr)) {
1293 /* The PCB is bound to the old ipaddr and
1294 * is set to bound to the new one instead */
1295 ip_addr_copy(upcb->local_ip, *new_addr);
1296 }
1297 }
1298 }
1299}
1300
1301#if UDP_DEBUG
1307void
1308udp_debug_print(struct udp_hdr *udphdr)
1309{
1310 LWIP_DEBUGF(UDP_DEBUG, ("UDP header:\n"));
1311 LWIP_DEBUGF(UDP_DEBUG, ("+-------------------------------+\n"));
1312 LWIP_DEBUGF(UDP_DEBUG, ("| %5"U16_F" | %5"U16_F" | (src port, dest port)\n",
1313 lwip_ntohs(udphdr->src), lwip_ntohs(udphdr->dest)));
1314 LWIP_DEBUGF(UDP_DEBUG, ("+-------------------------------+\n"));
1315 LWIP_DEBUGF(UDP_DEBUG, ("| %5"U16_F" | 0x%04"X16_F" | (len, chksum)\n",
1316 lwip_ntohs(udphdr->len), lwip_ntohs(udphdr->chksum)));
1317 LWIP_DEBUGF(UDP_DEBUG, ("+-------------------------------+\n"));
1318}
1319#endif /* UDP_DEBUG */
1320
1321#endif /* LWIP_UDP */
#define lwip_htons(x)
Definition: def.h:86
#define lwip_ntohs(x)
Definition: def.h:87
#define NULL
Definition: types.h:112
static UINT mib2[]
Definition: main.c:83
USHORT port
Definition: uri.c:228
INT WSAAPI recv(IN SOCKET s, OUT CHAR FAR *buf, IN INT len, IN INT flags)
Definition: recv.c:23
#define X16_F
Definition: cc.h:21
#define U16_F
Definition: cc.h:19
#define LWIP_DEBUGF(debug, message)
Definition: debug.h:158
#define LWIP_ERROR(message, expression, handler)
Definition: debug.h:130
#define LWIP_ASSERT(message, assertion)
Definition: debug.h:116
#define ip_get_option(pcb, opt)
Definition: ip.h:228
#define ip_current_header_tot_len()
Definition: ip.h:152
#define ip_current_src_addr()
Definition: ip.h:223
#define ip_current_dest_addr()
Definition: ip.h:225
#define SOF_REUSEADDR
Definition: ip.h:110
#define ip_current_netif()
Definition: ip.h:146
#define SOF_BROADCAST
Definition: ip.h:112
struct ip_globals ip_data
#define pcb_tci_init(pcb)
Definition: ip.h:104
#define IP_PROTO_UDPLITE
Definition: ip.h:49
#define IP_PROTO_UDP
Definition: ip.h:48
#define mib2_udp_unbind(pcb)
Definition: snmp.h:192
#define mib2_udp_bind(pcb)
Definition: snmp.h:191
#define ERR_MEM
Definition: fontsub.h:52
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
GLuint GLuint end
Definition: gl.h:1545
GLdouble GLdouble GLdouble GLdouble q
Definition: gl.h:2063
GLdouble n
Definition: glext.h:7729
GLenum src
Definition: glext.h:6340
GLenum const GLvoid * addr
Definition: glext.h:9621
GLfloat GLfloat p
Definition: glext.h:8902
uint32_t u32_t
Definition: arch.h:129
uint8_t u8_t
Definition: arch.h:125
#define LWIP_UNUSED_ARG(x)
Definition: arch.h:373
uint16_t u16_t
Definition: arch.h:127
int16_t s16_t
Definition: arch.h:128
#define LWIP_DBG_LEVEL_SERIOUS
Definition: debug.h:57
#define LWIP_DBG_STATE
Definition: debug.h:85
#define LWIP_DBG_TRACE
Definition: debug.h:83
s8_t err_t
Definition: err.h:96
@ ERR_USE
Definition: err.h:71
@ ERR_RTE
Definition: err.h:63
@ ERR_OK
Definition: err.h:55
@ ERR_VAL
Definition: err.h:67
@ ERR_ARG
Definition: err.h:88
#define IP_ANY_TYPE
Definition: ip_addr.h:461
@ IPADDR_TYPE_ANY
Definition: ip_addr.h:60
#define UDP_DEBUG
Definition: opt.h:3505
#define LWIP_IPV6
Definition: opt.h:2440
#define LWIP_ASSERT_CORE_LOCKED()
Definition: opt.h:227
#define UDP_TTL
Definition: opt.h:1236
struct netif * netif_get_by_index(u8_t idx)
Definition: netif.c:1730
void pbuf_chain(struct pbuf *h, struct pbuf *t)
Definition: pbuf.c:897
struct pbuf * pbuf_alloc(pbuf_layer layer, u16_t length, pbuf_type type)
Definition: pbuf.c:224
u8_t pbuf_free(struct pbuf *p)
Definition: pbuf.c:727
struct pbuf * pbuf_clone(pbuf_layer layer, pbuf_type type, struct pbuf *p)
Definition: pbuf.c:1337
@ PBUF_RAM
Definition: pbuf.h:152
@ PBUF_POOL
Definition: pbuf.h:167
@ PBUF_RAW
Definition: pbuf.h:111
@ PBUF_IP
Definition: pbuf.h:97
u16_t ip_chksum_pseudo(struct pbuf *p, u8_t proto, u16_t proto_len, const ip_addr_t *src, const ip_addr_t *dest)
Definition: inet_chksum.c:379
u16_t ip_chksum_pseudo_partial(struct pbuf *p, u8_t proto, u16_t proto_len, u16_t chksum_len, const ip_addr_t *src, const ip_addr_t *dest)
Definition: inet_chksum.c:526
#define FOLD_U32T(u)
Definition: inet_chksum.h:52
#define ip_2_ip6(ipaddr)
Definition: ip_addr.h:356
#define ip_addr_isbroadcast(addr, netif)
Definition: ip_addr.h:381
#define IP_IS_V6_VAL(ipaddr)
Definition: ip_addr.h:348
#define ip_addr_ismulticast(ipaddr)
Definition: ip_addr.h:382
#define IP_ADDR_PCB_VERSION_MATCH(addr, pcb)
Definition: ip_addr.h:286
#define ip_addr_isany(ipaddr)
Definition: ip_addr.h:377
#define ip_addr_eq(addr1, addr2)
Definition: ip_addr.h:374
#define ip_addr_copy(dest, src)
Definition: ip_addr.h:360
#define IP_ADDR_PCB_VERSION_MATCH_EXACT(pcb, ipaddr)
Definition: ip_addr.h:287
#define IP_IS_ANY_TYPE_VAL(ipaddr)
Definition: ip_addr.h:351
#define ip_addr_set_any(is_ipv6, ipaddr)
Definition: ip_addr.h:367
ip6_addr_t ip_addr_t
Definition: ip_addr.h:344
#define IP_IS_V6(ipaddr)
Definition: ip_addr.h:350
#define IP_GET_TYPE(ipaddr)
Definition: ip_addr.h:354
#define IP_SET_TYPE_VAL(ipaddr, iptype)
Definition: ip_addr.h:352
#define IP_IS_V4_VAL(ipaddr)
Definition: ip_addr.h:347
#define IP_IS_V4(ipaddr)
Definition: ip_addr.h:349
#define ip_addr_debug_print_val(debug, ipaddr)
Definition: ip_addr.h:384
#define ip_addr_isany_val(ipaddr)
Definition: ip_addr.h:378
#define ip_addr_set_ipaddr(dest, src)
Definition: ip_addr.h:364
#define ip_addr_debug_print(debug, ipaddr)
Definition: ip_addr.h:383
#define icmp_port_unreach(isipv6, pbuf)
Definition: icmp.h:103
#define UDP_HLEN
Definition: udp.h:46
void * memp_malloc(memp_t type)
Definition: memp.c:337
void memp_free(memp_t type, void *mem)
Definition: memp.c:420
static char * dest
Definition: rtl.c:135
#define NETIF_RESET_HINTS(netif)
Definition: netif.h:570
#define NETIF_NO_INDEX
Definition: netif.h:579
#define netif_get_index(netif)
Definition: netif.h:578
#define IF__NETIF_CHECKSUM_ENABLED(netif, chksumflag)
Definition: netif.h:416
#define NETIF_SET_HINTS(netif, netifhint)
Definition: netif.h:569
u8_t pbuf_add_header(struct pbuf *p, size_t header_size_increment)
Definition: pbuf.c:554
u8_t pbuf_remove_header(struct pbuf *p, size_t header_size_decrement)
Definition: pbuf.c:585
u8_t pbuf_header_force(struct pbuf *p, s16_t header_size_increment)
Definition: pbuf.c:659
#define PBUF_FLAG_MCASTLOOP
Definition: pbuf.h:177
#define PERF_START
Definition: perf.h:3
#define PERF_STOP
Definition: perf.h:4
#define err(...)
#define memset(x, y, z)
Definition: compat.h:39
#define MIB2_STATS_INC(x)
Definition: stats.h:467
#define UDP_STATS_INC(x)
Definition: stats.h:336
struct define * next
Definition: compiler.c:65
Definition: netif.h:269
Definition: pbuf.h:186
Definition: udp.h:53
Definition: dhcpd.h:79
static const u8_t broadcast[6]
Definition: test_dhcp.c:23