STM32F769IDiscovery  1.00
uDANTE Audio Networking with STM32F7 DISCO board
udp.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without modification,
6  * are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  * 3. The name of the author may not be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
19  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
21  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
24  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
25  * OF SUCH DAMAGE.
26  *
27  * This file is part of the lwIP TCP/IP stack.
28  *
29  * Author: Adam Dunkels <adam@sics.se>
30  *
31  */
32 #ifndef LWIP_HDR_UDP_H
33 #define LWIP_HDR_UDP_H
34 
35 #include "lwip/opt.h"
36 
37 #if LWIP_UDP /* don't build if not configured for use in lwipopts.h */
38 
39 #include "lwip/pbuf.h"
40 #include "lwip/netif.h"
41 #include "lwip/ip_addr.h"
42 #include "lwip/ip.h"
43 #include "lwip/ip6_addr.h"
44 
45 #ifdef __cplusplus
46 extern "C" {
47 #endif
48 
49 #define UDP_HLEN 8
50 
51 /* Fields are (of course) in network byte order. */
52 #ifdef PACK_STRUCT_USE_INCLUDES
53 # include "arch/bpstruct.h"
54 #endif
56 struct udp_hdr {
58  PACK_STRUCT_FIELD(u16_t dest); /* src/dest UDP ports */
60  PACK_STRUCT_FIELD(u16_t chksum);
63 #ifdef PACK_STRUCT_USE_INCLUDES
64 # include "arch/epstruct.h"
65 #endif
66 
67 #define UDP_FLAGS_NOCHKSUM 0x01U
68 #define UDP_FLAGS_UDPLITE 0x02U
69 #define UDP_FLAGS_CONNECTED 0x04U
70 #define UDP_FLAGS_MULTICAST_LOOP 0x08U
71 
72 struct udp_pcb;
73 
88 typedef void (*udp_recv_fn)(void *arg, struct udp_pcb *pcb, struct pbuf *p,
89  const ip_addr_t *addr, u16_t port);
90 
91 struct udp_pcb {
92 /* Common members of all PCB types */
93  IP_PCB;
94 
95 /* Protocol specific PCB members */
96 
97  struct udp_pcb *next;
98 
99  u8_t flags;
101  u16_t local_port, remote_port;
102 
103 #if LWIP_MULTICAST_TX_OPTIONS
104 
105  ip_addr_t multicast_ip;
107  u8_t mcast_ttl;
108 #endif /* LWIP_MULTICAST_TX_OPTIONS */
109 
110 #if LWIP_UDPLITE
111 
112  u16_t chksum_len_rx, chksum_len_tx;
113 #endif /* LWIP_UDPLITE */
114 
116  udp_recv_fn recv;
118  void *recv_arg;
119 };
120 /* udp_pcbs export for external reference (e.g. SNMP agent) */
121 extern struct udp_pcb *udp_pcbs;
122 
123 /* The following functions is the application layer interface to the
124  UDP code. */
125 struct udp_pcb * udp_new (void);
126 void udp_remove (struct udp_pcb *pcb);
127 err_t udp_bind (struct udp_pcb *pcb, const ip_addr_t *ipaddr,
128  u16_t port);
129 err_t udp_connect (struct udp_pcb *pcb, const ip_addr_t *ipaddr,
130  u16_t port);
131 void udp_disconnect (struct udp_pcb *pcb);
132 void udp_recv (struct udp_pcb *pcb, udp_recv_fn recv,
133  void *recv_arg);
134 err_t udp_sendto_if (struct udp_pcb *pcb, struct pbuf *p,
135  const ip_addr_t *dst_ip, u16_t dst_port,
136  struct netif *netif);
137 err_t udp_sendto_if_src(struct udp_pcb *pcb, struct pbuf *p,
138  const ip_addr_t *dst_ip, u16_t dst_port,
139  struct netif *netif, const ip_addr_t *src_ip);
140 err_t udp_sendto (struct udp_pcb *pcb, struct pbuf *p,
141  const ip_addr_t *dst_ip, u16_t dst_port);
142 err_t udp_send (struct udp_pcb *pcb, struct pbuf *p);
143 
144 #if LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP
145 err_t udp_sendto_if_chksum(struct udp_pcb *pcb, struct pbuf *p,
146  const ip_addr_t *dst_ip, u16_t dst_port,
147  struct netif *netif, u8_t have_chksum,
148  u16_t chksum);
149 err_t udp_sendto_chksum(struct udp_pcb *pcb, struct pbuf *p,
150  const ip_addr_t *dst_ip, u16_t dst_port,
151  u8_t have_chksum, u16_t chksum);
152 err_t udp_send_chksum(struct udp_pcb *pcb, struct pbuf *p,
153  u8_t have_chksum, u16_t chksum);
154 err_t udp_sendto_if_src_chksum(struct udp_pcb *pcb, struct pbuf *p,
155  const ip_addr_t *dst_ip, u16_t dst_port, struct netif *netif,
156  u8_t have_chksum, u16_t chksum, const ip_addr_t *src_ip);
157 #endif /* LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP */
158 
159 #define udp_flags(pcb) ((pcb)->flags)
160 #define udp_setflags(pcb, f) ((pcb)->flags = (f))
161 
162 /* The following functions are the lower layer interface to UDP. */
163 void udp_input (struct pbuf *p, struct netif *inp);
164 
165 void udp_init (void);
166 
167 #if LWIP_IPV6
168 struct udp_pcb * udp_new_ip6(void);
169 #endif /* LWIP_IPV6 */
170 
171 #if LWIP_MULTICAST_TX_OPTIONS
172 #define udp_set_multicast_netif_addr(pcb, ip4addr) ip_addr_copy_from_ip4((pcb)->multicast_ip, *(ip4addr))
173 #define udp_get_multicast_netif_addr(pcb) ip_2_ip4(&(pcb)->multicast_ip)
174 #define udp_set_multicast_ttl(pcb, value) do { (pcb)->mcast_ttl = value; } while(0)
175 #define udp_get_multicast_ttl(pcb) ((pcb)->mcast_ttl)
176 #endif /* LWIP_MULTICAST_TX_OPTIONS */
177 
178 #if UDP_DEBUG
179 void udp_debug_print(struct udp_hdr *udphdr);
180 #else
181 #define udp_debug_print(udphdr)
182 #endif
183 
184 #if LWIP_IPV4
185 void udp_netif_ipv4_addr_changed(const ip4_addr_t* old_addr, const ip4_addr_t* new_addr);
186 #endif /* LWIP_IPV4 */
187 
188 #ifdef __cplusplus
189 }
190 #endif
191 
192 #endif /* LWIP_UDP */
193 
194 #endif /* LWIP_HDR_UDP_H */
195 
#define PACK_STRUCT_STRUCT
Definition: arch.h:68
#define IP_PCB
Definition: ip.h:96
#define PACK_STRUCT_FIELD(x)
Definition: arch.h:72
Definition: pbuf.h:108
s8_t err_t
Definition: err.h:47
Definition: netif.h:182
#define PACK_STRUCT_BEGIN
Definition: arch.h:60
unsigned char u8_t
Definition: cc.h:38
ip6_addr_t ip_addr_t
Definition: ip_addr.h:194
#define PACK_STRUCT_END
Definition: arch.h:64
unsigned short u16_t
Definition: cc.h:40