The Pedigree Project 0.1
netbuf.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
25/*
26 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
27 * All rights reserved.
28 *
29 * Redistribution and use in source and binary forms, with or without modification,
30 * are permitted provided that the following conditions are met:
31 *
32 * 1. Redistributions of source code must retain the above copyright notice,
33 * this list of conditions and the following disclaimer.
34 * 2. Redistributions in binary form must reproduce the above copyright notice,
35 * this list of conditions and the following disclaimer in the documentation
36 * and/or other materials provided with the distribution.
37 * 3. The name of the author may not be used to endorse or promote products
38 * derived from this software without specific prior written permission.
39 *
40 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
41 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
42 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
43 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
44 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
45 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
46 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
47 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
48 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
49 * OF SUCH DAMAGE.
50 *
51 * This file is part of the lwIP TCP/IP stack.
52 *
53 * Author: Adam Dunkels <adam@sics.se>
54 *
55 */
56#ifndef LWIP_HDR_NETBUF_H
57#define LWIP_HDR_NETBUF_H
58
59#include "lwip/opt.h"
60
61#if LWIP_NETCONN || LWIP_SOCKET /* don't build if not configured for use in lwipopts.h */
62/* Note: Netconn API is always available when sockets are enabled -
63 * sockets are implemented on top of them */
64
65#include "lwip/pbuf.h"
66#include "lwip/ip_addr.h"
67#include "lwip/ip6_addr.h"
68
69#ifdef __cplusplus
70extern "C" {
71#endif
72
74#define NETBUF_FLAG_DESTADDR 0x01
76#define NETBUF_FLAG_CHKSUM 0x02
77
79struct netbuf {
80 struct pbuf *p, *ptr;
81 ip_addr_t addr;
82 u16_t port;
83#if LWIP_NETBUF_RECVINFO || LWIP_CHECKSUM_ON_COPY
84#if LWIP_CHECKSUM_ON_COPY
85 u8_t flags;
86#endif /* LWIP_CHECKSUM_ON_COPY */
87 u16_t toport_chksum;
88#if LWIP_NETBUF_RECVINFO
89 ip_addr_t toaddr;
90#endif /* LWIP_NETBUF_RECVINFO */
91#endif /* LWIP_NETBUF_RECVINFO || LWIP_CHECKSUM_ON_COPY */
92};
93
94/* Network buffer functions: */
95struct netbuf * netbuf_new (void);
96void netbuf_delete (struct netbuf *buf);
97void * netbuf_alloc (struct netbuf *buf, u16_t size);
98void netbuf_free (struct netbuf *buf);
99err_t netbuf_ref (struct netbuf *buf,
100 const void *dataptr, u16_t size);
101void netbuf_chain (struct netbuf *head, struct netbuf *tail);
102
103err_t netbuf_data (struct netbuf *buf,
104 void **dataptr, u16_t *len);
105s8_t netbuf_next (struct netbuf *buf);
106void netbuf_first (struct netbuf *buf);
107
108
109#define netbuf_copy_partial(buf, dataptr, len, offset) \
110 pbuf_copy_partial((buf)->p, (dataptr), (len), (offset))
111#define netbuf_copy(buf,dataptr,len) netbuf_copy_partial(buf, dataptr, len, 0)
112#define netbuf_take(buf, dataptr, len) pbuf_take((buf)->p, dataptr, len)
113#define netbuf_len(buf) ((buf)->p->tot_len)
114#define netbuf_fromaddr(buf) (&((buf)->addr))
115#define netbuf_set_fromaddr(buf, fromaddr) ip_addr_set(&((buf)->addr), fromaddr)
116#define netbuf_fromport(buf) ((buf)->port)
117#if LWIP_NETBUF_RECVINFO
118#define netbuf_destaddr(buf) (&((buf)->toaddr))
119#define netbuf_set_destaddr(buf, destaddr) ip_addr_set(&((buf)->toaddr), destaddr)
120#if LWIP_CHECKSUM_ON_COPY
121#define netbuf_destport(buf) (((buf)->flags & NETBUF_FLAG_DESTADDR) ? (buf)->toport_chksum : 0)
122#else /* LWIP_CHECKSUM_ON_COPY */
123#define netbuf_destport(buf) ((buf)->toport_chksum)
124#endif /* LWIP_CHECKSUM_ON_COPY */
125#endif /* LWIP_NETBUF_RECVINFO */
126#if LWIP_CHECKSUM_ON_COPY
127#define netbuf_set_chksum(buf, chksum) do { (buf)->flags = NETBUF_FLAG_CHKSUM; \
128 (buf)->toport_chksum = chksum; } while(0)
129#endif /* LWIP_CHECKSUM_ON_COPY */
130
131#ifdef __cplusplus
132}
133#endif
134
135#endif /* LWIP_NETCONN || LWIP_SOCKET */
136
137#endif /* LWIP_HDR_NETBUF_H */
s8_t err_t
Definition err.h:76
Definition pbuf.h:161