Stripped down version of Segundos NetService library (http://mbed.org/users/segundo/libraries/NetServices ). I have removed all NetServices, and all functions which had been disabled. Use this version when you need only pure TCP or UDP functions - this library compiles faster.

Dependencies:   lwip lwip-sys

Dependents:   christmasLights device_server pop3demo device_server_udp ... more

Committer:
hlipka
Date:
Mon Jan 10 21:03:11 2011 +0000
Revision:
0:8b387bed54c2
initial version

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hlipka 0:8b387bed54c2 1 /*
hlipka 0:8b387bed54c2 2 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
hlipka 0:8b387bed54c2 3 * All rights reserved.
hlipka 0:8b387bed54c2 4 *
hlipka 0:8b387bed54c2 5 * Redistribution and use in source and binary forms, with or without modification,
hlipka 0:8b387bed54c2 6 * are permitted provided that the following conditions are met:
hlipka 0:8b387bed54c2 7 *
hlipka 0:8b387bed54c2 8 * 1. Redistributions of source code must retain the above copyright notice,
hlipka 0:8b387bed54c2 9 * this list of conditions and the following disclaimer.
hlipka 0:8b387bed54c2 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
hlipka 0:8b387bed54c2 11 * this list of conditions and the following disclaimer in the documentation
hlipka 0:8b387bed54c2 12 * and/or other materials provided with the distribution.
hlipka 0:8b387bed54c2 13 * 3. The name of the author may not be used to endorse or promote products
hlipka 0:8b387bed54c2 14 * derived from this software without specific prior written permission.
hlipka 0:8b387bed54c2 15 *
hlipka 0:8b387bed54c2 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
hlipka 0:8b387bed54c2 17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
hlipka 0:8b387bed54c2 18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
hlipka 0:8b387bed54c2 19 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
hlipka 0:8b387bed54c2 20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
hlipka 0:8b387bed54c2 21 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
hlipka 0:8b387bed54c2 22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
hlipka 0:8b387bed54c2 23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
hlipka 0:8b387bed54c2 24 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
hlipka 0:8b387bed54c2 25 * OF SUCH DAMAGE.
hlipka 0:8b387bed54c2 26 *
hlipka 0:8b387bed54c2 27 * This file is part of the lwIP TCP/IP stack.
hlipka 0:8b387bed54c2 28 *
hlipka 0:8b387bed54c2 29 * Author: Adam Dunkels <adam@sics.se>
hlipka 0:8b387bed54c2 30 *
hlipka 0:8b387bed54c2 31 */
hlipka 0:8b387bed54c2 32
hlipka 0:8b387bed54c2 33 #ifndef __LWIP_PBUF_H__
hlipka 0:8b387bed54c2 34 #define __LWIP_PBUF_H__
hlipka 0:8b387bed54c2 35
hlipka 0:8b387bed54c2 36 #include "lwip/opt.h"
hlipka 0:8b387bed54c2 37 #include "lwip/err.h"
hlipka 0:8b387bed54c2 38
hlipka 0:8b387bed54c2 39 #ifdef __cplusplus
hlipka 0:8b387bed54c2 40 extern "C" {
hlipka 0:8b387bed54c2 41 #endif
hlipka 0:8b387bed54c2 42
hlipka 0:8b387bed54c2 43 /* Currently, the pbuf_custom code is only needed for one specific configuration
hlipka 0:8b387bed54c2 44 * of IP_FRAG */
hlipka 0:8b387bed54c2 45 #define LWIP_SUPPORT_CUSTOM_PBUF (IP_FRAG && !IP_FRAG_USES_STATIC_BUF && !LWIP_NETIF_TX_SINGLE_PBUF)
hlipka 0:8b387bed54c2 46
hlipka 0:8b387bed54c2 47 #define PBUF_TRANSPORT_HLEN 20
hlipka 0:8b387bed54c2 48 #define PBUF_IP_HLEN 20
hlipka 0:8b387bed54c2 49
hlipka 0:8b387bed54c2 50 typedef enum {
hlipka 0:8b387bed54c2 51 PBUF_TRANSPORT,
hlipka 0:8b387bed54c2 52 PBUF_IP,
hlipka 0:8b387bed54c2 53 PBUF_LINK,
hlipka 0:8b387bed54c2 54 PBUF_RAW
hlipka 0:8b387bed54c2 55 } pbuf_layer;
hlipka 0:8b387bed54c2 56
hlipka 0:8b387bed54c2 57 typedef enum {
hlipka 0:8b387bed54c2 58 PBUF_RAM, /* pbuf data is stored in RAM */
hlipka 0:8b387bed54c2 59 PBUF_ROM, /* pbuf data is stored in ROM */
hlipka 0:8b387bed54c2 60 PBUF_REF, /* pbuf comes from the pbuf pool */
hlipka 0:8b387bed54c2 61 PBUF_POOL /* pbuf payload refers to RAM */
hlipka 0:8b387bed54c2 62 } pbuf_type;
hlipka 0:8b387bed54c2 63
hlipka 0:8b387bed54c2 64
hlipka 0:8b387bed54c2 65 /* indicates this packet's data should be immediately passed to the application */
hlipka 0:8b387bed54c2 66 #define PBUF_FLAG_PUSH 0x01U
hlipka 0:8b387bed54c2 67 /* indicates this is a custom pbuf: pbuf_free and pbuf_header handle such a
hlipka 0:8b387bed54c2 68 a pbuf differently */
hlipka 0:8b387bed54c2 69 #define PBUF_FLAG_IS_CUSTOM 0x02U
hlipka 0:8b387bed54c2 70 /* indicates this pbuf is UDP multicast to be looped back */
hlipka 0:8b387bed54c2 71 #define PBUF_FLAG_MCASTLOOP 0x04U
hlipka 0:8b387bed54c2 72
hlipka 0:8b387bed54c2 73 struct pbuf {
hlipka 0:8b387bed54c2 74 /* next pbuf in singly linked pbuf chain */
hlipka 0:8b387bed54c2 75 struct pbuf *next;
hlipka 0:8b387bed54c2 76
hlipka 0:8b387bed54c2 77 /* pointer to the actual data in the buffer */
hlipka 0:8b387bed54c2 78 void *payload;
hlipka 0:8b387bed54c2 79
hlipka 0:8b387bed54c2 80 /**
hlipka 0:8b387bed54c2 81 * total length of this buffer and all next buffers in chain
hlipka 0:8b387bed54c2 82 * belonging to the same packet.
hlipka 0:8b387bed54c2 83 *
hlipka 0:8b387bed54c2 84 * For non-queue packet chains this is the invariant:
hlipka 0:8b387bed54c2 85 * p->tot_len == p->len + (p->next? p->next->tot_len: 0)
hlipka 0:8b387bed54c2 86 */
hlipka 0:8b387bed54c2 87 u16_t tot_len;
hlipka 0:8b387bed54c2 88
hlipka 0:8b387bed54c2 89 /* length of this buffer */
hlipka 0:8b387bed54c2 90 u16_t len;
hlipka 0:8b387bed54c2 91
hlipka 0:8b387bed54c2 92 /* pbuf_type as u8_t instead of enum to save space */
hlipka 0:8b387bed54c2 93 u8_t /*pbuf_type*/ type;
hlipka 0:8b387bed54c2 94
hlipka 0:8b387bed54c2 95 /* misc flags */
hlipka 0:8b387bed54c2 96 u8_t flags;
hlipka 0:8b387bed54c2 97
hlipka 0:8b387bed54c2 98 /**
hlipka 0:8b387bed54c2 99 * the reference count always equals the number of pointers
hlipka 0:8b387bed54c2 100 * that refer to this pbuf. This can be pointers from an application,
hlipka 0:8b387bed54c2 101 * the stack itself, or pbuf->next pointers from a chain.
hlipka 0:8b387bed54c2 102 */
hlipka 0:8b387bed54c2 103 u16_t ref;
hlipka 0:8b387bed54c2 104 };
hlipka 0:8b387bed54c2 105
hlipka 0:8b387bed54c2 106 #if LWIP_SUPPORT_CUSTOM_PBUF
hlipka 0:8b387bed54c2 107 /* Prototype for a function to free a custom pbuf */
hlipka 0:8b387bed54c2 108 typedef void (*pbuf_free_custom_fn)(struct pbuf *p);
hlipka 0:8b387bed54c2 109
hlipka 0:8b387bed54c2 110 /* A custom pbuf: like a pbuf, but following a function pointer to free it. */
hlipka 0:8b387bed54c2 111 struct pbuf_custom {
hlipka 0:8b387bed54c2 112 /* The actual pbuf */
hlipka 0:8b387bed54c2 113 struct pbuf pbuf;
hlipka 0:8b387bed54c2 114 /* This function is called when pbuf_free deallocates this pbuf(_custom) */
hlipka 0:8b387bed54c2 115 pbuf_free_custom_fn custom_free_function;
hlipka 0:8b387bed54c2 116 };
hlipka 0:8b387bed54c2 117 #endif /* LWIP_SUPPORT_CUSTOM_PBUF */
hlipka 0:8b387bed54c2 118
hlipka 0:8b387bed54c2 119 /* Initializes the pbuf module. This call is empty for now, but may not be in future. */
hlipka 0:8b387bed54c2 120 #define pbuf_init()
hlipka 0:8b387bed54c2 121
hlipka 0:8b387bed54c2 122 struct pbuf *pbuf_alloc(pbuf_layer l, u16_t length, pbuf_type type);
hlipka 0:8b387bed54c2 123 #if LWIP_SUPPORT_CUSTOM_PBUF
hlipka 0:8b387bed54c2 124 struct pbuf *pbuf_alloced_custom(pbuf_layer l, u16_t length, pbuf_type type,
hlipka 0:8b387bed54c2 125 struct pbuf_custom *p, void *payload_mem,
hlipka 0:8b387bed54c2 126 u16_t payload_mem_len);
hlipka 0:8b387bed54c2 127 #endif /* LWIP_SUPPORT_CUSTOM_PBUF */
hlipka 0:8b387bed54c2 128 void pbuf_realloc(struct pbuf *p, u16_t size);
hlipka 0:8b387bed54c2 129 u8_t pbuf_header(struct pbuf *p, s16_t header_size);
hlipka 0:8b387bed54c2 130 void pbuf_ref(struct pbuf *p);
hlipka 0:8b387bed54c2 131 u8_t pbuf_free(struct pbuf *p);
hlipka 0:8b387bed54c2 132 u8_t pbuf_clen(struct pbuf *p);
hlipka 0:8b387bed54c2 133 void pbuf_cat(struct pbuf *head, struct pbuf *tail);
hlipka 0:8b387bed54c2 134 void pbuf_chain(struct pbuf *head, struct pbuf *tail);
hlipka 0:8b387bed54c2 135 struct pbuf *pbuf_dechain(struct pbuf *p);
hlipka 0:8b387bed54c2 136 err_t pbuf_copy(struct pbuf *p_to, struct pbuf *p_from);
hlipka 0:8b387bed54c2 137 u16_t pbuf_copy_partial(struct pbuf *p, void *dataptr, u16_t len, u16_t offset);
hlipka 0:8b387bed54c2 138 err_t pbuf_take(struct pbuf *buf, const void *dataptr, u16_t len);
hlipka 0:8b387bed54c2 139 struct pbuf *pbuf_coalesce(struct pbuf *p, pbuf_layer layer);
hlipka 0:8b387bed54c2 140 #if LWIP_CHECKSUM_ON_COPY
hlipka 0:8b387bed54c2 141 err_t pbuf_fill_chksum(struct pbuf *p, u16_t start_offset, const void *dataptr,
hlipka 0:8b387bed54c2 142 u16_t len, u16_t *chksum);
hlipka 0:8b387bed54c2 143 #endif /* LWIP_CHECKSUM_ON_COPY */
hlipka 0:8b387bed54c2 144
hlipka 0:8b387bed54c2 145 u8_t pbuf_get_at(struct pbuf* p, u16_t offset);
hlipka 0:8b387bed54c2 146 u16_t pbuf_memcmp(struct pbuf* p, u16_t offset, const void* s2, u16_t n);
hlipka 0:8b387bed54c2 147 u16_t pbuf_memfind(struct pbuf* p, const void* mem, u16_t mem_len, u16_t start_offset);
hlipka 0:8b387bed54c2 148 u16_t pbuf_strstr(struct pbuf* p, const char* substr);
hlipka 0:8b387bed54c2 149
hlipka 0:8b387bed54c2 150 #ifdef __cplusplus
hlipka 0:8b387bed54c2 151 }
hlipka 0:8b387bed54c2 152 #endif
hlipka 0:8b387bed54c2 153
hlipka 0:8b387bed54c2 154 #endif /* __LWIP_PBUF_H__ */