sdk-core v2026.11.05
PS2 SDK - core tier (build-critical EE/IOP modules)
Loading...
Searching...
No Matches
netbuf.h
Go to the documentation of this file.
1
6
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_NETBUF_H
39#define LWIP_HDR_NETBUF_H
40
41#include "lwip/opt.h"
42
43#if LWIP_NETCONN || LWIP_SOCKET /* don't build if not configured for use in lwipopts.h */
44/* Note: Netconn API is always available when sockets are enabled -
45 * sockets are implemented on top of them */
46
47#include "lwip/pbuf.h"
48#include "lwip/ip_addr.h"
49#include "lwip/ip6_addr.h"
50
51#ifdef __cplusplus
52extern "C" {
53#endif
54
56#define NETBUF_FLAG_DESTADDR 0x01
58#define NETBUF_FLAG_CHKSUM 0x02
59
61struct netbuf {
62 struct pbuf *p, *ptr;
63 ip_addr_t addr;
64 u16_t port;
65#if LWIP_NETBUF_RECVINFO || LWIP_CHECKSUM_ON_COPY
66 u8_t flags;
67 u16_t toport_chksum;
68#if LWIP_NETBUF_RECVINFO
69 ip_addr_t toaddr;
70#endif /* LWIP_NETBUF_RECVINFO */
71#endif /* LWIP_NETBUF_RECVINFO || LWIP_CHECKSUM_ON_COPY */
72};
73
74/* Network buffer functions: */
75struct netbuf * netbuf_new (void);
76void netbuf_delete (struct netbuf *buf);
77void * netbuf_alloc (struct netbuf *buf, u16_t size);
78void netbuf_free (struct netbuf *buf);
79err_t netbuf_ref (struct netbuf *buf,
80 const void *dataptr, u16_t size);
81void netbuf_chain (struct netbuf *head, struct netbuf *tail);
82
83err_t netbuf_data (struct netbuf *buf,
84 void **dataptr, u16_t *len);
85s8_t netbuf_next (struct netbuf *buf);
86void netbuf_first (struct netbuf *buf);
87
88
89#define netbuf_copy_partial(buf, dataptr, len, offset) \
90 pbuf_copy_partial((buf)->p, (dataptr), (len), (offset))
91#define netbuf_copy(buf,dataptr,len) netbuf_copy_partial(buf, dataptr, len, 0)
92#define netbuf_take(buf, dataptr, len) pbuf_take((buf)->p, dataptr, len)
93#define netbuf_len(buf) ((buf)->p->tot_len)
94#define netbuf_fromaddr(buf) (&((buf)->addr))
95#define netbuf_set_fromaddr(buf, fromaddr) ip_addr_set(&((buf)->addr), fromaddr)
96#define netbuf_fromport(buf) ((buf)->port)
97#if LWIP_NETBUF_RECVINFO
98#define netbuf_destaddr(buf) (&((buf)->toaddr))
99#define netbuf_set_destaddr(buf, destaddr) ip_addr_set(&((buf)->toaddr), destaddr)
100#if LWIP_CHECKSUM_ON_COPY
101#define netbuf_destport(buf) (((buf)->flags & NETBUF_FLAG_DESTADDR) ? (buf)->toport_chksum : 0)
102#else /* LWIP_CHECKSUM_ON_COPY */
103#define netbuf_destport(buf) ((buf)->toport_chksum)
104#endif /* LWIP_CHECKSUM_ON_COPY */
105#endif /* LWIP_NETBUF_RECVINFO */
106#if LWIP_CHECKSUM_ON_COPY
107#define netbuf_set_chksum(buf, chksum) do { (buf)->flags = NETBUF_FLAG_CHKSUM; \
108 (buf)->toport_chksum = chksum; } while(0)
109#endif /* LWIP_CHECKSUM_ON_COPY */
110
111#ifdef __cplusplus
112}
113#endif
114
115#endif /* LWIP_NETCONN || LWIP_SOCKET */
116
117#endif /* LWIP_HDR_NETBUF_H */