Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: cobaLCDJoyMotor_Thread odometry_omni_3roda_v3 odometry_omni_3roda_v1 odometry_omni_3roda_v2 ... more
netbuf.h
00001 /** 00002 * @file 00003 * netbuf API (for netconn API) 00004 */ 00005 00006 /* 00007 * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 00008 * All rights reserved. 00009 * 00010 * Redistribution and use in source and binary forms, with or without modification, 00011 * are permitted provided that the following conditions are met: 00012 * 00013 * 1. Redistributions of source code must retain the above copyright notice, 00014 * this list of conditions and the following disclaimer. 00015 * 2. Redistributions in binary form must reproduce the above copyright notice, 00016 * this list of conditions and the following disclaimer in the documentation 00017 * and/or other materials provided with the distribution. 00018 * 3. The name of the author may not be used to endorse or promote products 00019 * derived from this software without specific prior written permission. 00020 * 00021 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 00022 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 00023 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 00024 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00025 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 00026 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00027 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00028 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 00029 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 00030 * OF SUCH DAMAGE. 00031 * 00032 * This file is part of the lwIP TCP/IP stack. 00033 * 00034 * Author: Adam Dunkels <adam@sics.se> 00035 * 00036 */ 00037 #ifndef LWIP_HDR_NETBUF_H 00038 #define LWIP_HDR_NETBUF_H 00039 00040 #include "lwip/opt.h" 00041 00042 #if LWIP_NETCONN || LWIP_SOCKET /* don't build if not configured for use in lwipopts.h */ 00043 /* Note: Netconn API is always available when sockets are enabled - 00044 * sockets are implemented on top of them */ 00045 00046 #include "lwip/pbuf.h" 00047 #include "lwip/ip_addr.h" 00048 #include "lwip/ip6_addr.h" 00049 00050 #ifdef __cplusplus 00051 extern "C" { 00052 #endif 00053 00054 /** This netbuf has dest-addr/port set */ 00055 #define NETBUF_FLAG_DESTADDR 0x01 00056 /** This netbuf includes a checksum */ 00057 #define NETBUF_FLAG_CHKSUM 0x02 00058 00059 /** "Network buffer" - contains data and addressing info */ 00060 struct netbuf { 00061 struct pbuf *p, *ptr; 00062 ip_addr_t addr; 00063 u16_t port; 00064 #if LWIP_NETBUF_RECVINFO || LWIP_CHECKSUM_ON_COPY 00065 #if LWIP_CHECKSUM_ON_COPY 00066 u8_t flags; 00067 #endif /* LWIP_CHECKSUM_ON_COPY */ 00068 u16_t toport_chksum; 00069 #if LWIP_NETBUF_RECVINFO 00070 ip_addr_t toaddr; 00071 #endif /* LWIP_NETBUF_RECVINFO */ 00072 #endif /* LWIP_NETBUF_RECVINFO || LWIP_CHECKSUM_ON_COPY */ 00073 }; 00074 00075 /* Network buffer functions: */ 00076 struct netbuf * netbuf_new (void); 00077 void netbuf_delete (struct netbuf *buf); 00078 void * netbuf_alloc (struct netbuf *buf, u16_t size); 00079 void netbuf_free (struct netbuf *buf); 00080 err_t netbuf_ref (struct netbuf *buf, 00081 const void *dataptr, u16_t size); 00082 void netbuf_chain (struct netbuf *head, struct netbuf *tail); 00083 00084 err_t netbuf_data (struct netbuf *buf, 00085 void **dataptr, u16_t *len); 00086 s8_t netbuf_next (struct netbuf *buf); 00087 void netbuf_first (struct netbuf *buf); 00088 00089 00090 #define netbuf_copy_partial(buf, dataptr, len, offset) \ 00091 pbuf_copy_partial((buf)->p, (dataptr), (len), (offset)) 00092 #define netbuf_copy(buf,dataptr,len) netbuf_copy_partial(buf, dataptr, len, 0) 00093 #define netbuf_take(buf, dataptr, len) pbuf_take((buf)->p, dataptr, len) 00094 #define netbuf_len(buf) ((buf)->p->tot_len) 00095 #define netbuf_fromaddr(buf) (&((buf)->addr)) 00096 #define netbuf_set_fromaddr(buf, fromaddr) ip_addr_set(&((buf)->addr), fromaddr) 00097 #define netbuf_fromport(buf) ((buf)->port) 00098 #if LWIP_NETBUF_RECVINFO 00099 #define netbuf_destaddr(buf) (&((buf)->toaddr)) 00100 #define netbuf_set_destaddr(buf, destaddr) ip_addr_set(&((buf)->toaddr), destaddr) 00101 #if LWIP_CHECKSUM_ON_COPY 00102 #define netbuf_destport(buf) (((buf)->flags & NETBUF_FLAG_DESTADDR) ? (buf)->toport_chksum : 0) 00103 #else /* LWIP_CHECKSUM_ON_COPY */ 00104 #define netbuf_destport(buf) ((buf)->toport_chksum) 00105 #endif /* LWIP_CHECKSUM_ON_COPY */ 00106 #endif /* LWIP_NETBUF_RECVINFO */ 00107 #if LWIP_CHECKSUM_ON_COPY 00108 #define netbuf_set_chksum(buf, chksum) do { (buf)->flags = NETBUF_FLAG_CHKSUM; \ 00109 (buf)->toport_chksum = chksum; } while(0) 00110 #endif /* LWIP_CHECKSUM_ON_COPY */ 00111 00112 #ifdef __cplusplus 00113 } 00114 #endif 00115 00116 #endif /* LWIP_NETCONN || LWIP_SOCKET */ 00117 00118 #endif /* LWIP_HDR_NETBUF_H */
Generated on Tue Jul 12 2022 13:03:07 by
