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