1
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
102
103
104
105
107
108
109
110
111
112
113
114
115
116
117
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
162
163
164
165
166
167
168
169
170
171
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/* ... */
/* ... */
#ifndef LWIP_HDR_UDP_H
#define LWIP_HDR_UDP_H
#include "lwip/opt.h"
#if LWIP_UDP
#include "lwip/pbuf.h"
#include "lwip/netif.h"
#include "lwip/ip_addr.h"
#include "lwip/ip.h"
#include "lwip/ip6_addr.h"
#include "lwip/prot/udp.h"
6 includes
#ifdef __cplusplus
extern "C" {
#endif
#define UDP_FLAGS_NOCHKSUM 0x01U
#define UDP_FLAGS_UDPLITE 0x02U
#define UDP_FLAGS_CONNECTED 0x04U
#define UDP_FLAGS_MULTICAST_LOOP 0x08U
struct udp_pcb;
/* ... */
typedef void (*udp_recv_fn)(void *arg, struct udp_pcb *pcb, struct pbuf *p,
const ip_addr_t *addr, u16_t port);
struct udp_pcb {
IP_PCB;
struct udp_pcb *next;
u8_t flags;
u16_t local_port, remote_port;
#if LWIP_MULTICAST_TX_OPTIONS
#if LWIP_IPV4
ip4_addr_t mcast_ip4;/* ... */
#endif
u8_t mcast_ifindex;
u8_t mcast_ttl;/* ... */
#endif
#if LWIP_UDPLITE
u16_t chksum_len_rx, chksum_len_tx;/* ... */
#endif
udp_recv_fn recv;
void *recv_arg;
...};
extern struct udp_pcb *udp_pcbs;
/* ... */
struct udp_pcb * udp_new (void);
struct udp_pcb * udp_new_ip_type(u8_t type);
void udp_remove (struct udp_pcb *pcb);
err_t udp_bind (struct udp_pcb *pcb, const ip_addr_t *ipaddr,
u16_t port);
void udp_bind_netif (struct udp_pcb *pcb, const struct netif* netif);
err_t udp_connect (struct udp_pcb *pcb, const ip_addr_t *ipaddr,
u16_t port);
void udp_disconnect (struct udp_pcb *pcb);
void udp_recv (struct udp_pcb *pcb, udp_recv_fn recv,
void *recv_arg);
err_t udp_sendto_if (struct udp_pcb *pcb, struct pbuf *p,
const ip_addr_t *dst_ip, u16_t dst_port,
struct netif *netif);
err_t udp_sendto_if_src(struct udp_pcb *pcb, struct pbuf *p,
const ip_addr_t *dst_ip, u16_t dst_port,
struct netif *netif, const ip_addr_t *src_ip);
err_t udp_sendto (struct udp_pcb *pcb, struct pbuf *p,
const ip_addr_t *dst_ip, u16_t dst_port);
err_t udp_send (struct udp_pcb *pcb, struct pbuf *p);
#if LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP
err_t udp_sendto_if_chksum(struct udp_pcb *pcb, struct pbuf *p,
const ip_addr_t *dst_ip, u16_t dst_port,
struct netif *netif, u8_t have_chksum,
u16_t chksum);
err_t udp_sendto_chksum(struct udp_pcb *pcb, struct pbuf *p,
const ip_addr_t *dst_ip, u16_t dst_port,
u8_t have_chksum, u16_t chksum);
err_t udp_send_chksum(struct udp_pcb *pcb, struct pbuf *p,
u8_t have_chksum, u16_t chksum);
err_t udp_sendto_if_src_chksum(struct udp_pcb *pcb, struct pbuf *p,
const ip_addr_t *dst_ip, u16_t dst_port, struct netif *netif,
u8_t have_chksum, u16_t chksum, const ip_addr_t *src_ip);/* ... */
#endif
#define udp_flags(pcb) ((pcb)->flags)
#define udp_setflags(pcb, f) ((pcb)->flags = (f))
#define udp_set_flags(pcb, set_flags) do { (pcb)->flags = (u8_t)((pcb)->flags | (set_flags)); } while(0)
#define udp_clear_flags(pcb, clr_flags) do { (pcb)->flags = (u8_t)((pcb)->flags & (u8_t)(~(clr_flags) & 0xff)); } while(0)
#define udp_is_flag_set(pcb, flag) (((pcb)->flags & (flag)) != 0)
5 defines
void udp_input (struct pbuf *p, struct netif *inp);
void udp_init (void);
#define udp_new_ip6() udp_new_ip_type(IPADDR_TYPE_V6)
#if LWIP_MULTICAST_TX_OPTIONS
#if LWIP_IPV4
#define udp_set_multicast_netif_addr(pcb, ip4addr) ip4_addr_copy((pcb)->mcast_ip4, *(ip4addr))
#define udp_get_multicast_netif_addr(pcb) (&(pcb)->mcast_ip4)
/* ... */#endif
#define udp_set_multicast_netif_index(pcb, idx) ((pcb)->mcast_ifindex = (idx))
#define udp_get_multicast_netif_index(pcb) ((pcb)->mcast_ifindex)
#define udp_set_multicast_ttl(pcb, value) ((pcb)->mcast_ttl = (value))
#define udp_get_multicast_ttl(pcb) ((pcb)->mcast_ttl)
/* ... */#endif
#if UDP_DEBUG
void udp_debug_print(struct udp_hdr *udphdr);
#else
#define udp_debug_print(udphdr)
#endif
void udp_netif_ip_addr_changed(const ip_addr_t* old_addr, const ip_addr_t* new_addr);
#ifdef __cplusplus
}extern "C" { ... }
#endif
/* ... */
#endif
/* ... */
#endif