UbixOS V2 2.0

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