2003-03-25 12:58:22 +00:00
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* User Datagram Protocol module
|
|
|
|
*
|
|
|
|
*/
|
2007-08-09 22:21:44 +00:00
|
|
|
|
2002-10-19 12:59:30 +00:00
|
|
|
/*
|
2004-02-07 00:30:03 +00:00
|
|
|
* Copyright (c) 2001-2004 Swedish Institute of Computer Science.
|
2003-06-09 21:14:47 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without modification,
|
2002-10-19 12:59:30 +00:00
|
|
|
* are permitted provided that the following conditions are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
|
|
* and/or other materials provided with the distribution.
|
|
|
|
* 3. The name of the author may not be used to endorse or promote products
|
2003-06-09 21:14:47 +00:00
|
|
|
* derived from this software without specific prior written permission.
|
2002-10-19 12:59:30 +00:00
|
|
|
*
|
2003-06-09 21:14:47 +00:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
|
|
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
|
|
|
|
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
|
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
|
|
|
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
|
|
|
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
|
2002-10-19 12:59:30 +00:00
|
|
|
* OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* This file is part of the lwIP TCP/IP stack.
|
2003-06-09 21:14:47 +00:00
|
|
|
*
|
2002-10-19 12:59:30 +00:00
|
|
|
* Author: Adam Dunkels <adam@sics.se>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2003-11-14 13:17:23 +00:00
|
|
|
|
2002-10-19 12:59:30 +00:00
|
|
|
/* udp.c
|
|
|
|
*
|
2007-10-07 20:19:23 +00:00
|
|
|
* The code for the User Datagram Protocol UDP & UDPLite (RFC 3828).
|
2002-10-19 12:59:30 +00:00
|
|
|
*
|
|
|
|
*/
|
2003-11-14 13:17:23 +00:00
|
|
|
|
2007-10-07 20:19:23 +00:00
|
|
|
/* @todo Check the use of '(struct udp_pcb).chksum_len_rx'!
|
|
|
|
*/
|
|
|
|
|
2003-02-21 16:43:46 +00:00
|
|
|
#include "lwip/opt.h"
|
2002-10-19 12:59:30 +00:00
|
|
|
|
2007-09-07 23:01:59 +00:00
|
|
|
#if LWIP_UDP /* don't build if not configured for use in lwipopts.h */
|
|
|
|
|
2007-11-16 19:31:10 +00:00
|
|
|
#include "lwip/udp.h"
|
2002-10-19 12:59:30 +00:00
|
|
|
#include "lwip/def.h"
|
|
|
|
#include "lwip/memp.h"
|
2007-11-16 19:31:10 +00:00
|
|
|
#include "lwip/inet_chksum.h"
|
2004-03-12 00:10:07 +00:00
|
|
|
#include "lwip/ip_addr.h"
|
2011-05-17 19:35:14 +00:00
|
|
|
#include "lwip/ip6.h"
|
|
|
|
#include "lwip/ip6_addr.h"
|
2011-05-25 17:16:35 +00:00
|
|
|
#include "lwip/inet_chksum.h"
|
2002-10-19 12:59:30 +00:00
|
|
|
#include "lwip/netif.h"
|
|
|
|
#include "lwip/icmp.h"
|
2011-05-17 19:35:14 +00:00
|
|
|
#include "lwip/icmp6.h"
|
2002-10-19 12:59:30 +00:00
|
|
|
#include "lwip/stats.h"
|
2003-02-10 21:58:34 +00:00
|
|
|
#include "lwip/snmp.h"
|
2007-11-30 08:55:15 +00:00
|
|
|
#include "lwip/dhcp.h"
|
2007-09-07 23:01:59 +00:00
|
|
|
|
|
|
|
#include <string.h>
|
2002-10-19 12:59:30 +00:00
|
|
|
|
2011-09-11 10:44:01 +00:00
|
|
|
#ifndef UDP_LOCAL_PORT_RANGE_START
|
|
|
|
/* From http://www.iana.org/assignments/port-numbers:
|
|
|
|
"The Dynamic and/or Private Ports are those from 49152 through 65535" */
|
|
|
|
#define UDP_LOCAL_PORT_RANGE_START 0xc000
|
|
|
|
#define UDP_LOCAL_PORT_RANGE_END 0xffff
|
2015-04-23 05:24:45 +00:00
|
|
|
#define UDP_ENSURE_LOCAL_PORT_RANGE(port) ((u16_t)(((port) & ~UDP_LOCAL_PORT_RANGE_START) + UDP_LOCAL_PORT_RANGE_START))
|
2011-09-11 10:44:01 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* last local UDP port */
|
|
|
|
static u16_t udp_port = UDP_LOCAL_PORT_RANGE_START;
|
|
|
|
|
2003-03-31 08:00:01 +00:00
|
|
|
/* The list of UDP PCBs */
|
2006-08-11 14:09:48 +00:00
|
|
|
/* exported in udp.h (was static) */
|
2007-10-09 19:59:56 +00:00
|
|
|
struct udp_pcb *udp_pcbs;
|
2002-10-19 12:59:30 +00:00
|
|
|
|
2011-09-11 10:44:01 +00:00
|
|
|
/**
|
|
|
|
* Initialize this module.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
udp_init(void)
|
|
|
|
{
|
|
|
|
#if LWIP_RANDOMIZE_INITIAL_LOCAL_PORTS && defined(LWIP_RAND)
|
|
|
|
udp_port = UDP_ENSURE_LOCAL_PORT_RANGE(LWIP_RAND());
|
|
|
|
#endif /* LWIP_RANDOMIZE_INITIAL_LOCAL_PORTS && defined(LWIP_RAND) */
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Allocate a new local UDP port.
|
|
|
|
*
|
|
|
|
* @return a new (free) local UDP port number
|
|
|
|
*/
|
|
|
|
static u16_t
|
|
|
|
udp_new_port(void)
|
|
|
|
{
|
|
|
|
u16_t n = 0;
|
|
|
|
struct udp_pcb *pcb;
|
|
|
|
|
|
|
|
again:
|
|
|
|
if (udp_port++ == UDP_LOCAL_PORT_RANGE_END) {
|
|
|
|
udp_port = UDP_LOCAL_PORT_RANGE_START;
|
|
|
|
}
|
|
|
|
/* Check all PCBs. */
|
|
|
|
for(pcb = udp_pcbs; pcb != NULL; pcb = pcb->next) {
|
|
|
|
if (pcb->local_port == udp_port) {
|
|
|
|
if (++n > (UDP_LOCAL_PORT_RANGE_END - UDP_LOCAL_PORT_RANGE_START)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
goto again;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return udp_port;
|
|
|
|
#if 0
|
|
|
|
struct udp_pcb *ipcb = udp_pcbs;
|
|
|
|
while ((ipcb != NULL) && (udp_port != UDP_LOCAL_PORT_RANGE_END)) {
|
|
|
|
if (ipcb->local_port == udp_port) {
|
|
|
|
/* port is already used by another udp_pcb */
|
|
|
|
udp_port++;
|
|
|
|
/* restart scanning all udp pcbs */
|
|
|
|
ipcb = udp_pcbs;
|
|
|
|
} else {
|
|
|
|
/* go on with next udp pcb */
|
|
|
|
ipcb = ipcb->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ipcb != NULL) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return udp_port;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2003-01-27 13:58:45 +00:00
|
|
|
/**
|
|
|
|
* Process an incoming UDP datagram.
|
|
|
|
*
|
|
|
|
* Given an incoming UDP datagram (as a chain of pbufs) this function
|
2007-06-03 18:05:52 +00:00
|
|
|
* finds a corresponding UDP PCB and hands over the pbuf to the pcbs
|
|
|
|
* recv function. If no pcb is found or the datagram is incorrect, the
|
|
|
|
* pbuf is freed.
|
2003-01-27 13:58:45 +00:00
|
|
|
*
|
2011-05-17 19:35:14 +00:00
|
|
|
* @param p pbuf to be demultiplexed to a UDP PCB (p->payload pointing to the UDP header)
|
2007-06-03 18:05:52 +00:00
|
|
|
* @param inp network interface on which the datagram was received.
|
2003-01-27 13:58:45 +00:00
|
|
|
*
|
|
|
|
*/
|
2002-10-19 12:59:30 +00:00
|
|
|
void
|
|
|
|
udp_input(struct pbuf *p, struct netif *inp)
|
|
|
|
{
|
2003-06-09 21:14:47 +00:00
|
|
|
struct udp_hdr *udphdr;
|
2007-11-30 09:44:18 +00:00
|
|
|
struct udp_pcb *pcb, *prev;
|
2006-01-02 12:06:02 +00:00
|
|
|
struct udp_pcb *uncon_pcb;
|
2002-10-19 12:59:30 +00:00
|
|
|
u16_t src, dest;
|
2006-01-02 12:06:02 +00:00
|
|
|
u8_t local_match;
|
2009-04-29 12:42:43 +00:00
|
|
|
u8_t broadcast;
|
2011-05-25 17:16:35 +00:00
|
|
|
u8_t for_us;
|
2003-06-09 21:14:47 +00:00
|
|
|
|
2002-10-19 12:59:30 +00:00
|
|
|
PERF_START;
|
2003-06-09 21:14:47 +00:00
|
|
|
|
2003-11-14 13:17:23 +00:00
|
|
|
UDP_STATS_INC(udp.recv);
|
2002-10-19 12:59:30 +00:00
|
|
|
|
2011-05-17 19:35:14 +00:00
|
|
|
/* Check minimum length (UDP header) */
|
|
|
|
if (p->len < UDP_HLEN) {
|
2003-05-01 08:03:51 +00:00
|
|
|
/* drop short packets */
|
2006-05-26 01:36:16 +00:00
|
|
|
LWIP_DEBUGF(UDP_DEBUG,
|
|
|
|
("udp_input: short UDP datagram (%"U16_F" bytes) discarded\n", p->tot_len));
|
2003-11-14 13:17:23 +00:00
|
|
|
UDP_STATS_INC(udp.lenerr);
|
|
|
|
UDP_STATS_INC(udp.drop);
|
2003-05-01 08:03:51 +00:00
|
|
|
snmp_inc_udpinerrors();
|
2003-06-09 21:14:47 +00:00
|
|
|
pbuf_free(p);
|
|
|
|
goto end;
|
2003-05-01 08:03:51 +00:00
|
|
|
}
|
2002-10-19 12:59:30 +00:00
|
|
|
|
2006-05-26 02:40:54 +00:00
|
|
|
udphdr = (struct udp_hdr *)p->payload;
|
2003-06-09 21:14:47 +00:00
|
|
|
|
2009-04-29 12:42:43 +00:00
|
|
|
/* is broadcast packet ? */
|
2011-05-17 19:35:14 +00:00
|
|
|
broadcast = ip_addr_isbroadcast(ip_current_dest_addr(), inp);
|
2009-04-29 12:42:43 +00:00
|
|
|
|
2005-11-25 12:03:38 +00:00
|
|
|
LWIP_DEBUGF(UDP_DEBUG, ("udp_input: received datagram of length %"U16_F"\n", p->tot_len));
|
2003-06-09 21:14:47 +00:00
|
|
|
|
2007-06-03 18:05:52 +00:00
|
|
|
/* convert src and dest ports to host byte order */
|
2003-02-21 16:43:46 +00:00
|
|
|
src = ntohs(udphdr->src);
|
|
|
|
dest = ntohs(udphdr->dest);
|
2002-10-19 12:59:30 +00:00
|
|
|
|
|
|
|
udp_debug_print(udphdr);
|
2003-01-17 15:16:33 +00:00
|
|
|
|
2003-01-30 15:02:48 +00:00
|
|
|
/* print the UDP source and destination */
|
2011-05-17 19:35:14 +00:00
|
|
|
LWIP_DEBUGF(UDP_DEBUG, ("udp ("));
|
2015-04-09 20:21:15 +00:00
|
|
|
ip_addr_debug_print(UDP_DEBUG, ip_current_dest_addr());
|
2011-05-17 19:35:14 +00:00
|
|
|
LWIP_DEBUGF(UDP_DEBUG, (", %"U16_F") <-- (", ntohs(udphdr->dest)));
|
2015-04-09 20:21:15 +00:00
|
|
|
ip_addr_debug_print(UDP_DEBUG, ip_current_src_addr());
|
2011-05-17 19:35:14 +00:00
|
|
|
LWIP_DEBUGF(UDP_DEBUG, (", %"U16_F")\n", ntohs(udphdr->src)));
|
2003-11-14 13:17:23 +00:00
|
|
|
|
2007-11-30 08:55:15 +00:00
|
|
|
#if LWIP_DHCP
|
|
|
|
pcb = NULL;
|
|
|
|
/* when LWIP_DHCP is active, packets to DHCP_CLIENT_PORT may only be processed by
|
|
|
|
the dhcp module, no other UDP pcb may use the local UDP port DHCP_CLIENT_PORT */
|
|
|
|
if (dest == DHCP_CLIENT_PORT) {
|
|
|
|
/* all packets for DHCP_CLIENT_PORT not coming from DHCP_SERVER_PORT are dropped! */
|
|
|
|
if (src == DHCP_SERVER_PORT) {
|
|
|
|
if ((inp->dhcp != NULL) && (inp->dhcp->pcb != NULL)) {
|
2014-09-18 19:15:13 +00:00
|
|
|
/* accept the packet if
|
2007-11-30 08:55:15 +00:00
|
|
|
(- broadcast or directed to us) -> DHCP is link-layer-addressed, local ip is always ANY!
|
2011-05-25 17:16:35 +00:00
|
|
|
- inp->dhcp->pcb->remote == ANY or iphdr->src
|
|
|
|
(no need to check for IPv6 since the dhcp struct always uses IPv4) */
|
2015-04-09 20:21:15 +00:00
|
|
|
if (ip_addr_isany(&inp->dhcp->pcb->remote_ip) ||
|
|
|
|
ip_addr_cmp(&inp->dhcp->pcb->remote_ip, ip_current_src_addr())) {
|
2007-11-30 08:55:15 +00:00
|
|
|
pcb = inp->dhcp->pcb;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
#endif /* LWIP_DHCP */
|
|
|
|
{
|
2007-11-30 09:44:18 +00:00
|
|
|
prev = NULL;
|
2007-06-25 17:24:31 +00:00
|
|
|
local_match = 0;
|
2007-11-30 08:55:15 +00:00
|
|
|
uncon_pcb = NULL;
|
|
|
|
/* Iterate through the UDP pcb list for a matching pcb.
|
|
|
|
* 'Perfect match' pcbs (connected to the remote port & ip address) are
|
|
|
|
* preferred. If no perfect match is found, the first unconnected pcb that
|
|
|
|
* matches the local port and ip address gets the datagram. */
|
|
|
|
for (pcb = udp_pcbs; pcb != NULL; pcb = pcb->next) {
|
|
|
|
local_match = 0;
|
|
|
|
/* print the PCB local and remote address */
|
2011-05-17 19:35:14 +00:00
|
|
|
LWIP_DEBUGF(UDP_DEBUG, ("pcb ("));
|
2015-04-09 20:21:15 +00:00
|
|
|
ip_addr_debug_print(UDP_DEBUG, &pcb->local_ip);
|
2011-05-17 19:35:14 +00:00
|
|
|
LWIP_DEBUGF(UDP_DEBUG, (", %"U16_F") <-- (", pcb->local_port));
|
2015-04-09 20:21:15 +00:00
|
|
|
ip_addr_debug_print(UDP_DEBUG, &pcb->remote_ip);
|
2011-05-17 19:35:14 +00:00
|
|
|
LWIP_DEBUGF(UDP_DEBUG, (", %"U16_F")\n", pcb->remote_port));
|
2007-11-30 08:55:15 +00:00
|
|
|
|
|
|
|
/* compare PCB local addr+port to UDP destination addr+port */
|
2011-09-09 20:25:59 +00:00
|
|
|
if (pcb->local_port == dest) {
|
|
|
|
if (
|
2011-05-17 19:35:14 +00:00
|
|
|
#if LWIP_IPV6
|
2015-04-12 08:43:46 +00:00
|
|
|
(PCB_ISIPV6(pcb) && (ip_current_is_v6()) &&
|
2015-04-09 20:21:15 +00:00
|
|
|
(ip6_addr_isany(ip_2_ip6(&pcb->local_ip)) ||
|
2011-05-17 19:35:14 +00:00
|
|
|
#if LWIP_IPV6_MLD
|
|
|
|
ip6_addr_ismulticast(ip6_current_dest_addr()) ||
|
|
|
|
#endif /* LWIP_IPV6_MLD */
|
2015-04-12 08:43:46 +00:00
|
|
|
ip6_addr_cmp(ip_2_ip6(&pcb->local_ip), ip6_current_dest_addr())))
|
2011-05-17 19:35:14 +00:00
|
|
|
#endif /* LWIP_IPV6 */
|
2015-04-12 08:43:46 +00:00
|
|
|
#if LWIP_IPV4 && LWIP_IPV6
|
|
|
|
|| (!PCB_ISIPV6(pcb) &&
|
|
|
|
(ip4_current_header() != NULL) &&
|
|
|
|
#endif /* LWIP_IPV4 && LWIP_IPV6 */
|
|
|
|
#if LWIP_IPV4
|
|
|
|
#if !LWIP_IPV6
|
|
|
|
(
|
|
|
|
#endif /* !LWIP_IPV6 */
|
2015-04-09 20:21:15 +00:00
|
|
|
((!broadcast && ip_addr_isany(&pcb->local_ip)) ||
|
|
|
|
ip_addr_cmp(&pcb->local_ip, ip_current_dest_addr()) ||
|
2007-08-09 18:34:03 +00:00
|
|
|
#if LWIP_IGMP
|
2011-05-17 19:35:14 +00:00
|
|
|
ip_addr_ismulticast(ip_current_dest_addr()) ||
|
2007-08-09 18:34:03 +00:00
|
|
|
#endif /* LWIP_IGMP */
|
2009-04-29 12:42:43 +00:00
|
|
|
#if IP_SOF_BROADCAST_RECV
|
2011-12-17 21:12:01 +00:00
|
|
|
(broadcast && ip_get_option(pcb, SOF_BROADCAST) &&
|
2015-04-09 20:21:15 +00:00
|
|
|
(ip_addr_isany(&pcb->local_ip) ||
|
2015-04-12 08:43:46 +00:00
|
|
|
ip_addr_netcmp(&pcb->local_ip, ip_current_dest_addr(), &inp->netmask)))))
|
2011-09-09 20:25:59 +00:00
|
|
|
#else /* IP_SOF_BROADCAST_RECV */
|
|
|
|
(broadcast &&
|
2015-04-09 20:21:15 +00:00
|
|
|
(ip_addr_isany(&pcb->local_ip) ||
|
2015-04-12 08:43:46 +00:00
|
|
|
ip_addr_netcmp(&pcb->local_ip, ip_current_dest_addr(), &inp->netmask)))))
|
|
|
|
#endif /* IP_SOF_BROADCAST_RECV */
|
|
|
|
#endif /* LWIP_IPV4 */
|
|
|
|
) {
|
2011-09-09 20:25:59 +00:00
|
|
|
local_match = 1;
|
|
|
|
if ((uncon_pcb == NULL) &&
|
|
|
|
((pcb->flags & UDP_FLAGS_CONNECTED) == 0)) {
|
|
|
|
/* the first unconnected matching PCB */
|
|
|
|
uncon_pcb = pcb;
|
|
|
|
}
|
2007-11-30 08:55:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* compare PCB remote addr+port to UDP source addr+port */
|
|
|
|
if ((local_match != 0) &&
|
2011-05-25 17:16:35 +00:00
|
|
|
(pcb->remote_port == src) && IP_PCB_IPVER_INPUT_MATCH(pcb) &&
|
2015-04-09 20:21:15 +00:00
|
|
|
(ip_addr_isany(&pcb->remote_ip) ||
|
|
|
|
ip_addr_cmp(&pcb->remote_ip, ip_current_src_addr()))) {
|
2007-11-30 08:55:15 +00:00
|
|
|
/* the first fully matching PCB */
|
2007-11-30 09:44:18 +00:00
|
|
|
if (prev != NULL) {
|
|
|
|
/* move the pcb to the front of udp_pcbs so that is
|
|
|
|
found faster next time */
|
|
|
|
prev->next = pcb->next;
|
|
|
|
pcb->next = udp_pcbs;
|
|
|
|
udp_pcbs = pcb;
|
|
|
|
} else {
|
|
|
|
UDP_STATS_INC(udp.cachehit);
|
|
|
|
}
|
2007-11-30 08:55:15 +00:00
|
|
|
break;
|
2006-05-26 01:36:16 +00:00
|
|
|
}
|
2007-11-30 09:44:18 +00:00
|
|
|
prev = pcb;
|
2006-01-02 12:06:02 +00:00
|
|
|
}
|
2007-11-30 08:55:15 +00:00
|
|
|
/* no fully matching pcb found? then look for an unconnected pcb */
|
|
|
|
if (pcb == NULL) {
|
|
|
|
pcb = uncon_pcb;
|
2002-10-19 12:59:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check checksum if this is a match or if it was directed at us. */
|
2011-05-25 17:16:35 +00:00
|
|
|
if (pcb != NULL) {
|
|
|
|
for_us = 1;
|
|
|
|
} else {
|
2011-05-17 19:35:14 +00:00
|
|
|
#if LWIP_IPV6
|
2011-05-25 17:16:35 +00:00
|
|
|
if (ip_current_is_v6()) {
|
2014-02-25 21:30:46 +00:00
|
|
|
for_us = netif_get_ip6_addr_match(inp, ip6_current_dest_addr()) >= 0;
|
2015-04-09 20:21:15 +00:00
|
|
|
}
|
|
|
|
#if LWIP_IPV4
|
|
|
|
else
|
|
|
|
#endif /* LWIP_IPV4 */
|
2011-05-17 19:35:14 +00:00
|
|
|
#endif /* LWIP_IPV6 */
|
2015-04-09 20:21:15 +00:00
|
|
|
#if LWIP_IPV4
|
2011-05-25 17:16:35 +00:00
|
|
|
{
|
2015-04-09 20:21:15 +00:00
|
|
|
for_us = ip4_addr_cmp(&inp->ip_addr, ip4_current_dest_addr());
|
2011-05-25 17:16:35 +00:00
|
|
|
}
|
2015-04-09 20:21:15 +00:00
|
|
|
#endif /* LWIP_IPV4 */
|
2011-05-25 17:16:35 +00:00
|
|
|
}
|
|
|
|
if (for_us) {
|
2007-03-30 08:47:04 +00:00
|
|
|
LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE, ("udp_input: calculating checksum\n"));
|
2011-05-25 17:16:35 +00:00
|
|
|
#if CHECKSUM_CHECK_UDP
|
2007-06-10 12:02:24 +00:00
|
|
|
#if LWIP_UDPLITE
|
2011-05-25 17:16:35 +00:00
|
|
|
if (ip_current_header_proto() == IP_PROTO_UDPLITE) {
|
2002-10-19 12:59:30 +00:00
|
|
|
/* Do the UDP Lite checksum */
|
2007-06-11 18:03:57 +00:00
|
|
|
u16_t chklen = ntohs(udphdr->len);
|
|
|
|
if (chklen < sizeof(struct udp_hdr)) {
|
|
|
|
if (chklen == 0) {
|
|
|
|
/* For UDP-Lite, checksum length of 0 means checksum
|
|
|
|
over the complete packet (See RFC 3828 chap. 3.1) */
|
|
|
|
chklen = p->tot_len;
|
|
|
|
} else {
|
|
|
|
/* At least the UDP-Lite header must be covered by the
|
|
|
|
checksum! (Again, see RFC 3828 chap. 3.1) */
|
2011-05-25 17:16:35 +00:00
|
|
|
goto chkerr;
|
2011-05-17 19:35:14 +00:00
|
|
|
}
|
|
|
|
}
|
2015-04-09 20:21:15 +00:00
|
|
|
if (ip_chksum_pseudo_partial(p, IP_PROTO_UDPLITE,
|
2011-05-25 17:16:35 +00:00
|
|
|
p->tot_len, chklen,
|
2015-04-09 20:21:15 +00:00
|
|
|
ip_current_src_addr(), ip_current_dest_addr()) != 0) {
|
2011-05-25 17:16:35 +00:00
|
|
|
goto chkerr;
|
2002-10-19 12:59:30 +00:00
|
|
|
}
|
2007-06-10 12:02:24 +00:00
|
|
|
} else
|
|
|
|
#endif /* LWIP_UDPLITE */
|
|
|
|
{
|
2003-05-01 13:24:01 +00:00
|
|
|
if (udphdr->chksum != 0) {
|
2015-04-09 20:21:15 +00:00
|
|
|
if (ip_chksum_pseudo(p, IP_PROTO_UDP, p->tot_len,
|
|
|
|
ip_current_src_addr(),
|
|
|
|
ip_current_dest_addr()) != 0) {
|
2011-05-25 17:16:35 +00:00
|
|
|
goto chkerr;
|
2006-05-26 01:36:16 +00:00
|
|
|
}
|
2002-10-19 12:59:30 +00:00
|
|
|
}
|
|
|
|
}
|
2011-05-25 17:16:35 +00:00
|
|
|
#endif /* CHECKSUM_CHECK_UDP */
|
2007-03-21 12:55:00 +00:00
|
|
|
if(pbuf_header(p, -UDP_HLEN)) {
|
|
|
|
/* Can we cope with this failing? Just assert for now */
|
|
|
|
LWIP_ASSERT("pbuf_header failed\n", 0);
|
|
|
|
UDP_STATS_INC(udp.drop);
|
|
|
|
snmp_inc_udpinerrors();
|
|
|
|
pbuf_free(p);
|
|
|
|
goto end;
|
|
|
|
}
|
2003-05-01 13:24:01 +00:00
|
|
|
if (pcb != NULL) {
|
2002-11-21 10:32:19 +00:00
|
|
|
snmp_inc_udpindatagrams();
|
2010-05-15 16:46:53 +00:00
|
|
|
#if SO_REUSE && SO_REUSE_RXTOALL
|
2011-05-17 19:35:14 +00:00
|
|
|
if ((broadcast ||
|
|
|
|
#if LWIP_IPV6
|
|
|
|
ip6_addr_ismulticast(ip6_current_dest_addr()) ||
|
|
|
|
#endif /* LWIP_IPV6 */
|
|
|
|
ip_addr_ismulticast(ip_current_dest_addr())) &&
|
2011-12-17 21:12:01 +00:00
|
|
|
ip_get_option(pcb, SOF_REUSEADDR)) {
|
2010-05-15 14:52:39 +00:00
|
|
|
/* pass broadcast- or multicast packets to all multicast pcbs
|
|
|
|
if SOF_REUSEADDR is set on the first match */
|
|
|
|
struct udp_pcb *mpcb;
|
2010-05-15 17:11:41 +00:00
|
|
|
u8_t p_header_changed = 0;
|
2011-05-25 17:16:35 +00:00
|
|
|
s16_t hdrs_len = (s16_t)(ip_current_header_tot_len() + UDP_HLEN);
|
2010-05-15 14:52:39 +00:00
|
|
|
for (mpcb = udp_pcbs; mpcb != NULL; mpcb = mpcb->next) {
|
|
|
|
if (mpcb != pcb) {
|
|
|
|
/* compare PCB local addr+port to UDP destination addr+port */
|
|
|
|
if ((mpcb->local_port == dest) &&
|
2011-05-17 19:35:14 +00:00
|
|
|
#if LWIP_IPV6
|
2011-05-28 09:30:43 +00:00
|
|
|
((PCB_ISIPV6(mpcb) &&
|
2011-05-17 19:35:14 +00:00
|
|
|
(ip6_addr_ismulticast(ip6_current_dest_addr()) ||
|
2015-04-09 20:21:15 +00:00
|
|
|
ip6_addr_cmp(ip_2_ip6(&mpcb->local_ip), ip6_current_dest_addr()))) ||
|
2011-05-28 09:30:43 +00:00
|
|
|
(!PCB_ISIPV6(mpcb) &&
|
2011-05-17 19:35:14 +00:00
|
|
|
#else /* LWIP_IPV6 */
|
|
|
|
((
|
|
|
|
#endif /* LWIP_IPV6 */
|
2015-04-09 20:21:15 +00:00
|
|
|
((!broadcast && ip_addr_isany(&mpcb->local_ip)) ||
|
|
|
|
ip_addr_cmp(&mpcb->local_ip, ip_current_dest_addr()) ||
|
2010-05-15 14:52:39 +00:00
|
|
|
#if LWIP_IGMP
|
2011-05-17 19:35:14 +00:00
|
|
|
ip_addr_ismulticast(ip_current_dest_addr()) ||
|
2010-05-15 14:52:39 +00:00
|
|
|
#endif /* LWIP_IGMP */
|
|
|
|
#if IP_SOF_BROADCAST_RECV
|
2011-12-17 21:12:01 +00:00
|
|
|
(broadcast && ip_get_option(mpcb, SOF_BROADCAST)))))) {
|
2010-05-15 14:52:39 +00:00
|
|
|
#else /* IP_SOF_BROADCAST_RECV */
|
2011-05-17 19:35:14 +00:00
|
|
|
(broadcast))))) {
|
2010-05-15 14:52:39 +00:00
|
|
|
#endif /* IP_SOF_BROADCAST_RECV */
|
|
|
|
/* pass a copy of the packet to all local matches */
|
2015-04-09 20:21:15 +00:00
|
|
|
if (mpcb->recv != NULL) {
|
2010-05-15 17:11:41 +00:00
|
|
|
struct pbuf *q;
|
|
|
|
/* for that, move payload to IP header again */
|
|
|
|
if (p_header_changed == 0) {
|
2014-12-08 13:45:36 +00:00
|
|
|
pbuf_header_force(p, hdrs_len);
|
2010-05-15 17:11:41 +00:00
|
|
|
p_header_changed = 1;
|
|
|
|
}
|
|
|
|
q = pbuf_alloc(PBUF_RAW, p->tot_len, PBUF_RAM);
|
2010-05-15 14:52:39 +00:00
|
|
|
if (q != NULL) {
|
|
|
|
err_t err = pbuf_copy(q, p);
|
|
|
|
if (err == ERR_OK) {
|
|
|
|
/* move payload to UDP data */
|
2011-05-17 19:35:14 +00:00
|
|
|
pbuf_header(q, -hdrs_len);
|
2015-04-09 20:21:15 +00:00
|
|
|
mpcb->recv(mpcb->recv_arg, mpcb, q, ip_current_src_addr(), src);
|
2010-05-15 14:52:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-05-15 17:11:41 +00:00
|
|
|
if (p_header_changed) {
|
|
|
|
/* and move payload to UDP data again */
|
2011-05-17 19:35:14 +00:00
|
|
|
pbuf_header(p, -hdrs_len);
|
2010-05-15 17:11:41 +00:00
|
|
|
}
|
2010-05-15 14:52:39 +00:00
|
|
|
}
|
2010-05-15 16:46:53 +00:00
|
|
|
#endif /* SO_REUSE && SO_REUSE_RXTOALL */
|
2005-01-03 17:54:21 +00:00
|
|
|
/* callback */
|
2015-04-09 20:21:15 +00:00
|
|
|
if (pcb->recv != NULL) {
|
2007-06-03 11:32:03 +00:00
|
|
|
/* now the recv function is responsible for freeing p */
|
2015-04-09 20:21:15 +00:00
|
|
|
pcb->recv(pcb->recv_arg, pcb, p, ip_current_src_addr(), src);
|
2007-06-03 11:32:03 +00:00
|
|
|
} else {
|
|
|
|
/* no recv function registered? then we have to free the pbuf! */
|
|
|
|
pbuf_free(p);
|
|
|
|
goto end;
|
|
|
|
}
|
2006-05-26 01:36:16 +00:00
|
|
|
} else {
|
2007-03-30 08:47:04 +00:00
|
|
|
LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE, ("udp_input: not for us.\n"));
|
2003-06-09 21:14:47 +00:00
|
|
|
|
2011-05-17 19:35:14 +00:00
|
|
|
#if LWIP_ICMP || LWIP_ICMP6
|
2002-10-19 12:59:30 +00:00
|
|
|
/* No match was found, send ICMP destination port unreachable unless
|
2006-05-26 01:36:16 +00:00
|
|
|
destination address was broadcast/multicast. */
|
2015-04-09 20:21:15 +00:00
|
|
|
if (
|
|
|
|
#if LWIP_IPV4
|
|
|
|
!broadcast && !ip_addr_ismulticast(ip_current_dest_addr())
|
|
|
|
#if LWIP_IPV6
|
|
|
|
&&
|
|
|
|
#endif /* LWIP_IPV6 */
|
|
|
|
#endif /* LWIP_IPV4 */
|
2011-05-17 19:35:14 +00:00
|
|
|
#if LWIP_IPV6
|
2015-04-09 20:21:15 +00:00
|
|
|
!ip6_addr_ismulticast(ip6_current_dest_addr())
|
2011-05-17 19:35:14 +00:00
|
|
|
#endif /* LWIP_IPV6 */
|
2015-04-09 20:21:15 +00:00
|
|
|
) {
|
2011-05-25 17:16:35 +00:00
|
|
|
/* move payload pointer back to ip header */
|
2014-12-08 13:45:36 +00:00
|
|
|
pbuf_header_force(p, ip_current_header_tot_len() + UDP_HLEN);
|
2011-05-25 17:16:35 +00:00
|
|
|
icmp_port_unreach(ip_current_is_v6(), p);
|
2011-05-17 19:35:14 +00:00
|
|
|
}
|
|
|
|
#endif /* LWIP_ICMP || LWIP_ICMP6 */
|
2003-11-14 13:17:23 +00:00
|
|
|
UDP_STATS_INC(udp.proterr);
|
|
|
|
UDP_STATS_INC(udp.drop);
|
2006-05-26 01:36:16 +00:00
|
|
|
snmp_inc_udpnoports();
|
2002-10-19 12:59:30 +00:00
|
|
|
pbuf_free(p);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
pbuf_free(p);
|
|
|
|
}
|
2006-05-26 01:36:16 +00:00
|
|
|
end:
|
2002-10-19 12:59:30 +00:00
|
|
|
PERF_STOP("udp_input");
|
2011-05-25 17:16:35 +00:00
|
|
|
return;
|
2012-03-25 15:20:22 +00:00
|
|
|
#if CHECKSUM_CHECK_UDP
|
2011-05-25 17:16:35 +00:00
|
|
|
chkerr:
|
|
|
|
LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_LEVEL_SERIOUS,
|
|
|
|
("udp_input: UDP (or UDP Lite) datagram discarded due to failing checksum\n"));
|
|
|
|
UDP_STATS_INC(udp.chkerr);
|
|
|
|
UDP_STATS_INC(udp.drop);
|
|
|
|
snmp_inc_udpinerrors();
|
|
|
|
pbuf_free(p);
|
|
|
|
PERF_STOP("udp_input");
|
2012-03-25 15:20:22 +00:00
|
|
|
#endif /* CHECKSUM_CHECK_UDP */
|
2002-10-19 12:59:30 +00:00
|
|
|
}
|
2004-03-11 19:41:22 +00:00
|
|
|
|
2007-11-27 20:13:16 +00:00
|
|
|
/**
|
|
|
|
* Send data using UDP.
|
|
|
|
*
|
|
|
|
* @param pcb UDP PCB used to send the data.
|
|
|
|
* @param p chain of pbuf's to be sent.
|
|
|
|
*
|
|
|
|
* The datagram will be sent to the current remote_ip & remote_port
|
|
|
|
* stored in pcb. If the pcb is not bound to a port, it will
|
|
|
|
* automatically be bound to a random port.
|
|
|
|
*
|
|
|
|
* @return lwIP error code.
|
2014-09-18 19:15:13 +00:00
|
|
|
* - ERR_OK. Successful. No error occurred.
|
2007-11-27 20:13:16 +00:00
|
|
|
* - ERR_MEM. Out of memory.
|
|
|
|
* - ERR_RTE. Could not find route to destination address.
|
|
|
|
* - More errors could be returned by lower protocol layers.
|
|
|
|
*
|
|
|
|
* @see udp_disconnect() udp_sendto()
|
|
|
|
*/
|
|
|
|
err_t
|
|
|
|
udp_send(struct udp_pcb *pcb, struct pbuf *p)
|
|
|
|
{
|
|
|
|
/* send to the packet using remote ip and port stored in the pcb */
|
2015-04-09 20:21:15 +00:00
|
|
|
return udp_sendto(pcb, p, &pcb->remote_ip, pcb->remote_port);
|
2007-11-27 20:13:16 +00:00
|
|
|
}
|
|
|
|
|
2013-01-14 19:46:41 +00:00
|
|
|
#if LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP
|
2010-04-30 20:39:45 +00:00
|
|
|
/** Same as udp_send() but with checksum
|
|
|
|
*/
|
|
|
|
err_t
|
|
|
|
udp_send_chksum(struct udp_pcb *pcb, struct pbuf *p,
|
|
|
|
u8_t have_chksum, u16_t chksum)
|
|
|
|
{
|
|
|
|
/* send to the packet using remote ip and port stored in the pcb */
|
2015-04-09 20:21:15 +00:00
|
|
|
return udp_sendto_chksum(pcb, p, &pcb->remote_ip, pcb->remote_port,
|
2010-04-30 20:39:45 +00:00
|
|
|
have_chksum, chksum);
|
|
|
|
}
|
2013-01-14 19:46:41 +00:00
|
|
|
#endif /* LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP */
|
2010-04-30 20:39:45 +00:00
|
|
|
|
2004-03-11 20:01:26 +00:00
|
|
|
/**
|
|
|
|
* Send data to a specified address using UDP.
|
|
|
|
*
|
|
|
|
* @param pcb UDP PCB used to send the data.
|
2007-06-03 18:05:52 +00:00
|
|
|
* @param p chain of pbuf's to be sent.
|
2004-03-11 20:01:26 +00:00
|
|
|
* @param dst_ip Destination IP address.
|
|
|
|
* @param dst_port Destination UDP port.
|
|
|
|
*
|
2007-05-17 12:21:32 +00:00
|
|
|
* dst_ip & dst_port are expected to be in the same byte order as in the pcb.
|
|
|
|
*
|
2004-03-11 20:01:26 +00:00
|
|
|
* If the PCB already has a remote address association, it will
|
|
|
|
* be restored after the data is sent.
|
|
|
|
*
|
2007-06-03 18:05:52 +00:00
|
|
|
* @return lwIP error code (@see udp_send for possible error codes)
|
2004-03-11 20:01:26 +00:00
|
|
|
*
|
2004-03-11 20:04:16 +00:00
|
|
|
* @see udp_disconnect() udp_send()
|
2004-03-11 20:01:26 +00:00
|
|
|
*/
|
2004-03-11 19:41:22 +00:00
|
|
|
err_t
|
|
|
|
udp_sendto(struct udp_pcb *pcb, struct pbuf *p,
|
2015-01-24 00:25:18 +00:00
|
|
|
const ip_addr_t *dst_ip, u16_t dst_port)
|
2004-03-11 19:41:22 +00:00
|
|
|
{
|
2013-01-14 19:46:41 +00:00
|
|
|
#if LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP
|
2010-04-30 20:39:45 +00:00
|
|
|
return udp_sendto_chksum(pcb, p, dst_ip, dst_port, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Same as udp_sendto(), but with checksum */
|
|
|
|
err_t
|
2015-01-24 00:25:18 +00:00
|
|
|
udp_sendto_chksum(struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *dst_ip,
|
2010-04-30 20:39:45 +00:00
|
|
|
u16_t dst_port, u8_t have_chksum, u16_t chksum)
|
|
|
|
{
|
2013-01-14 19:46:41 +00:00
|
|
|
#endif /* LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP */
|
2007-11-27 20:13:16 +00:00
|
|
|
struct netif *netif;
|
2015-04-09 20:21:15 +00:00
|
|
|
const ip_addr_t *dst_ip_route = dst_ip;
|
|
|
|
#if LWIP_IPV6 && LWIP_IPV4 && LWIP_IGMP
|
|
|
|
ip_addr_t dst_ip_tmp;
|
|
|
|
#endif /* LWIP_IPV6 && LWIP_IPV4 && LWIP_IGMP */
|
2007-11-27 20:13:16 +00:00
|
|
|
|
2009-11-22 15:14:46 +00:00
|
|
|
LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE, ("udp_send\n"));
|
2007-11-27 20:13:16 +00:00
|
|
|
|
2015-04-09 20:21:15 +00:00
|
|
|
#if LWIP_IPV6 || (LWIP_IPV4 && LWIP_IGMP)
|
|
|
|
if (ip_addr_ismulticast(dst_ip_route)) {
|
2011-05-17 19:35:14 +00:00
|
|
|
#if LWIP_IPV6
|
2011-05-28 09:30:43 +00:00
|
|
|
if (PCB_ISIPV6(pcb)) {
|
2015-02-25 19:58:11 +00:00
|
|
|
/* For multicast, find a netif based on source address. */
|
2011-05-26 15:46:44 +00:00
|
|
|
dst_ip_route = &pcb->local_ip;
|
|
|
|
} else
|
2011-05-17 19:35:14 +00:00
|
|
|
#endif /* LWIP_IPV6 */
|
2011-05-26 15:46:44 +00:00
|
|
|
{
|
2015-04-09 20:21:15 +00:00
|
|
|
#if LWIP_IPV4 && LWIP_IGMP
|
2015-02-25 19:58:11 +00:00
|
|
|
/* IPv4 does not use source-based routing by default, so we use an
|
|
|
|
administratively selected interface for multicast by default.
|
|
|
|
However, this can be overridden by setting an interface address
|
|
|
|
in pcb->multicast_ip that is used for routing. */
|
2015-04-09 20:21:15 +00:00
|
|
|
if (!ip4_addr_isany(&pcb->multicast_ip) &&
|
|
|
|
!ip4_addr_cmp(&pcb->multicast_ip, IP4_ADDR_BROADCAST)) {
|
|
|
|
dst_ip_route = ip4_2_ip(&pcb->multicast_ip, &dst_ip_tmp);
|
2015-02-25 19:58:11 +00:00
|
|
|
}
|
2015-04-09 20:21:15 +00:00
|
|
|
#endif /* LWIP_IPV4 && LWIP_IGMP */
|
2011-05-28 09:30:43 +00:00
|
|
|
}
|
2011-05-17 19:35:14 +00:00
|
|
|
}
|
2011-05-26 15:46:44 +00:00
|
|
|
#endif /* LWIP_IPV6 || LWIP_IGMP */
|
|
|
|
|
|
|
|
/* find the outgoing network interface for this packet */
|
2015-04-09 20:21:15 +00:00
|
|
|
netif = ip_route(PCB_ISIPV6(pcb), &pcb->local_ip, dst_ip_route);
|
2007-11-27 20:13:16 +00:00
|
|
|
|
|
|
|
/* no outgoing network interface could be found? */
|
|
|
|
if (netif == NULL) {
|
2011-05-17 19:35:14 +00:00
|
|
|
LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_LEVEL_SERIOUS, ("udp_send: No route to "));
|
2015-04-09 20:21:15 +00:00
|
|
|
ip_addr_debug_print(UDP_DEBUG | LWIP_DBG_LEVEL_SERIOUS, dst_ip);
|
2011-05-17 19:35:14 +00:00
|
|
|
LWIP_DEBUGF(UDP_DEBUG, ("\n"));
|
2007-11-27 20:13:16 +00:00
|
|
|
UDP_STATS_INC(udp.rterr);
|
|
|
|
return ERR_RTE;
|
|
|
|
}
|
2013-01-14 19:46:41 +00:00
|
|
|
#if LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP
|
2010-04-30 20:39:45 +00:00
|
|
|
return udp_sendto_if_chksum(pcb, p, dst_ip, dst_port, netif, have_chksum, chksum);
|
2013-01-14 19:46:41 +00:00
|
|
|
#else /* LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP */
|
2007-11-27 20:13:16 +00:00
|
|
|
return udp_sendto_if(pcb, p, dst_ip, dst_port, netif);
|
2013-01-14 19:46:41 +00:00
|
|
|
#endif /* LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP */
|
2004-03-11 19:41:22 +00:00
|
|
|
}
|
|
|
|
|
2003-01-27 13:58:45 +00:00
|
|
|
/**
|
2007-11-27 20:13:16 +00:00
|
|
|
* Send data to a specified address using UDP.
|
|
|
|
* The netif used for sending can be specified.
|
|
|
|
*
|
|
|
|
* This function exists mainly for DHCP, to be able to send UDP packets
|
|
|
|
* on a netif that is still down.
|
2003-01-27 13:58:45 +00:00
|
|
|
*
|
|
|
|
* @param pcb UDP PCB used to send the data.
|
2007-06-03 18:05:52 +00:00
|
|
|
* @param p chain of pbuf's to be sent.
|
2007-11-27 20:13:16 +00:00
|
|
|
* @param dst_ip Destination IP address.
|
|
|
|
* @param dst_port Destination UDP port.
|
|
|
|
* @param netif the netif used for sending.
|
2007-06-03 18:05:52 +00:00
|
|
|
*
|
2007-11-27 20:13:16 +00:00
|
|
|
* dst_ip & dst_port are expected to be in the same byte order as in the pcb.
|
2003-01-27 13:58:45 +00:00
|
|
|
*
|
2007-11-27 20:13:16 +00:00
|
|
|
* @return lwIP error code (@see udp_send for possible error codes)
|
2003-06-09 21:14:47 +00:00
|
|
|
*
|
2007-11-27 20:13:16 +00:00
|
|
|
* @see udp_disconnect() udp_send()
|
2003-01-27 13:58:45 +00:00
|
|
|
*/
|
2002-10-19 12:59:30 +00:00
|
|
|
err_t
|
2007-11-27 20:13:16 +00:00
|
|
|
udp_sendto_if(struct udp_pcb *pcb, struct pbuf *p,
|
2015-01-24 00:25:18 +00:00
|
|
|
const ip_addr_t *dst_ip, u16_t dst_port, struct netif *netif)
|
2002-10-19 12:59:30 +00:00
|
|
|
{
|
2013-01-14 19:46:41 +00:00
|
|
|
#if LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP
|
2010-04-30 20:39:45 +00:00
|
|
|
return udp_sendto_if_chksum(pcb, p, dst_ip, dst_port, netif, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Same as udp_sendto_if(), but with checksum */
|
|
|
|
err_t
|
2015-01-24 00:25:18 +00:00
|
|
|
udp_sendto_if_chksum(struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *dst_ip,
|
2010-04-30 20:39:45 +00:00
|
|
|
u16_t dst_port, struct netif *netif, u8_t have_chksum,
|
|
|
|
u16_t chksum)
|
|
|
|
{
|
2013-01-14 19:46:41 +00:00
|
|
|
#endif /* LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP */
|
2015-01-24 00:25:18 +00:00
|
|
|
const ip_addr_t *src_ip;
|
2015-04-09 20:21:15 +00:00
|
|
|
#if LWIP_IPV6 && LWIP_IPV4
|
|
|
|
ip_addr_t src_ip_tmp;
|
|
|
|
#endif /* LWIP_IPV6 && LWIP_IPV4 */
|
2014-04-06 18:32:37 +00:00
|
|
|
|
|
|
|
/* PCB local address is IP_ANY_ADDR? */
|
|
|
|
#if LWIP_IPV6
|
|
|
|
if (PCB_ISIPV6(pcb)) {
|
2015-04-09 20:21:15 +00:00
|
|
|
if (ip6_addr_isany(ip_2_ip6(&pcb->local_ip))) {
|
|
|
|
src_ip = ip6_2_ip(ip6_select_source_address(netif, ip_2_ip6(dst_ip)), &src_ip_tmp);
|
2014-04-06 18:32:37 +00:00
|
|
|
if (src_ip == NULL) {
|
|
|
|
/* No suitable source address was found. */
|
|
|
|
return ERR_RTE;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* use UDP PCB local IPv6 address as source address, if still valid. */
|
2015-04-09 20:21:15 +00:00
|
|
|
if (netif_get_ip6_addr_match(netif, ip_2_ip6(&pcb->local_ip)) < 0) {
|
2014-04-06 18:32:37 +00:00
|
|
|
/* Address isn't valid anymore. */
|
|
|
|
return ERR_RTE;
|
|
|
|
}
|
2015-04-09 20:21:15 +00:00
|
|
|
src_ip = &pcb->local_ip;
|
2014-04-06 18:32:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* LWIP_IPV6 */
|
2015-04-09 20:21:15 +00:00
|
|
|
#if LWIP_IPV4 && LWIP_IPV6
|
|
|
|
else
|
|
|
|
#endif /* LWIP_IPV4 && LWIP_IPV6 */
|
|
|
|
#if LWIP_IPV4
|
|
|
|
if (ip4_addr_isany(ip_2_ip4(&pcb->local_ip))) {
|
2014-04-06 18:32:37 +00:00
|
|
|
/* use outgoing network interface IP address as source address */
|
2015-04-09 20:21:15 +00:00
|
|
|
src_ip = ip4_2_ip(&netif->ip_addr, &src_ip_tmp);
|
2014-04-06 18:32:37 +00:00
|
|
|
} else {
|
|
|
|
/* check if UDP PCB local IP address is correct
|
|
|
|
* this could be an old address if netif->ip_addr has changed */
|
2015-04-09 20:21:15 +00:00
|
|
|
if (!ip4_addr_cmp(ip_2_ip4(&(pcb->local_ip)), &(netif->ip_addr))) {
|
2014-04-06 18:32:37 +00:00
|
|
|
/* local_ip doesn't match, drop the packet */
|
|
|
|
return ERR_VAL;
|
|
|
|
}
|
|
|
|
/* use UDP PCB local IP address as source address */
|
2015-04-09 20:21:15 +00:00
|
|
|
src_ip = &pcb->local_ip;
|
2014-04-06 18:32:37 +00:00
|
|
|
}
|
2015-04-09 20:21:15 +00:00
|
|
|
#endif /* LWIP_IPV4 */
|
2014-04-06 18:32:37 +00:00
|
|
|
#if LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP
|
|
|
|
return udp_sendto_if_src_chksum(pcb, p, dst_ip, dst_port, netif, have_chksum, chksum, src_ip);
|
|
|
|
#else /* LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP */
|
|
|
|
return udp_sendto_if_src(pcb, p, dst_ip, dst_port, netif, src_ip);
|
|
|
|
#endif /* LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP */
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Same as udp_sendto_if(), but with source address */
|
|
|
|
err_t
|
|
|
|
udp_sendto_if_src(struct udp_pcb *pcb, struct pbuf *p,
|
2015-01-24 00:25:18 +00:00
|
|
|
const ip_addr_t *dst_ip, u16_t dst_port, struct netif *netif, const ip_addr_t *src_ip)
|
2014-04-06 18:32:37 +00:00
|
|
|
{
|
|
|
|
#if LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP
|
|
|
|
return udp_sendto_if_src_chksum(pcb, p, dst_ip, dst_port, netif, 0, 0, src_ip);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Same as udp_sendto_if_src(), but with checksum */
|
|
|
|
err_t
|
2015-01-24 00:25:18 +00:00
|
|
|
udp_sendto_if_src_chksum(struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *dst_ip,
|
2014-04-06 18:32:37 +00:00
|
|
|
u16_t dst_port, struct netif *netif, u8_t have_chksum,
|
2015-01-24 00:25:18 +00:00
|
|
|
u16_t chksum, const ip_addr_t *src_ip)
|
2014-04-06 18:32:37 +00:00
|
|
|
{
|
|
|
|
#endif /* LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP */
|
|
|
|
struct udp_hdr *udphdr;
|
2002-10-19 12:59:30 +00:00
|
|
|
err_t err;
|
2003-03-25 12:58:22 +00:00
|
|
|
struct pbuf *q; /* q will be sent down the stack */
|
2011-05-25 17:16:35 +00:00
|
|
|
u8_t ip_proto;
|
2015-02-25 20:59:21 +00:00
|
|
|
u8_t ttl;
|
2002-10-19 12:59:30 +00:00
|
|
|
|
2015-04-09 20:21:15 +00:00
|
|
|
#if LWIP_IPV4 && IP_SOF_BROADCAST
|
2009-04-29 12:42:43 +00:00
|
|
|
/* broadcast filter? */
|
2011-12-17 21:12:01 +00:00
|
|
|
if (!ip_get_option(pcb, SOF_BROADCAST) &&
|
2011-05-17 19:35:14 +00:00
|
|
|
#if LWIP_IPV6
|
2011-05-28 09:30:43 +00:00
|
|
|
!PCB_ISIPV6(pcb) &&
|
2011-05-17 19:35:14 +00:00
|
|
|
#endif /* LWIP_IPV6 */
|
|
|
|
ip_addr_isbroadcast(dst_ip, netif) ) {
|
2009-11-22 15:14:46 +00:00
|
|
|
LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_LEVEL_SERIOUS,
|
|
|
|
("udp_sendto_if: SOF_BROADCAST not enabled on pcb %p\n", (void *)pcb));
|
2009-04-29 12:42:43 +00:00
|
|
|
return ERR_VAL;
|
|
|
|
}
|
2015-04-09 20:21:15 +00:00
|
|
|
#endif /* LWIP_IPV4 && IP_SOF_BROADCAST */
|
2009-04-29 12:42:43 +00:00
|
|
|
|
2003-04-16 07:39:48 +00:00
|
|
|
/* if the PCB is not yet bound to a port, bind it here */
|
2003-03-31 08:00:01 +00:00
|
|
|
if (pcb->local_port == 0) {
|
2009-11-22 15:14:46 +00:00
|
|
|
LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE, ("udp_send: not yet bound to a port, binding now\n"));
|
2015-04-09 20:21:15 +00:00
|
|
|
err = udp_bind(pcb, &pcb->local_ip, pcb->local_port);
|
2003-03-31 08:00:01 +00:00
|
|
|
if (err != ERR_OK) {
|
2009-11-22 15:14:46 +00:00
|
|
|
LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_LEVEL_SERIOUS, ("udp_send: forced port bind failed\n"));
|
2003-02-06 22:18:56 +00:00
|
|
|
return err;
|
2003-03-31 08:00:01 +00:00
|
|
|
}
|
2003-02-06 22:18:56 +00:00
|
|
|
}
|
2007-09-15 15:19:41 +00:00
|
|
|
|
2003-03-24 12:57:00 +00:00
|
|
|
/* not enough space to add an UDP header to first pbuf in given p chain? */
|
2007-03-21 12:55:00 +00:00
|
|
|
if (pbuf_header(p, UDP_HLEN)) {
|
2008-01-11 14:28:58 +00:00
|
|
|
/* allocate header in a separate new pbuf */
|
2003-03-25 12:58:22 +00:00
|
|
|
q = pbuf_alloc(PBUF_IP, UDP_HLEN, PBUF_RAM);
|
2003-01-27 13:58:45 +00:00
|
|
|
/* new header pbuf could not be allocated? */
|
2003-03-25 12:58:22 +00:00
|
|
|
if (q == NULL) {
|
2009-11-22 15:14:46 +00:00
|
|
|
LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_LEVEL_SERIOUS, ("udp_send: could not allocate header\n"));
|
2002-10-19 12:59:30 +00:00
|
|
|
return ERR_MEM;
|
|
|
|
}
|
2010-08-03 08:38:59 +00:00
|
|
|
if (p->tot_len != 0) {
|
|
|
|
/* chain header q in front of given pbuf p (only if p contains data) */
|
|
|
|
pbuf_chain(q, p);
|
|
|
|
}
|
2006-05-26 01:36:16 +00:00
|
|
|
/* first pbuf q points to header pbuf */
|
|
|
|
LWIP_DEBUGF(UDP_DEBUG,
|
|
|
|
("udp_send: added header pbuf %p before given pbuf %p\n", (void *)q, (void *)p));
|
2004-03-11 19:41:22 +00:00
|
|
|
} else {
|
2007-06-03 18:05:52 +00:00
|
|
|
/* adding space for header within p succeeded */
|
2003-03-25 12:58:22 +00:00
|
|
|
/* first pbuf q equals given pbuf */
|
|
|
|
q = p;
|
2003-06-10 10:45:29 +00:00
|
|
|
LWIP_DEBUGF(UDP_DEBUG, ("udp_send: added header in given pbuf %p\n", (void *)p));
|
2002-10-19 12:59:30 +00:00
|
|
|
}
|
2007-07-03 20:28:35 +00:00
|
|
|
LWIP_ASSERT("check that first pbuf can hold struct udp_hdr",
|
|
|
|
(q->len >= sizeof(struct udp_hdr)));
|
2006-05-26 01:36:16 +00:00
|
|
|
/* q now represents the packet to be sent */
|
2010-01-25 08:24:30 +00:00
|
|
|
udphdr = (struct udp_hdr *)q->payload;
|
2002-10-19 12:59:30 +00:00
|
|
|
udphdr->src = htons(pcb->local_port);
|
2007-11-27 20:13:16 +00:00
|
|
|
udphdr->dest = htons(dst_port);
|
2004-03-11 19:41:22 +00:00
|
|
|
/* in UDP, 0 checksum means 'no checksum' */
|
2015-04-09 20:21:15 +00:00
|
|
|
udphdr->chksum = 0x0000;
|
2002-10-19 12:59:30 +00:00
|
|
|
|
2010-07-12 09:34:11 +00:00
|
|
|
/* Multicast Loop? */
|
2015-04-09 20:21:15 +00:00
|
|
|
#if (LWIP_IPV4 && LWIP_IGMP) || (LWIP_IPV6 && LWIP_IPV6_MLD)
|
|
|
|
if (((pcb->flags & UDP_FLAGS_MULTICAST_LOOP) != 0) && ip_addr_ismulticast(dst_ip)) {
|
2010-07-12 09:34:11 +00:00
|
|
|
q->flags |= PBUF_FLAG_MCASTLOOP;
|
|
|
|
}
|
2015-04-09 20:21:15 +00:00
|
|
|
#endif /* (LWIP_IPV4 && LWIP_IGMP) || (LWIP_IPV6 && LWIP_IPV6_MLD) */
|
2010-07-12 09:34:11 +00:00
|
|
|
|
2005-11-25 12:03:38 +00:00
|
|
|
LWIP_DEBUGF(UDP_DEBUG, ("udp_send: sending datagram of length %"U16_F"\n", q->tot_len));
|
2003-06-09 21:14:47 +00:00
|
|
|
|
2007-06-10 12:02:24 +00:00
|
|
|
#if LWIP_UDPLITE
|
2003-01-27 13:58:45 +00:00
|
|
|
/* UDP Lite protocol? */
|
2003-04-16 07:39:48 +00:00
|
|
|
if (pcb->flags & UDP_FLAGS_UDPLITE) {
|
2007-10-07 20:19:23 +00:00
|
|
|
u16_t chklen, chklen_hdr;
|
2005-11-25 12:03:38 +00:00
|
|
|
LWIP_DEBUGF(UDP_DEBUG, ("udp_send: UDP LITE packet length %"U16_F"\n", q->tot_len));
|
2003-01-13 13:22:09 +00:00
|
|
|
/* set UDP message length in UDP header */
|
2007-10-07 20:19:23 +00:00
|
|
|
chklen_hdr = chklen = pcb->chksum_len_tx;
|
|
|
|
if ((chklen < sizeof(struct udp_hdr)) || (chklen > q->tot_len)) {
|
2007-06-11 18:03:57 +00:00
|
|
|
if (chklen != 0) {
|
|
|
|
LWIP_DEBUGF(UDP_DEBUG, ("udp_send: UDP LITE pcb->chksum_len is illegal: %"U16_F"\n", chklen));
|
|
|
|
}
|
|
|
|
/* For UDP-Lite, checksum length of 0 means checksum
|
|
|
|
over the complete packet. (See RFC 3828 chap. 3.1)
|
|
|
|
At least the UDP-Lite header must be covered by the
|
|
|
|
checksum, therefore, if chksum_len has an illegal
|
|
|
|
value, we generate the checksum over the complete
|
|
|
|
packet to be safe. */
|
2007-10-07 20:19:23 +00:00
|
|
|
chklen_hdr = 0;
|
|
|
|
chklen = q->tot_len;
|
2007-06-11 18:03:57 +00:00
|
|
|
}
|
2007-10-07 20:19:23 +00:00
|
|
|
udphdr->len = htons(chklen_hdr);
|
2002-10-19 12:59:30 +00:00
|
|
|
/* calculate checksum */
|
2011-05-17 19:35:14 +00:00
|
|
|
#if CHECKSUM_GEN_UDP
|
2011-05-25 17:16:35 +00:00
|
|
|
#if LWIP_CHECKSUM_ON_COPY
|
|
|
|
if (have_chksum) {
|
|
|
|
chklen = UDP_HLEN;
|
2011-05-17 19:35:14 +00:00
|
|
|
}
|
2011-05-25 17:16:35 +00:00
|
|
|
#endif /* LWIP_CHECKSUM_ON_COPY */
|
2015-04-09 20:21:15 +00:00
|
|
|
udphdr->chksum = ip_chksum_pseudo_partial(q, IP_PROTO_UDPLITE,
|
|
|
|
q->tot_len, chklen, src_ip, dst_ip);
|
2011-05-25 17:16:35 +00:00
|
|
|
#if LWIP_CHECKSUM_ON_COPY
|
|
|
|
if (have_chksum) {
|
|
|
|
u32_t acc;
|
|
|
|
acc = udphdr->chksum + (u16_t)~(chksum);
|
|
|
|
udphdr->chksum = FOLD_U32T(acc);
|
2011-05-17 19:35:14 +00:00
|
|
|
}
|
2011-05-25 17:16:35 +00:00
|
|
|
#endif /* LWIP_CHECKSUM_ON_COPY */
|
|
|
|
|
|
|
|
/* chksum zero must become 0xffff, as zero means 'no checksum' */
|
|
|
|
if (udphdr->chksum == 0x0000) {
|
|
|
|
udphdr->chksum = 0xffff;
|
2011-05-17 19:35:14 +00:00
|
|
|
}
|
2011-05-25 17:16:35 +00:00
|
|
|
#endif /* CHECKSUM_GEN_UDP */
|
|
|
|
|
|
|
|
ip_proto = IP_PROTO_UDPLITE;
|
2007-06-10 12:02:24 +00:00
|
|
|
} else
|
|
|
|
#endif /* LWIP_UDPLITE */
|
|
|
|
{ /* UDP */
|
2005-11-25 12:03:38 +00:00
|
|
|
LWIP_DEBUGF(UDP_DEBUG, ("udp_send: UDP packet length %"U16_F"\n", q->tot_len));
|
2003-03-25 12:58:22 +00:00
|
|
|
udphdr->len = htons(q->tot_len);
|
2002-10-19 12:59:30 +00:00
|
|
|
/* calculate checksum */
|
2011-05-25 17:16:35 +00:00
|
|
|
#if CHECKSUM_GEN_UDP
|
2011-05-17 19:35:14 +00:00
|
|
|
/* Checksum is mandatory over IPv6. */
|
2011-05-25 17:16:35 +00:00
|
|
|
if (PCB_ISIPV6(pcb) || (pcb->flags & UDP_FLAGS_NOCHKSUM) == 0) {
|
2010-04-30 20:39:45 +00:00
|
|
|
u16_t udpchksum;
|
|
|
|
#if LWIP_CHECKSUM_ON_COPY
|
|
|
|
if (have_chksum) {
|
|
|
|
u32_t acc;
|
2015-04-09 20:21:15 +00:00
|
|
|
udpchksum = ip_chksum_pseudo_partial(q, IP_PROTO_UDP,
|
|
|
|
q->tot_len, UDP_HLEN, src_ip, dst_ip);
|
2010-04-30 20:39:45 +00:00
|
|
|
acc = udpchksum + (u16_t)~(chksum);
|
|
|
|
udpchksum = FOLD_U32T(acc);
|
|
|
|
} else
|
|
|
|
#endif /* LWIP_CHECKSUM_ON_COPY */
|
|
|
|
{
|
2015-04-09 20:21:15 +00:00
|
|
|
udpchksum = ip_chksum_pseudo(q, IP_PROTO_UDP, q->tot_len,
|
|
|
|
src_ip, dst_ip);
|
2010-04-30 20:39:45 +00:00
|
|
|
}
|
|
|
|
|
2003-01-27 13:58:45 +00:00
|
|
|
/* chksum zero must become 0xffff, as zero means 'no checksum' */
|
2010-04-30 20:39:45 +00:00
|
|
|
if (udpchksum == 0x0000) {
|
|
|
|
udpchksum = 0xffff;
|
2010-01-13 15:17:01 +00:00
|
|
|
}
|
2010-04-30 20:39:45 +00:00
|
|
|
udphdr->chksum = udpchksum;
|
2002-10-19 12:59:30 +00:00
|
|
|
}
|
2010-03-14 12:35:30 +00:00
|
|
|
#endif /* CHECKSUM_GEN_UDP */
|
2011-05-25 17:16:35 +00:00
|
|
|
ip_proto = IP_PROTO_UDP;
|
2002-10-19 12:59:30 +00:00
|
|
|
}
|
2011-05-25 17:16:35 +00:00
|
|
|
|
2015-02-25 20:59:21 +00:00
|
|
|
/* Determine TTL to use */
|
|
|
|
#if LWIP_IGMP
|
|
|
|
ttl = (ip_addr_ismulticast(dst_ip) ? pcb->mcast_ttl : pcb->ttl);
|
|
|
|
#else
|
|
|
|
ttl = pcb->ttl;
|
|
|
|
#endif
|
|
|
|
|
2011-05-25 17:16:35 +00:00
|
|
|
LWIP_DEBUGF(UDP_DEBUG, ("udp_send: UDP checksum 0x%04"X16_F"\n", udphdr->chksum));
|
|
|
|
LWIP_DEBUGF(UDP_DEBUG, ("udp_send: ip_output_if (,,,,0x%02"X16_F",)\n", (u16_t)ip_proto));
|
|
|
|
/* output to IP */
|
|
|
|
NETIF_SET_HWADDRHINT(netif, &(pcb->addr_hint));
|
2015-04-09 20:21:15 +00:00
|
|
|
err = ip_output_if_src(PCB_ISIPV6(pcb), q, src_ip, dst_ip, ttl, pcb->tos, ip_proto, netif);
|
2011-05-25 17:16:35 +00:00
|
|
|
NETIF_SET_HWADDRHINT(netif, NULL);
|
|
|
|
|
2014-09-18 19:15:13 +00:00
|
|
|
/* TODO: must this be increased even if error occurred? */
|
2004-03-11 19:41:22 +00:00
|
|
|
snmp_inc_udpoutdatagrams();
|
2003-03-25 12:58:22 +00:00
|
|
|
|
2008-01-11 14:28:58 +00:00
|
|
|
/* did we chain a separate header pbuf earlier? */
|
2003-03-25 12:58:22 +00:00
|
|
|
if (q != p) {
|
2004-03-11 19:41:22 +00:00
|
|
|
/* free the header pbuf */
|
2006-05-26 01:36:16 +00:00
|
|
|
pbuf_free(q);
|
|
|
|
q = NULL;
|
|
|
|
/* p is still referenced by the caller, and will live on */
|
2002-10-19 12:59:30 +00:00
|
|
|
}
|
2003-06-09 21:14:47 +00:00
|
|
|
|
2003-11-14 13:17:23 +00:00
|
|
|
UDP_STATS_INC(udp.xmit);
|
2002-10-19 12:59:30 +00:00
|
|
|
return err;
|
|
|
|
}
|
2003-03-25 12:58:22 +00:00
|
|
|
|
2003-01-27 13:58:45 +00:00
|
|
|
/**
|
|
|
|
* Bind an UDP PCB.
|
|
|
|
*
|
|
|
|
* @param pcb UDP PCB to be bound with a local address ipaddr and port.
|
|
|
|
* @param ipaddr local IP address to bind with. Use IP_ADDR_ANY to
|
|
|
|
* bind to all local interfaces.
|
2007-06-03 18:05:52 +00:00
|
|
|
* @param port local UDP port to bind with. Use 0 to automatically bind
|
|
|
|
* to a random port between UDP_LOCAL_PORT_RANGE_START and
|
|
|
|
* UDP_LOCAL_PORT_RANGE_END.
|
2003-01-27 13:58:45 +00:00
|
|
|
*
|
2007-05-17 12:21:32 +00:00
|
|
|
* ipaddr & port are expected to be in the same byte order as in the pcb.
|
|
|
|
*
|
2003-01-27 13:58:45 +00:00
|
|
|
* @return lwIP error code.
|
2014-09-18 19:15:13 +00:00
|
|
|
* - ERR_OK. Successful. No error occurred.
|
2003-01-27 13:58:45 +00:00
|
|
|
* - ERR_USE. The specified ipaddr and port are already bound to by
|
|
|
|
* another UDP PCB.
|
2003-06-09 21:14:47 +00:00
|
|
|
*
|
2003-01-27 13:58:45 +00:00
|
|
|
* @see udp_disconnect()
|
|
|
|
*/
|
2002-10-19 12:59:30 +00:00
|
|
|
err_t
|
2015-01-24 00:25:18 +00:00
|
|
|
udp_bind(struct udp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port)
|
2002-10-19 12:59:30 +00:00
|
|
|
{
|
|
|
|
struct udp_pcb *ipcb;
|
2003-02-14 15:49:02 +00:00
|
|
|
u8_t rebind;
|
2005-11-25 12:03:38 +00:00
|
|
|
|
2009-11-22 15:14:46 +00:00
|
|
|
LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE, ("udp_bind(ipaddr = "));
|
2015-04-09 20:21:15 +00:00
|
|
|
ip_addr_debug_print(UDP_DEBUG | LWIP_DBG_TRACE, ipaddr);
|
2009-11-22 15:14:46 +00:00
|
|
|
LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE, (", port = %"U16_F")\n", port));
|
2003-11-14 13:17:23 +00:00
|
|
|
|
2003-02-14 15:49:02 +00:00
|
|
|
rebind = 0;
|
2003-01-22 16:18:05 +00:00
|
|
|
/* Check for double bind and rebind of the same pcb */
|
2003-04-16 07:39:48 +00:00
|
|
|
for (ipcb = udp_pcbs; ipcb != NULL; ipcb = ipcb->next) {
|
2003-06-09 21:14:47 +00:00
|
|
|
/* is this UDP PCB already on active list? */
|
2003-01-22 16:18:05 +00:00
|
|
|
if (pcb == ipcb) {
|
2003-04-01 14:52:41 +00:00
|
|
|
/* pcb may occur at most once in active list */
|
|
|
|
LWIP_ASSERT("rebind == 0", rebind == 0);
|
|
|
|
/* pcb already in list, just rebind */
|
2003-06-09 21:14:47 +00:00
|
|
|
rebind = 1;
|
2003-01-27 13:58:45 +00:00
|
|
|
}
|
2003-11-14 13:17:23 +00:00
|
|
|
|
2010-05-12 22:29:58 +00:00
|
|
|
/* By default, we don't allow to bind to a port that any other udp
|
2014-09-18 19:15:13 +00:00
|
|
|
PCB is already bound to, unless *all* PCBs with that port have tha
|
2010-05-12 22:29:58 +00:00
|
|
|
REUSEADDR flag set. */
|
|
|
|
#if SO_REUSE
|
2011-12-17 21:12:01 +00:00
|
|
|
else if (!ip_get_option(pcb, SOF_REUSEADDR) &&
|
|
|
|
!ip_get_option(ipcb, SOF_REUSEADDR)) {
|
2010-05-12 22:29:58 +00:00
|
|
|
#else /* SO_REUSE */
|
|
|
|
/* port matches that of PCB in list and REUSEADDR not set -> reject */
|
2010-01-13 15:17:01 +00:00
|
|
|
else {
|
2010-05-12 22:29:58 +00:00
|
|
|
#endif /* SO_REUSE */
|
2011-05-25 17:16:35 +00:00
|
|
|
if ((ipcb->local_port == port) && IP_PCB_IPVER_EQ(pcb, ipcb) &&
|
2006-05-26 01:36:16 +00:00
|
|
|
/* IP address matches, or one is IP_ADDR_ANY? */
|
2015-04-09 20:21:15 +00:00
|
|
|
(ip_addr_isany(&ipcb->local_ip) ||
|
|
|
|
ip_addr_isany(ipaddr) ||
|
|
|
|
ip_addr_cmp(&ipcb->local_ip, ipaddr))) {
|
2006-05-26 01:36:16 +00:00
|
|
|
/* other PCB already binds to this local IP and port */
|
|
|
|
LWIP_DEBUGF(UDP_DEBUG,
|
|
|
|
("udp_bind: local port %"U16_F" already bound by another pcb\n", port));
|
|
|
|
return ERR_USE;
|
|
|
|
}
|
2010-01-13 15:17:01 +00:00
|
|
|
}
|
2002-10-19 12:59:30 +00:00
|
|
|
}
|
2003-11-14 13:17:23 +00:00
|
|
|
|
2015-04-09 20:21:15 +00:00
|
|
|
ip_addr_set_ipaddr(&pcb->local_ip, ipaddr);
|
2006-05-26 01:36:16 +00:00
|
|
|
|
2003-04-01 14:52:41 +00:00
|
|
|
/* no port specified? */
|
2003-02-14 15:49:02 +00:00
|
|
|
if (port == 0) {
|
2011-09-11 10:44:01 +00:00
|
|
|
port = udp_new_port();
|
|
|
|
if (port == 0) {
|
2003-03-19 16:04:54 +00:00
|
|
|
/* no more ports available in local range */
|
2003-06-10 10:45:29 +00:00
|
|
|
LWIP_DEBUGF(UDP_DEBUG, ("udp_bind: out of free UDP ports\n"));
|
2003-03-19 16:04:54 +00:00
|
|
|
return ERR_USE;
|
2003-06-09 21:14:47 +00:00
|
|
|
}
|
2003-02-06 22:18:56 +00:00
|
|
|
}
|
2003-01-21 14:09:31 +00:00
|
|
|
pcb->local_port = port;
|
2006-09-01 07:14:50 +00:00
|
|
|
snmp_insert_udpidx_tree(pcb);
|
2003-04-01 14:52:41 +00:00
|
|
|
/* pcb not active yet? */
|
2003-01-22 16:18:05 +00:00
|
|
|
if (rebind == 0) {
|
2003-04-01 14:52:41 +00:00
|
|
|
/* place the PCB on the active list if not already there */
|
2003-01-22 16:18:05 +00:00
|
|
|
pcb->next = udp_pcbs;
|
|
|
|
udp_pcbs = pcb;
|
2003-06-09 21:14:47 +00:00
|
|
|
}
|
2011-05-17 19:35:14 +00:00
|
|
|
LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("udp_bind: bound to "));
|
2015-04-09 20:21:15 +00:00
|
|
|
ip_addr_debug_print(UDP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, &pcb->local_ip);
|
2011-05-17 19:35:14 +00:00
|
|
|
LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, (", port %"U16_F")\n", pcb->local_port));
|
2002-10-19 12:59:30 +00:00
|
|
|
return ERR_OK;
|
|
|
|
}
|
2011-05-25 17:16:35 +00:00
|
|
|
|
2003-01-27 13:58:45 +00:00
|
|
|
/**
|
|
|
|
* Connect an UDP PCB.
|
|
|
|
*
|
2003-02-14 15:49:02 +00:00
|
|
|
* This will associate the UDP PCB with the remote address.
|
|
|
|
*
|
2003-01-27 13:58:45 +00:00
|
|
|
* @param pcb UDP PCB to be connected with remote address ipaddr and port.
|
|
|
|
* @param ipaddr remote IP address to connect with.
|
|
|
|
* @param port remote UDP port to connect with.
|
|
|
|
*
|
|
|
|
* @return lwIP error code
|
2003-06-09 21:14:47 +00:00
|
|
|
*
|
2007-05-17 12:21:32 +00:00
|
|
|
* ipaddr & port are expected to be in the same byte order as in the pcb.
|
|
|
|
*
|
2007-06-03 18:05:52 +00:00
|
|
|
* The udp pcb is bound to a random local port if not already bound.
|
|
|
|
*
|
2003-01-27 13:58:45 +00:00
|
|
|
* @see udp_disconnect()
|
|
|
|
*/
|
2002-10-19 12:59:30 +00:00
|
|
|
err_t
|
2015-01-24 00:25:18 +00:00
|
|
|
udp_connect(struct udp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port)
|
2002-10-19 12:59:30 +00:00
|
|
|
{
|
|
|
|
struct udp_pcb *ipcb;
|
2003-02-06 22:18:56 +00:00
|
|
|
|
2003-05-01 13:24:01 +00:00
|
|
|
if (pcb->local_port == 0) {
|
2015-04-09 20:21:15 +00:00
|
|
|
err_t err = udp_bind(pcb, &pcb->local_ip, pcb->local_port);
|
2010-01-13 15:17:01 +00:00
|
|
|
if (err != ERR_OK) {
|
2003-02-10 13:47:47 +00:00
|
|
|
return err;
|
2010-01-13 15:17:01 +00:00
|
|
|
}
|
2003-02-06 22:18:56 +00:00
|
|
|
}
|
|
|
|
|
2015-04-09 20:21:15 +00:00
|
|
|
ip_addr_set_ipaddr(&pcb->remote_ip, ipaddr);
|
2002-10-19 12:59:30 +00:00
|
|
|
pcb->remote_port = port;
|
2003-05-20 11:23:59 +00:00
|
|
|
pcb->flags |= UDP_FLAGS_CONNECTED;
|
2003-02-14 15:49:02 +00:00
|
|
|
/** TODO: this functionality belongs in upper layers */
|
2003-06-27 20:46:11 +00:00
|
|
|
#ifdef LWIP_UDP_TODO
|
2011-05-17 19:35:14 +00:00
|
|
|
#if LWIP_IPV6
|
2011-05-28 09:30:43 +00:00
|
|
|
if (!PCB_ISIPV6(pcb))
|
2011-05-17 19:35:14 +00:00
|
|
|
#endif /* LWIP_IPV6 */
|
|
|
|
{
|
|
|
|
/* Nail down local IP for netconn_addr()/getsockname() */
|
2015-04-09 20:21:15 +00:00
|
|
|
if (ip_addr_isany(&pcb->local_ip) && !ip_addr_isany(&pcb->remote_ip)) {
|
2011-05-17 19:35:14 +00:00
|
|
|
struct netif *netif;
|
|
|
|
|
2015-04-09 20:21:15 +00:00
|
|
|
if ((netif = ip_route(PCB_ISIPV6(pcb), (const ip_addr_t*)NULL, &pcb->remote_ip)) == NULL) {
|
|
|
|
LWIP_DEBUGF(UDP_DEBUG, ("udp_connect: No route to %s\n", ipaddr_ntoa(&pcb->remote_ip)));
|
2011-05-17 19:35:14 +00:00
|
|
|
UDP_STATS_INC(udp.rterr);
|
|
|
|
return ERR_RTE;
|
|
|
|
}
|
|
|
|
/** TODO: this will bind the udp pcb locally, to the interface which
|
|
|
|
is used to route output packets to the remote address. However, we
|
|
|
|
might want to accept incoming packets on any interface! */
|
2015-04-09 20:21:15 +00:00
|
|
|
ip_netif_get_local_ip(PCB_ISIPV6(pcb), netif, &pcb->remote_ip, &pcb->local_ip);
|
|
|
|
} else if (ip_addr_isany(&pcb->remote_ip)) {
|
|
|
|
ip_addr_set_any(PCB_ISIPV6(pcb), &pcb->local_ip);
|
2003-02-06 22:18:56 +00:00
|
|
|
}
|
|
|
|
}
|
2003-02-10 13:47:47 +00:00
|
|
|
#endif
|
2011-05-17 19:35:14 +00:00
|
|
|
LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("udp_connect: connected to "));
|
2015-04-09 20:21:15 +00:00
|
|
|
ip_addr_debug_print(UDP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE,
|
|
|
|
&pcb->remote_ip);
|
2011-05-17 19:35:14 +00:00
|
|
|
LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, (", port %"U16_F")\n", pcb->remote_port));
|
2003-04-04 08:14:49 +00:00
|
|
|
|
2002-10-19 12:59:30 +00:00
|
|
|
/* Insert UDP PCB into the list of active UDP PCBs. */
|
2006-05-26 01:36:16 +00:00
|
|
|
for (ipcb = udp_pcbs; ipcb != NULL; ipcb = ipcb->next) {
|
2003-05-01 13:24:01 +00:00
|
|
|
if (pcb == ipcb) {
|
2003-01-27 13:58:45 +00:00
|
|
|
/* already on the list, just return */
|
2002-10-19 12:59:30 +00:00
|
|
|
return ERR_OK;
|
|
|
|
}
|
|
|
|
}
|
2003-01-27 13:58:45 +00:00
|
|
|
/* PCB not yet on the list, add PCB now */
|
2002-10-19 12:59:30 +00:00
|
|
|
pcb->next = udp_pcbs;
|
|
|
|
udp_pcbs = pcb;
|
|
|
|
return ERR_OK;
|
|
|
|
}
|
2003-01-22 16:18:05 +00:00
|
|
|
|
2007-06-03 18:05:52 +00:00
|
|
|
/**
|
|
|
|
* Disconnect a UDP PCB
|
|
|
|
*
|
|
|
|
* @param pcb the udp pcb to disconnect.
|
|
|
|
*/
|
2003-01-22 16:18:05 +00:00
|
|
|
void
|
|
|
|
udp_disconnect(struct udp_pcb *pcb)
|
|
|
|
{
|
2004-03-11 20:45:09 +00:00
|
|
|
/* reset remote address association */
|
2015-04-09 20:21:15 +00:00
|
|
|
ip_addr_set_any(PCB_ISIPV6(pcb), &pcb->remote_ip);
|
2004-03-11 20:45:09 +00:00
|
|
|
pcb->remote_port = 0;
|
|
|
|
/* mark PCB as unconnected */
|
2003-06-09 21:14:47 +00:00
|
|
|
pcb->flags &= ~UDP_FLAGS_CONNECTED;
|
2003-01-22 16:18:05 +00:00
|
|
|
}
|
2003-11-14 13:17:23 +00:00
|
|
|
|
2007-06-03 18:05:52 +00:00
|
|
|
/**
|
|
|
|
* Set a receive callback for a UDP PCB
|
|
|
|
*
|
|
|
|
* This callback will be called when receiving a datagram for the pcb.
|
|
|
|
*
|
2014-09-18 19:15:13 +00:00
|
|
|
* @param pcb the pcb for which to set the recv callback
|
2007-06-03 18:05:52 +00:00
|
|
|
* @param recv function pointer of the callback function
|
2007-08-09 22:21:44 +00:00
|
|
|
* @param recv_arg additional argument to pass to the callback function
|
2007-06-03 18:05:52 +00:00
|
|
|
*/
|
2002-10-19 12:59:30 +00:00
|
|
|
void
|
2010-01-14 20:02:15 +00:00
|
|
|
udp_recv(struct udp_pcb *pcb, udp_recv_fn recv, void *recv_arg)
|
2002-10-19 12:59:30 +00:00
|
|
|
{
|
2003-01-27 13:58:45 +00:00
|
|
|
/* remember recv() callback and user data */
|
2015-04-09 20:21:15 +00:00
|
|
|
pcb->recv = recv;
|
2002-10-19 12:59:30 +00:00
|
|
|
pcb->recv_arg = recv_arg;
|
|
|
|
}
|
2006-05-26 01:36:16 +00:00
|
|
|
|
2003-01-27 13:58:45 +00:00
|
|
|
/**
|
|
|
|
* Remove an UDP PCB.
|
|
|
|
*
|
|
|
|
* @param pcb UDP PCB to be removed. The PCB is removed from the list of
|
|
|
|
* UDP PCB's and the data structure is freed from memory.
|
2003-06-09 21:14:47 +00:00
|
|
|
*
|
2003-01-27 13:58:45 +00:00
|
|
|
* @see udp_new()
|
|
|
|
*/
|
2002-10-19 12:59:30 +00:00
|
|
|
void
|
|
|
|
udp_remove(struct udp_pcb *pcb)
|
|
|
|
{
|
|
|
|
struct udp_pcb *pcb2;
|
2006-09-01 07:14:50 +00:00
|
|
|
|
|
|
|
snmp_delete_udpidx_tree(pcb);
|
2003-01-27 13:58:45 +00:00
|
|
|
/* pcb to be removed is first in list? */
|
|
|
|
if (udp_pcbs == pcb) {
|
|
|
|
/* make list start at 2nd pcb */
|
2002-10-19 12:59:30 +00:00
|
|
|
udp_pcbs = udp_pcbs->next;
|
2006-05-26 01:36:16 +00:00
|
|
|
/* pcb not 1st in list */
|
2010-01-13 15:17:01 +00:00
|
|
|
} else {
|
2006-05-26 01:36:16 +00:00
|
|
|
for (pcb2 = udp_pcbs; pcb2 != NULL; pcb2 = pcb2->next) {
|
|
|
|
/* find pcb in udp_pcbs list */
|
|
|
|
if (pcb2->next != NULL && pcb2->next == pcb) {
|
2006-11-17 10:51:13 +00:00
|
|
|
/* remove pcb from list */
|
|
|
|
pcb2->next = pcb->next;
|
2006-05-26 01:36:16 +00:00
|
|
|
}
|
2002-10-19 12:59:30 +00:00
|
|
|
}
|
2010-01-13 15:17:01 +00:00
|
|
|
}
|
2003-06-09 21:14:47 +00:00
|
|
|
memp_free(MEMP_UDP_PCB, pcb);
|
2002-10-19 12:59:30 +00:00
|
|
|
}
|
2006-05-26 01:36:16 +00:00
|
|
|
|
2003-01-27 13:58:45 +00:00
|
|
|
/**
|
|
|
|
* Create a UDP PCB.
|
|
|
|
*
|
|
|
|
* @return The UDP PCB which was created. NULL if the PCB data structure
|
|
|
|
* could not be allocated.
|
2003-06-09 21:14:47 +00:00
|
|
|
*
|
2003-01-27 13:58:45 +00:00
|
|
|
* @see udp_remove()
|
|
|
|
*/
|
2002-10-19 12:59:30 +00:00
|
|
|
struct udp_pcb *
|
2006-05-26 01:36:16 +00:00
|
|
|
udp_new(void)
|
|
|
|
{
|
2002-10-19 12:59:30 +00:00
|
|
|
struct udp_pcb *pcb;
|
2010-01-25 08:24:30 +00:00
|
|
|
pcb = (struct udp_pcb *)memp_malloc(MEMP_UDP_PCB);
|
2003-01-27 13:58:45 +00:00
|
|
|
/* could allocate UDP PCB? */
|
2003-05-01 13:24:01 +00:00
|
|
|
if (pcb != NULL) {
|
2007-06-03 18:05:52 +00:00
|
|
|
/* UDP Lite: by initializing to all zeroes, chksum_len is set to 0
|
|
|
|
* which means checksum is generated over the whole datagram per default
|
|
|
|
* (recommended as default by RFC 3828). */
|
2003-01-27 13:58:45 +00:00
|
|
|
/* initialize PCB to all zeroes */
|
2002-12-18 10:40:01 +00:00
|
|
|
memset(pcb, 0, sizeof(struct udp_pcb));
|
2004-01-20 13:23:52 +00:00
|
|
|
pcb->ttl = UDP_TTL;
|
2015-02-25 20:59:21 +00:00
|
|
|
#if LWIP_IGMP
|
|
|
|
pcb->mcast_ttl = UDP_TTL;
|
|
|
|
#endif
|
2002-10-19 12:59:30 +00:00
|
|
|
}
|
2003-01-27 13:58:45 +00:00
|
|
|
return pcb;
|
2002-10-19 12:59:30 +00:00
|
|
|
}
|
2003-11-14 13:17:23 +00:00
|
|
|
|
2011-05-17 19:35:14 +00:00
|
|
|
#if LWIP_IPV6
|
|
|
|
/**
|
|
|
|
* Create a UDP PCB for IPv6.
|
|
|
|
*
|
|
|
|
* @return The UDP PCB which was created. NULL if the PCB data structure
|
|
|
|
* could not be allocated.
|
|
|
|
*
|
|
|
|
* @see udp_remove()
|
|
|
|
*/
|
|
|
|
struct udp_pcb *
|
|
|
|
udp_new_ip6(void)
|
|
|
|
{
|
|
|
|
struct udp_pcb *pcb;
|
|
|
|
pcb = udp_new();
|
2015-04-09 20:21:15 +00:00
|
|
|
#if LWIP_IPV4
|
2011-05-25 17:16:35 +00:00
|
|
|
ip_set_v6(pcb, 1);
|
2015-04-09 20:21:15 +00:00
|
|
|
#endif /* LWIP_IPV4 */
|
2011-05-17 19:35:14 +00:00
|
|
|
return pcb;
|
|
|
|
}
|
|
|
|
#endif /* LWIP_IPV6 */
|
|
|
|
|
2015-04-09 20:21:15 +00:00
|
|
|
#if LWIP_IPV4
|
2015-02-26 21:17:30 +00:00
|
|
|
/** This function is called from netif.c when address is changed
|
|
|
|
*
|
|
|
|
* @param old_addr IPv4 address of the netif before change
|
|
|
|
* @param new_addr IPv4 address of the netif after change
|
|
|
|
*/
|
2015-04-09 20:21:15 +00:00
|
|
|
void udp_netif_ipv4_addr_changed(const ip4_addr_t* old_addr, const ip4_addr_t* new_addr)
|
2015-02-26 21:17:30 +00:00
|
|
|
{
|
|
|
|
struct udp_pcb* upcb;
|
|
|
|
|
2015-04-09 20:21:15 +00:00
|
|
|
if (!ip4_addr_isany(new_addr)) {
|
2015-03-06 19:25:51 +00:00
|
|
|
for (upcb = udp_pcbs; upcb != NULL; upcb = upcb->next) {
|
2015-04-09 20:21:15 +00:00
|
|
|
/* Is this an IPv4 pcb? */
|
2015-04-23 05:24:45 +00:00
|
|
|
if (!IP_IS_V6_VAL(upcb->local_ip)) {
|
2015-04-09 20:21:15 +00:00
|
|
|
/* PCB bound to current local interface address? */
|
|
|
|
if (!ip4_addr_isany(ip_2_ip4(&upcb->local_ip)) &&
|
|
|
|
ip4_addr_cmp(ip_2_ip4(&upcb->local_ip), old_addr)) {
|
|
|
|
/* The PCB is bound to the old ipaddr and
|
|
|
|
* is set to bound to the new one instead */
|
|
|
|
ip_addr_copy_from_ip4(upcb->local_ip, *new_addr);
|
|
|
|
}
|
2015-03-06 19:25:51 +00:00
|
|
|
}
|
2015-02-26 21:17:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-04-09 20:21:15 +00:00
|
|
|
#endif /* LWIP_IPV4 */
|
2015-02-26 21:17:30 +00:00
|
|
|
|
2002-10-19 12:59:30 +00:00
|
|
|
#if UDP_DEBUG
|
2007-06-03 18:05:52 +00:00
|
|
|
/**
|
|
|
|
* Print UDP header information for debug purposes.
|
|
|
|
*
|
|
|
|
* @param udphdr pointer to the udp header in memory.
|
|
|
|
*/
|
2005-11-25 12:03:38 +00:00
|
|
|
void
|
2002-10-19 12:59:30 +00:00
|
|
|
udp_debug_print(struct udp_hdr *udphdr)
|
|
|
|
{
|
2003-06-10 10:45:29 +00:00
|
|
|
LWIP_DEBUGF(UDP_DEBUG, ("UDP header:\n"));
|
|
|
|
LWIP_DEBUGF(UDP_DEBUG, ("+-------------------------------+\n"));
|
2005-11-25 12:03:38 +00:00
|
|
|
LWIP_DEBUGF(UDP_DEBUG, ("| %5"U16_F" | %5"U16_F" | (src port, dest port)\n",
|
2006-05-26 01:36:16 +00:00
|
|
|
ntohs(udphdr->src), ntohs(udphdr->dest)));
|
2003-06-10 10:45:29 +00:00
|
|
|
LWIP_DEBUGF(UDP_DEBUG, ("+-------------------------------+\n"));
|
2005-11-25 12:03:38 +00:00
|
|
|
LWIP_DEBUGF(UDP_DEBUG, ("| %5"U16_F" | 0x%04"X16_F" | (len, chksum)\n",
|
2006-05-26 01:36:16 +00:00
|
|
|
ntohs(udphdr->len), ntohs(udphdr->chksum)));
|
2003-06-10 10:45:29 +00:00
|
|
|
LWIP_DEBUGF(UDP_DEBUG, ("+-------------------------------+\n"));
|
2002-10-19 12:59:30 +00:00
|
|
|
}
|
|
|
|
#endif /* UDP_DEBUG */
|
2003-11-14 13:17:23 +00:00
|
|
|
|
2002-10-19 12:59:30 +00:00
|
|
|
#endif /* LWIP_UDP */
|