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