Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
udp.h
00001 /** 00002 * @file 00003 * UDP API (to be used from TCPIP thread)\n 00004 * See also @ref udp_raw 00005 */ 00006 00007 /* 00008 * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 00009 * All rights reserved. 00010 * 00011 * Redistribution and use in source and binary forms, with or without modification, 00012 * are permitted provided that the following conditions are met: 00013 * 00014 * 1. Redistributions of source code must retain the above copyright notice, 00015 * this list of conditions and the following disclaimer. 00016 * 2. Redistributions in binary form must reproduce the above copyright notice, 00017 * this list of conditions and the following disclaimer in the documentation 00018 * and/or other materials provided with the distribution. 00019 * 3. The name of the author may not be used to endorse or promote products 00020 * derived from this software without specific prior written permission. 00021 * 00022 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 00023 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 00024 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 00025 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00026 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 00027 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00028 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00029 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 00030 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 00031 * OF SUCH DAMAGE. 00032 * 00033 * This file is part of the lwIP TCP/IP stack. 00034 * 00035 * Author: Adam Dunkels <adam@sics.se> 00036 * 00037 */ 00038 #ifndef LWIP_HDR_UDP_H 00039 #define LWIP_HDR_UDP_H 00040 00041 #include "lwip/opt.h" 00042 00043 #if LWIP_UDP /* don't build if not configured for use in lwipopts.h */ 00044 00045 #include "lwip/pbuf.h" 00046 #include "lwip/netif.h" 00047 #include "lwip/ip_addr.h" 00048 #include "lwip/ip.h" 00049 #include "lwip/ip6_addr.h" 00050 #include "lwip/prot/udp.h" 00051 00052 #ifdef __cplusplus 00053 extern "C" { 00054 #endif 00055 00056 #define UDP_FLAGS_NOCHKSUM 0x01U 00057 #define UDP_FLAGS_UDPLITE 0x02U 00058 #define UDP_FLAGS_CONNECTED 0x04U 00059 #define UDP_FLAGS_MULTICAST_LOOP 0x08U 00060 00061 struct udp_pcb; 00062 00063 /** Function prototype for udp pcb receive callback functions 00064 * addr and port are in same byte order as in the pcb 00065 * The callback is responsible for freeing the pbuf 00066 * if it's not used any more. 00067 * 00068 * ATTENTION: Be aware that 'addr' might point into the pbuf 'p' so freeing this pbuf 00069 * can make 'addr' invalid, too. 00070 * 00071 * @param arg user supplied argument (udp_pcb.recv_arg) 00072 * @param pcb the udp_pcb which received data 00073 * @param p the packet buffer that was received 00074 * @param addr the remote IP address from which the packet was received 00075 * @param port the remote port from which the packet was received 00076 */ 00077 typedef void (*udp_recv_fn)(void *arg, struct udp_pcb *pcb, struct pbuf *p, 00078 const ip_addr_t *addr, u16_t port); 00079 00080 /** the UDP protocol control block */ 00081 struct udp_pcb { 00082 /** Common members of all PCB types */ 00083 IP_PCB; 00084 00085 /* Protocol specific PCB members */ 00086 00087 struct udp_pcb *next; 00088 00089 u8_t flags; 00090 /** ports are in host byte order */ 00091 u16_t local_port, remote_port; 00092 00093 #if LWIP_MULTICAST_TX_OPTIONS 00094 /** outgoing network interface for multicast packets */ 00095 ip_addr_t multicast_ip; 00096 /** TTL for outgoing multicast packets */ 00097 u8_t mcast_ttl; 00098 #endif /* LWIP_MULTICAST_TX_OPTIONS */ 00099 00100 #if LWIP_UDPLITE 00101 /** used for UDP_LITE only */ 00102 u16_t chksum_len_rx, chksum_len_tx; 00103 #endif /* LWIP_UDPLITE */ 00104 00105 /** receive callback function */ 00106 udp_recv_fn recv; 00107 /** user-supplied argument for the recv callback */ 00108 void *recv_arg; 00109 }; 00110 /* udp_pcbs export for external reference (e.g. SNMP agent) */ 00111 extern struct udp_pcb *udp_pcbs; 00112 00113 /* The following functions is the application layer interface to the 00114 UDP code. */ 00115 struct udp_pcb * udp_new (void); 00116 struct udp_pcb * udp_new_ip_type(u8_t type); 00117 void udp_remove (struct udp_pcb *pcb); 00118 err_t udp_bind (struct udp_pcb *pcb, const ip_addr_t *ipaddr, 00119 u16_t port); 00120 err_t udp_connect (struct udp_pcb *pcb, const ip_addr_t *ipaddr, 00121 u16_t port); 00122 void udp_disconnect (struct udp_pcb *pcb); 00123 void udp_recv (struct udp_pcb *pcb, udp_recv_fn recv, 00124 void *recv_arg); 00125 err_t udp_sendto_if (struct udp_pcb *pcb, struct pbuf *p, 00126 const ip_addr_t *dst_ip, u16_t dst_port, 00127 struct netif *netif); 00128 err_t udp_sendto_if_src(struct udp_pcb *pcb, struct pbuf *p, 00129 const ip_addr_t *dst_ip, u16_t dst_port, 00130 struct netif *netif, const ip_addr_t *src_ip); 00131 err_t udp_sendto (struct udp_pcb *pcb, struct pbuf *p, 00132 const ip_addr_t *dst_ip, u16_t dst_port); 00133 err_t udp_send (struct udp_pcb *pcb, struct pbuf *p); 00134 00135 #if LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP 00136 err_t udp_sendto_if_chksum(struct udp_pcb *pcb, struct pbuf *p, 00137 const ip_addr_t *dst_ip, u16_t dst_port, 00138 struct netif *netif, u8_t have_chksum, 00139 u16_t chksum); 00140 err_t udp_sendto_chksum(struct udp_pcb *pcb, struct pbuf *p, 00141 const ip_addr_t *dst_ip, u16_t dst_port, 00142 u8_t have_chksum, u16_t chksum); 00143 err_t udp_send_chksum(struct udp_pcb *pcb, struct pbuf *p, 00144 u8_t have_chksum, u16_t chksum); 00145 err_t udp_sendto_if_src_chksum(struct udp_pcb *pcb, struct pbuf *p, 00146 const ip_addr_t *dst_ip, u16_t dst_port, struct netif *netif, 00147 u8_t have_chksum, u16_t chksum, const ip_addr_t *src_ip); 00148 #endif /* LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP */ 00149 00150 #define udp_flags(pcb) ((pcb)->flags) 00151 #define udp_setflags(pcb, f) ((pcb)->flags = (f)) 00152 00153 /* The following functions are the lower layer interface to UDP. */ 00154 void udp_input (struct pbuf *p, struct netif *inp); 00155 00156 void udp_init (void); 00157 00158 /* for compatibility with older implementation */ 00159 #define udp_new_ip6() udp_new_ip_type(IPADDR_TYPE_V6) 00160 00161 #if LWIP_MULTICAST_TX_OPTIONS 00162 #define udp_set_multicast_netif_addr(pcb, ip4addr) ip_addr_copy_from_ip4((pcb)->multicast_ip, *(ip4addr)) 00163 #define udp_get_multicast_netif_addr(pcb) ip_2_ip4(&(pcb)->multicast_ip) 00164 #define udp_set_multicast_ttl(pcb, value) do { (pcb)->mcast_ttl = value; } while(0) 00165 #define udp_get_multicast_ttl(pcb) ((pcb)->mcast_ttl) 00166 #endif /* LWIP_MULTICAST_TX_OPTIONS */ 00167 00168 #if UDP_DEBUG 00169 void udp_debug_print(struct udp_hdr *udphdr); 00170 #else 00171 #define udp_debug_print(udphdr) 00172 #endif 00173 00174 void udp_netif_ip_addr_changed(const ip_addr_t* old_addr, const ip_addr_t* new_addr); 00175 00176 #ifdef __cplusplus 00177 } 00178 #endif 00179 00180 #endif /* LWIP_UDP */ 00181 00182 #endif /* LWIP_HDR_UDP_H */
Generated on Thu Jul 14 2022 14:36:23 by
