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
72extern "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
80struct udp_pcb;
81
96typedef void (*udp_recv_fn)(void *arg, struct udp_pcb *pcb, struct pbuf *p,
97 const ip_addr_t *addr, u16_t port);
98
100struct 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
114 ip_addr_t multicast_ip;
116 u8_t mcast_ttl;
117#endif /* LWIP_MULTICAST_TX_OPTIONS */
118
119#if LWIP_UDPLITE
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) */
130extern struct udp_pcb *udp_pcbs;
131
132/* The following functions is the application layer interface to the
133 UDP code. */
134struct udp_pcb * udp_new (void);
135struct udp_pcb * udp_new_ip_type(u8_t type);
136void udp_remove (struct udp_pcb *pcb);
137err_t udp_bind (struct udp_pcb *pcb, const ip_addr_t *ipaddr,
138 u16_t port);
139err_t udp_connect (struct udp_pcb *pcb, const ip_addr_t *ipaddr,
140 u16_t port);
141void udp_disconnect (struct udp_pcb *pcb);
142void udp_recv (struct udp_pcb *pcb, udp_recv_fn recv,
143 void *recv_arg);
144err_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);
147err_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);
150err_t udp_sendto (struct udp_pcb *pcb, struct pbuf *p,
151 const ip_addr_t *dst_ip, u16_t dst_port);
152err_t udp_send (struct udp_pcb *pcb, struct pbuf *p);
153
154#if LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP
155err_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);
159err_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);
162err_t udp_send_chksum(struct udp_pcb *pcb, struct pbuf *p,
163 u8_t have_chksum, u16_t chksum);
164err_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. */
173void udp_input (struct pbuf *p, struct netif *inp);
174
175void 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
188void udp_debug_print(struct udp_hdr *udphdr);
189#else
190#define udp_debug_print(udphdr)
191#endif
192
193void 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 */
s8_t err_t
Definition err.h:76
#define IP_PCB
Definition ip.h:95
Definition netif.h:244
Definition pbuf.h:161