A version of LWIP, provided for backwards compatibility.
Dependents: AA_DemoBoard DemoBoard HelloServerDemo DemoBoard_RangeIndicator ... more
udp.h
00001 /* 00002 * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 00003 * All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without modification, 00006 * are permitted provided that the following conditions are met: 00007 * 00008 * 1. Redistributions of source code must retain the above copyright notice, 00009 * this list of conditions and the following disclaimer. 00010 * 2. Redistributions in binary form must reproduce the above copyright notice, 00011 * this list of conditions and the following disclaimer in the documentation 00012 * and/or other materials provided with the distribution. 00013 * 3. The name of the author may not be used to endorse or promote products 00014 * derived from this software without specific prior written permission. 00015 * 00016 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 00017 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 00018 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 00019 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00020 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 00021 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00022 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00023 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 00024 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 00025 * OF SUCH DAMAGE. 00026 * 00027 * This file is part of the lwIP TCP/IP stack. 00028 * 00029 * Author: Adam Dunkels <adam@sics.se> 00030 * 00031 */ 00032 #ifndef __LWIP_UDP_H__ 00033 #define __LWIP_UDP_H__ 00034 00035 #include "lwip/opt.h" 00036 00037 #if LWIP_UDP /* don't build if not configured for use in lwipopts.h */ 00038 00039 #include "lwip/pbuf.h" 00040 #include "lwip/netif.h" 00041 #include "lwip/ip_addr.h" 00042 #include "lwip/ip.h" 00043 00044 #ifdef __cplusplus 00045 // XXX: WTF 00046 //extern "C" { 00047 #endif 00048 00049 #define UDP_HLEN 8 00050 00051 /* Fields are (of course) in network byte order. */ 00052 #ifdef PACK_STRUCT_USE_INCLUDES 00053 # include "arch/bpstruct.h" 00054 #endif 00055 PACK_STRUCT_BEGIN 00056 struct udp_hdr { 00057 PACK_STRUCT_FIELD(u16_t src); 00058 PACK_STRUCT_FIELD(u16_t dest); /* src/dest UDP ports */ 00059 PACK_STRUCT_FIELD(u16_t len); 00060 PACK_STRUCT_FIELD(u16_t chksum); 00061 } PACK_STRUCT_STRUCT; 00062 PACK_STRUCT_END 00063 #ifdef PACK_STRUCT_USE_INCLUDES 00064 # include "arch/epstruct.h" 00065 #endif 00066 00067 #define UDP_FLAGS_NOCHKSUM 0x01U 00068 #define UDP_FLAGS_UDPLITE 0x02U 00069 #define UDP_FLAGS_CONNECTED 0x04U 00070 00071 struct udp_pcb { 00072 /* Common members of all PCB types */ 00073 IP_PCB; 00074 00075 /* Protocol specific PCB members */ 00076 00077 struct udp_pcb *next; 00078 00079 u8_t flags; 00080 /* ports are in host byte order */ 00081 u16_t local_port, remote_port; 00082 00083 #if LWIP_IGMP 00084 /* outgoing network interface for multicast packets */ 00085 struct ip_addr multicast_ip; 00086 #endif /* LWIP_IGMP */ 00087 00088 #if LWIP_UDPLITE 00089 /* used for UDP_LITE only */ 00090 u16_t chksum_len_rx, chksum_len_tx; 00091 #endif /* LWIP_UDPLITE */ 00092 00093 /* receive callback function 00094 * addr and port are in same byte order as in the pcb 00095 * The callback is responsible for freeing the pbuf 00096 * if it's not used any more. 00097 * 00098 * @param arg user supplied argument (udp_pcb.recv_arg) 00099 * @param pcb the udp_pcb which received data 00100 * @param p the packet buffer that was received 00101 * @param addr the remote IP address from which the packet was received 00102 * @param port the remote port from which the packet was received 00103 */ 00104 void (* recv)(void *arg, struct udp_pcb *pcb, struct pbuf *p, 00105 struct ip_addr *addr, u16_t port); 00106 /* user-supplied argument for the recv callback */ 00107 void *recv_arg; 00108 }; 00109 /* udp_pcbs export for exernal reference (e.g. SNMP agent) */ 00110 extern struct udp_pcb *udp_pcbs; 00111 00112 /* The following functions is the application layer interface to the 00113 UDP code. */ 00114 struct udp_pcb * udp_new (void); 00115 void udp_remove (struct udp_pcb *pcb); 00116 err_t udp_bind (struct udp_pcb *pcb, struct ip_addr *ipaddr, 00117 u16_t port); 00118 err_t udp_connect (struct udp_pcb *pcb, struct ip_addr *ipaddr, 00119 u16_t port); 00120 void udp_disconnect (struct udp_pcb *pcb); 00121 void udp_recv (struct udp_pcb *pcb, 00122 void (* recv)(void *arg, struct udp_pcb *upcb, 00123 struct pbuf *p, 00124 struct ip_addr *addr, 00125 u16_t port), 00126 void *recv_arg); 00127 err_t udp_sendto_if (struct udp_pcb *pcb, struct pbuf *p, struct ip_addr *dst_ip, u16_t dst_port, struct netif *netif); 00128 err_t udp_sendto (struct udp_pcb *pcb, struct pbuf *p, struct ip_addr *dst_ip, u16_t dst_port); 00129 err_t udp_send (struct udp_pcb *pcb, struct pbuf *p); 00130 00131 #define udp_flags(pcb) ((pcb)->flags) 00132 #define udp_setflags(pcb, f) ((pcb)->flags = (f)) 00133 00134 /* The following functions are the lower layer interface to UDP. */ 00135 void udp_input (struct pbuf *p, struct netif *inp); 00136 00137 #define udp_init() /* Compatibility define, not init needed. */ 00138 00139 #if UDP_DEBUG 00140 void udp_debug_print(struct udp_hdr *udphdr); 00141 #else 00142 #define udp_debug_print(udphdr) 00143 #endif 00144 00145 #ifdef __cplusplus 00146 // XXX: WTF 00147 //} 00148 #endif 00149 00150 #endif /* LWIP_UDP */ 00151 00152 #endif /* __LWIP_UDP_H__ */
Generated on Tue Jul 12 2022 16:06:27 by 1.7.2