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 #ifndef __LWIP_STATS_H__
hlipka 0:8b387bed54c2 33 #define __LWIP_STATS_H__
hlipka 0:8b387bed54c2 34
hlipka 0:8b387bed54c2 35 #include "lwip/opt.h"
hlipka 0:8b387bed54c2 36
hlipka 0:8b387bed54c2 37 #include "lwip/mem.h"
hlipka 0:8b387bed54c2 38 #include "lwip/memp.h"
hlipka 0:8b387bed54c2 39
hlipka 0:8b387bed54c2 40 #ifdef __cplusplus
hlipka 0:8b387bed54c2 41 extern "C" {
hlipka 0:8b387bed54c2 42 #endif
hlipka 0:8b387bed54c2 43
hlipka 0:8b387bed54c2 44 #if LWIP_STATS
hlipka 0:8b387bed54c2 45
hlipka 0:8b387bed54c2 46 #ifndef LWIP_STATS_LARGE
hlipka 0:8b387bed54c2 47 #define LWIP_STATS_LARGE 0
hlipka 0:8b387bed54c2 48 #endif
hlipka 0:8b387bed54c2 49
hlipka 0:8b387bed54c2 50 #if LWIP_STATS_LARGE
hlipka 0:8b387bed54c2 51 #define STAT_COUNTER u32_t
hlipka 0:8b387bed54c2 52 #define STAT_COUNTER_F U32_F
hlipka 0:8b387bed54c2 53 #else
hlipka 0:8b387bed54c2 54 #define STAT_COUNTER u16_t
hlipka 0:8b387bed54c2 55 #define STAT_COUNTER_F U16_F
hlipka 0:8b387bed54c2 56 #endif
hlipka 0:8b387bed54c2 57
hlipka 0:8b387bed54c2 58 struct stats_proto {
hlipka 0:8b387bed54c2 59 STAT_COUNTER xmit; /* Transmitted packets. */
hlipka 0:8b387bed54c2 60 STAT_COUNTER recv; /* Received packets. */
hlipka 0:8b387bed54c2 61 STAT_COUNTER fw; /* Forwarded packets. */
hlipka 0:8b387bed54c2 62 STAT_COUNTER drop; /* Dropped packets. */
hlipka 0:8b387bed54c2 63 STAT_COUNTER chkerr; /* Checksum error. */
hlipka 0:8b387bed54c2 64 STAT_COUNTER lenerr; /* Invalid length error. */
hlipka 0:8b387bed54c2 65 STAT_COUNTER memerr; /* Out of memory error. */
hlipka 0:8b387bed54c2 66 STAT_COUNTER rterr; /* Routing error. */
hlipka 0:8b387bed54c2 67 STAT_COUNTER proterr; /* Protocol error. */
hlipka 0:8b387bed54c2 68 STAT_COUNTER opterr; /* Error in options. */
hlipka 0:8b387bed54c2 69 STAT_COUNTER err; /* Misc error. */
hlipka 0:8b387bed54c2 70 STAT_COUNTER cachehit;
hlipka 0:8b387bed54c2 71 };
hlipka 0:8b387bed54c2 72
hlipka 0:8b387bed54c2 73 struct stats_igmp {
hlipka 0:8b387bed54c2 74 STAT_COUNTER xmit; /* Transmitted packets. */
hlipka 0:8b387bed54c2 75 STAT_COUNTER recv; /* Received packets. */
hlipka 0:8b387bed54c2 76 STAT_COUNTER drop; /* Dropped packets. */
hlipka 0:8b387bed54c2 77 STAT_COUNTER chkerr; /* Checksum error. */
hlipka 0:8b387bed54c2 78 STAT_COUNTER lenerr; /* Invalid length error. */
hlipka 0:8b387bed54c2 79 STAT_COUNTER memerr; /* Out of memory error. */
hlipka 0:8b387bed54c2 80 STAT_COUNTER proterr; /* Protocol error. */
hlipka 0:8b387bed54c2 81 STAT_COUNTER rx_v1; /* Received v1 frames. */
hlipka 0:8b387bed54c2 82 STAT_COUNTER rx_group; /* Received group-specific queries. */
hlipka 0:8b387bed54c2 83 STAT_COUNTER rx_general; /* Received general queries. */
hlipka 0:8b387bed54c2 84 STAT_COUNTER rx_report; /* Received reports. */
hlipka 0:8b387bed54c2 85 STAT_COUNTER tx_join; /* Sent joins. */
hlipka 0:8b387bed54c2 86 STAT_COUNTER tx_leave; /* Sent leaves. */
hlipka 0:8b387bed54c2 87 STAT_COUNTER tx_report; /* Sent reports. */
hlipka 0:8b387bed54c2 88 };
hlipka 0:8b387bed54c2 89
hlipka 0:8b387bed54c2 90 struct stats_mem {
hlipka 0:8b387bed54c2 91 #ifdef LWIP_DEBUG
hlipka 0:8b387bed54c2 92 const char *name;
hlipka 0:8b387bed54c2 93 #endif /* LWIP_DEBUG */
hlipka 0:8b387bed54c2 94 mem_size_t avail;
hlipka 0:8b387bed54c2 95 mem_size_t used;
hlipka 0:8b387bed54c2 96 mem_size_t max;
hlipka 0:8b387bed54c2 97 STAT_COUNTER err;
hlipka 0:8b387bed54c2 98 STAT_COUNTER illegal;
hlipka 0:8b387bed54c2 99 };
hlipka 0:8b387bed54c2 100
hlipka 0:8b387bed54c2 101 struct stats_syselem {
hlipka 0:8b387bed54c2 102 STAT_COUNTER used;
hlipka 0:8b387bed54c2 103 STAT_COUNTER max;
hlipka 0:8b387bed54c2 104 STAT_COUNTER err;
hlipka 0:8b387bed54c2 105 };
hlipka 0:8b387bed54c2 106
hlipka 0:8b387bed54c2 107 struct stats_sys {
hlipka 0:8b387bed54c2 108 struct stats_syselem sem;
hlipka 0:8b387bed54c2 109 struct stats_syselem mutex;
hlipka 0:8b387bed54c2 110 struct stats_syselem mbox;
hlipka 0:8b387bed54c2 111 };
hlipka 0:8b387bed54c2 112
hlipka 0:8b387bed54c2 113 struct stats_ {
hlipka 0:8b387bed54c2 114 #if LINK_STATS
hlipka 0:8b387bed54c2 115 struct stats_proto link;
hlipka 0:8b387bed54c2 116 #endif
hlipka 0:8b387bed54c2 117 #if ETHARP_STATS
hlipka 0:8b387bed54c2 118 struct stats_proto etharp;
hlipka 0:8b387bed54c2 119 #endif
hlipka 0:8b387bed54c2 120 #if IPFRAG_STATS
hlipka 0:8b387bed54c2 121 struct stats_proto ip_frag;
hlipka 0:8b387bed54c2 122 #endif
hlipka 0:8b387bed54c2 123 #if IP_STATS
hlipka 0:8b387bed54c2 124 struct stats_proto ip;
hlipka 0:8b387bed54c2 125 #endif
hlipka 0:8b387bed54c2 126 #if ICMP_STATS
hlipka 0:8b387bed54c2 127 struct stats_proto icmp;
hlipka 0:8b387bed54c2 128 #endif
hlipka 0:8b387bed54c2 129 #if IGMP_STATS
hlipka 0:8b387bed54c2 130 struct stats_igmp igmp;
hlipka 0:8b387bed54c2 131 #endif
hlipka 0:8b387bed54c2 132 #if UDP_STATS
hlipka 0:8b387bed54c2 133 struct stats_proto udp;
hlipka 0:8b387bed54c2 134 #endif
hlipka 0:8b387bed54c2 135 #if TCP_STATS
hlipka 0:8b387bed54c2 136 struct stats_proto tcp;
hlipka 0:8b387bed54c2 137 #endif
hlipka 0:8b387bed54c2 138 #if MEM_STATS
hlipka 0:8b387bed54c2 139 struct stats_mem mem;
hlipka 0:8b387bed54c2 140 #endif
hlipka 0:8b387bed54c2 141 #if MEMP_STATS
hlipka 0:8b387bed54c2 142 struct stats_mem memp[MEMP_MAX];
hlipka 0:8b387bed54c2 143 #endif
hlipka 0:8b387bed54c2 144 #if SYS_STATS
hlipka 0:8b387bed54c2 145 struct stats_sys sys;
hlipka 0:8b387bed54c2 146 #endif
hlipka 0:8b387bed54c2 147 };
hlipka 0:8b387bed54c2 148
hlipka 0:8b387bed54c2 149 extern struct stats_ lwip_stats;
hlipka 0:8b387bed54c2 150
hlipka 0:8b387bed54c2 151 void stats_init(void);
hlipka 0:8b387bed54c2 152
hlipka 0:8b387bed54c2 153 #define STATS_INC(x) ++lwip_stats.x
hlipka 0:8b387bed54c2 154 #define STATS_DEC(x) --lwip_stats.x
hlipka 0:8b387bed54c2 155 #define STATS_INC_USED(x, y) do { lwip_stats.x.used += y; \
hlipka 0:8b387bed54c2 156 if (lwip_stats.x.max < lwip_stats.x.used) { \
hlipka 0:8b387bed54c2 157 lwip_stats.x.max = lwip_stats.x.used; \
hlipka 0:8b387bed54c2 158 } \
hlipka 0:8b387bed54c2 159 } while(0)
hlipka 0:8b387bed54c2 160 #else /* LWIP_STATS */
hlipka 0:8b387bed54c2 161 #define stats_init()
hlipka 0:8b387bed54c2 162 #define STATS_INC(x)
hlipka 0:8b387bed54c2 163 #define STATS_DEC(x)
hlipka 0:8b387bed54c2 164 #define STATS_INC_USED(x)
hlipka 0:8b387bed54c2 165 #endif /* LWIP_STATS */
hlipka 0:8b387bed54c2 166
hlipka 0:8b387bed54c2 167 #if TCP_STATS
hlipka 0:8b387bed54c2 168 #define TCP_STATS_INC(x) STATS_INC(x)
hlipka 0:8b387bed54c2 169 #define TCP_STATS_DISPLAY() stats_display_proto(&lwip_stats.tcp, "TCP")
hlipka 0:8b387bed54c2 170 #else
hlipka 0:8b387bed54c2 171 #define TCP_STATS_INC(x)
hlipka 0:8b387bed54c2 172 #define TCP_STATS_DISPLAY()
hlipka 0:8b387bed54c2 173 #endif
hlipka 0:8b387bed54c2 174
hlipka 0:8b387bed54c2 175 #if UDP_STATS
hlipka 0:8b387bed54c2 176 #define UDP_STATS_INC(x) STATS_INC(x)
hlipka 0:8b387bed54c2 177 #define UDP_STATS_DISPLAY() stats_display_proto(&lwip_stats.udp, "UDP")
hlipka 0:8b387bed54c2 178 #else
hlipka 0:8b387bed54c2 179 #define UDP_STATS_INC(x)
hlipka 0:8b387bed54c2 180 #define UDP_STATS_DISPLAY()
hlipka 0:8b387bed54c2 181 #endif
hlipka 0:8b387bed54c2 182
hlipka 0:8b387bed54c2 183 #if ICMP_STATS
hlipka 0:8b387bed54c2 184 #define ICMP_STATS_INC(x) STATS_INC(x)
hlipka 0:8b387bed54c2 185 #define ICMP_STATS_DISPLAY() stats_display_proto(&lwip_stats.icmp, "ICMP")
hlipka 0:8b387bed54c2 186 #else
hlipka 0:8b387bed54c2 187 #define ICMP_STATS_INC(x)
hlipka 0:8b387bed54c2 188 #define ICMP_STATS_DISPLAY()
hlipka 0:8b387bed54c2 189 #endif
hlipka 0:8b387bed54c2 190
hlipka 0:8b387bed54c2 191 #if IGMP_STATS
hlipka 0:8b387bed54c2 192 #define IGMP_STATS_INC(x) STATS_INC(x)
hlipka 0:8b387bed54c2 193 #define IGMP_STATS_DISPLAY() stats_display_igmp(&lwip_stats.igmp)
hlipka 0:8b387bed54c2 194 #else
hlipka 0:8b387bed54c2 195 #define IGMP_STATS_INC(x)
hlipka 0:8b387bed54c2 196 #define IGMP_STATS_DISPLAY()
hlipka 0:8b387bed54c2 197 #endif
hlipka 0:8b387bed54c2 198
hlipka 0:8b387bed54c2 199 #if IP_STATS
hlipka 0:8b387bed54c2 200 #define IP_STATS_INC(x) STATS_INC(x)
hlipka 0:8b387bed54c2 201 #define IP_STATS_DISPLAY() stats_display_proto(&lwip_stats.ip, "IP")
hlipka 0:8b387bed54c2 202 #else
hlipka 0:8b387bed54c2 203 #define IP_STATS_INC(x)
hlipka 0:8b387bed54c2 204 #define IP_STATS_DISPLAY()
hlipka 0:8b387bed54c2 205 #endif
hlipka 0:8b387bed54c2 206
hlipka 0:8b387bed54c2 207 #if IPFRAG_STATS
hlipka 0:8b387bed54c2 208 #define IPFRAG_STATS_INC(x) STATS_INC(x)
hlipka 0:8b387bed54c2 209 #define IPFRAG_STATS_DISPLAY() stats_display_proto(&lwip_stats.ip_frag, "IP_FRAG")
hlipka 0:8b387bed54c2 210 #else
hlipka 0:8b387bed54c2 211 #define IPFRAG_STATS_INC(x)
hlipka 0:8b387bed54c2 212 #define IPFRAG_STATS_DISPLAY()
hlipka 0:8b387bed54c2 213 #endif
hlipka 0:8b387bed54c2 214
hlipka 0:8b387bed54c2 215 #if ETHARP_STATS
hlipka 0:8b387bed54c2 216 #define ETHARP_STATS_INC(x) STATS_INC(x)
hlipka 0:8b387bed54c2 217 #define ETHARP_STATS_DISPLAY() stats_display_proto(&lwip_stats.etharp, "ETHARP")
hlipka 0:8b387bed54c2 218 #else
hlipka 0:8b387bed54c2 219 #define ETHARP_STATS_INC(x)
hlipka 0:8b387bed54c2 220 #define ETHARP_STATS_DISPLAY()
hlipka 0:8b387bed54c2 221 #endif
hlipka 0:8b387bed54c2 222
hlipka 0:8b387bed54c2 223 #if LINK_STATS
hlipka 0:8b387bed54c2 224 #define LINK_STATS_INC(x) STATS_INC(x)
hlipka 0:8b387bed54c2 225 #define LINK_STATS_DISPLAY() stats_display_proto(&lwip_stats.link, "LINK")
hlipka 0:8b387bed54c2 226 #else
hlipka 0:8b387bed54c2 227 #define LINK_STATS_INC(x)
hlipka 0:8b387bed54c2 228 #define LINK_STATS_DISPLAY()
hlipka 0:8b387bed54c2 229 #endif
hlipka 0:8b387bed54c2 230
hlipka 0:8b387bed54c2 231 #if MEM_STATS
hlipka 0:8b387bed54c2 232 #define MEM_STATS_AVAIL(x, y) lwip_stats.mem.x = y
hlipka 0:8b387bed54c2 233 #define MEM_STATS_INC(x) STATS_INC(mem.x)
hlipka 0:8b387bed54c2 234 #define MEM_STATS_INC_USED(x, y) STATS_INC_USED(mem, y)
hlipka 0:8b387bed54c2 235 #define MEM_STATS_DEC_USED(x, y) lwip_stats.mem.x -= y
hlipka 0:8b387bed54c2 236 #define MEM_STATS_DISPLAY() stats_display_mem(&lwip_stats.mem, "HEAP")
hlipka 0:8b387bed54c2 237 #else
hlipka 0:8b387bed54c2 238 #define MEM_STATS_AVAIL(x, y)
hlipka 0:8b387bed54c2 239 #define MEM_STATS_INC(x)
hlipka 0:8b387bed54c2 240 #define MEM_STATS_INC_USED(x, y)
hlipka 0:8b387bed54c2 241 #define MEM_STATS_DEC_USED(x, y)
hlipka 0:8b387bed54c2 242 #define MEM_STATS_DISPLAY()
hlipka 0:8b387bed54c2 243 #endif
hlipka 0:8b387bed54c2 244
hlipka 0:8b387bed54c2 245 #if MEMP_STATS
hlipka 0:8b387bed54c2 246 #define MEMP_STATS_AVAIL(x, i, y) lwip_stats.memp[i].x = y
hlipka 0:8b387bed54c2 247 #define MEMP_STATS_INC(x, i) STATS_INC(memp[i].x)
hlipka 0:8b387bed54c2 248 #define MEMP_STATS_DEC(x, i) STATS_DEC(memp[i].x)
hlipka 0:8b387bed54c2 249 #define MEMP_STATS_INC_USED(x, i) STATS_INC_USED(memp[i], 1)
hlipka 0:8b387bed54c2 250 #define MEMP_STATS_DISPLAY(i) stats_display_memp(&lwip_stats.memp[i], i)
hlipka 0:8b387bed54c2 251 #else
hlipka 0:8b387bed54c2 252 #define MEMP_STATS_AVAIL(x, i, y)
hlipka 0:8b387bed54c2 253 #define MEMP_STATS_INC(x, i)
hlipka 0:8b387bed54c2 254 #define MEMP_STATS_DEC(x, i)
hlipka 0:8b387bed54c2 255 #define MEMP_STATS_INC_USED(x, i)
hlipka 0:8b387bed54c2 256 #define MEMP_STATS_DISPLAY(i)
hlipka 0:8b387bed54c2 257 #endif
hlipka 0:8b387bed54c2 258
hlipka 0:8b387bed54c2 259 #if SYS_STATS
hlipka 0:8b387bed54c2 260 #define SYS_STATS_INC(x) STATS_INC(sys.x)
hlipka 0:8b387bed54c2 261 #define SYS_STATS_DEC(x) STATS_DEC(sys.x)
hlipka 0:8b387bed54c2 262 #define SYS_STATS_INC_USED(x) STATS_INC_USED(sys.x, 1)
hlipka 0:8b387bed54c2 263 #define SYS_STATS_DISPLAY() stats_display_sys(&lwip_stats.sys)
hlipka 0:8b387bed54c2 264 #else
hlipka 0:8b387bed54c2 265 #define SYS_STATS_INC(x)
hlipka 0:8b387bed54c2 266 #define SYS_STATS_DEC(x)
hlipka 0:8b387bed54c2 267 #define SYS_STATS_INC_USED(x)
hlipka 0:8b387bed54c2 268 #define SYS_STATS_DISPLAY()
hlipka 0:8b387bed54c2 269 #endif
hlipka 0:8b387bed54c2 270
hlipka 0:8b387bed54c2 271 /* Display of statistics */
hlipka 0:8b387bed54c2 272 #if LWIP_STATS_DISPLAY
hlipka 0:8b387bed54c2 273 void stats_display(void);
hlipka 0:8b387bed54c2 274 void stats_display_proto(struct stats_proto *proto, char *name);
hlipka 0:8b387bed54c2 275 void stats_display_igmp(struct stats_igmp *igmp);
hlipka 0:8b387bed54c2 276 void stats_display_mem(struct stats_mem *mem, char *name);
hlipka 0:8b387bed54c2 277 void stats_display_memp(struct stats_mem *mem, int index);
hlipka 0:8b387bed54c2 278 void stats_display_sys(struct stats_sys *sys);
hlipka 0:8b387bed54c2 279 #else /* LWIP_STATS_DISPLAY */
hlipka 0:8b387bed54c2 280 #define stats_display()
hlipka 0:8b387bed54c2 281 #define stats_display_proto(proto, name)
hlipka 0:8b387bed54c2 282 #define stats_display_igmp(igmp)
hlipka 0:8b387bed54c2 283 #define stats_display_mem(mem, name)
hlipka 0:8b387bed54c2 284 #define stats_display_memp(mem, index)
hlipka 0:8b387bed54c2 285 #define stats_display_sys(sys)
hlipka 0:8b387bed54c2 286 #endif /* LWIP_STATS_DISPLAY */
hlipka 0:8b387bed54c2 287
hlipka 0:8b387bed54c2 288 #ifdef __cplusplus
hlipka 0:8b387bed54c2 289 }
hlipka 0:8b387bed54c2 290 #endif
hlipka 0:8b387bed54c2 291
hlipka 0:8b387bed54c2 292 #endif /* __LWIP_STATS_H__ */