Dependencies:   mbed

Dependents:   TCP

Committer:
slowness
Date:
Tue Sep 06 18:05:46 2011 +0000
Revision:
0:58c3d014a4e7

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
slowness 0:58c3d014a4e7 1 /*
slowness 0:58c3d014a4e7 2 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
slowness 0:58c3d014a4e7 3 * All rights reserved.
slowness 0:58c3d014a4e7 4 *
slowness 0:58c3d014a4e7 5 * Redistribution and use in source and binary forms, with or without modification,
slowness 0:58c3d014a4e7 6 * are permitted provided that the following conditions are met:
slowness 0:58c3d014a4e7 7 *
slowness 0:58c3d014a4e7 8 * 1. Redistributions of source code must retain the above copyright notice,
slowness 0:58c3d014a4e7 9 * this list of conditions and the following disclaimer.
slowness 0:58c3d014a4e7 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
slowness 0:58c3d014a4e7 11 * this list of conditions and the following disclaimer in the documentation
slowness 0:58c3d014a4e7 12 * and/or other materials provided with the distribution.
slowness 0:58c3d014a4e7 13 * 3. The name of the author may not be used to endorse or promote products
slowness 0:58c3d014a4e7 14 * derived from this software without specific prior written permission.
slowness 0:58c3d014a4e7 15 *
slowness 0:58c3d014a4e7 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
slowness 0:58c3d014a4e7 17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
slowness 0:58c3d014a4e7 18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
slowness 0:58c3d014a4e7 19 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
slowness 0:58c3d014a4e7 20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
slowness 0:58c3d014a4e7 21 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
slowness 0:58c3d014a4e7 22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
slowness 0:58c3d014a4e7 23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
slowness 0:58c3d014a4e7 24 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
slowness 0:58c3d014a4e7 25 * OF SUCH DAMAGE.
slowness 0:58c3d014a4e7 26 *
slowness 0:58c3d014a4e7 27 * This file is part of the lwIP TCP/IP stack.
slowness 0:58c3d014a4e7 28 *
slowness 0:58c3d014a4e7 29 * Author: Adam Dunkels <adam@sics.se>
slowness 0:58c3d014a4e7 30 *
slowness 0:58c3d014a4e7 31 */
slowness 0:58c3d014a4e7 32 #ifndef __LWIP_DEF_H__
slowness 0:58c3d014a4e7 33 #define __LWIP_DEF_H__
slowness 0:58c3d014a4e7 34
slowness 0:58c3d014a4e7 35 /* arch.h might define NULL already */
slowness 0:58c3d014a4e7 36 #include "lwip/arch.h"
slowness 0:58c3d014a4e7 37 #include "lwip/opt.h"
slowness 0:58c3d014a4e7 38
slowness 0:58c3d014a4e7 39 #ifdef __cplusplus
slowness 0:58c3d014a4e7 40 extern "C" {
slowness 0:58c3d014a4e7 41 #endif
slowness 0:58c3d014a4e7 42
slowness 0:58c3d014a4e7 43 #define LWIP_MAX(x , y) (((x) > (y)) ? (x) : (y))
slowness 0:58c3d014a4e7 44 #define LWIP_MIN(x , y) (((x) < (y)) ? (x) : (y))
slowness 0:58c3d014a4e7 45
slowness 0:58c3d014a4e7 46 #ifndef NULL
slowness 0:58c3d014a4e7 47 #define NULL ((void *)0)
slowness 0:58c3d014a4e7 48 #endif
slowness 0:58c3d014a4e7 49
slowness 0:58c3d014a4e7 50 /** Get the absolute difference between 2 u32_t values (correcting overflows)
slowness 0:58c3d014a4e7 51 * 'a' is expected to be 'higher' (without overflow) than 'b'. */
slowness 0:58c3d014a4e7 52 #define LWIP_U32_DIFF(a, b) (((a) >= (b)) ? ((a) - (b)) : (((a) + ((b) ^ 0xFFFFFFFF) + 1)))
slowness 0:58c3d014a4e7 53
slowness 0:58c3d014a4e7 54 /* Endianess-optimized shifting of two u8_t to create one u16_t */
slowness 0:58c3d014a4e7 55 #if BYTE_ORDER == LITTLE_ENDIAN
slowness 0:58c3d014a4e7 56 #define LWIP_MAKE_U16(a, b) ((a << 8) | b)
slowness 0:58c3d014a4e7 57 #else
slowness 0:58c3d014a4e7 58 #define LWIP_MAKE_U16(a, b) ((b << 8) | a)
slowness 0:58c3d014a4e7 59 #endif
slowness 0:58c3d014a4e7 60
slowness 0:58c3d014a4e7 61 #ifndef LWIP_PLATFORM_BYTESWAP
slowness 0:58c3d014a4e7 62 #define LWIP_PLATFORM_BYTESWAP 0
slowness 0:58c3d014a4e7 63 #endif
slowness 0:58c3d014a4e7 64
slowness 0:58c3d014a4e7 65 #ifndef LWIP_PREFIX_BYTEORDER_FUNCS
slowness 0:58c3d014a4e7 66 /* workaround for naming collisions on some platforms */
slowness 0:58c3d014a4e7 67
slowness 0:58c3d014a4e7 68 #ifdef htons
slowness 0:58c3d014a4e7 69 #undef htons
slowness 0:58c3d014a4e7 70 #endif /* htons */
slowness 0:58c3d014a4e7 71 #ifdef htonl
slowness 0:58c3d014a4e7 72 #undef htonl
slowness 0:58c3d014a4e7 73 #endif /* htonl */
slowness 0:58c3d014a4e7 74 #ifdef ntohs
slowness 0:58c3d014a4e7 75 #undef ntohs
slowness 0:58c3d014a4e7 76 #endif /* ntohs */
slowness 0:58c3d014a4e7 77 #ifdef ntohl
slowness 0:58c3d014a4e7 78 #undef ntohl
slowness 0:58c3d014a4e7 79 #endif /* ntohl */
slowness 0:58c3d014a4e7 80
slowness 0:58c3d014a4e7 81 #define htons(x) lwip_htons(x)
slowness 0:58c3d014a4e7 82 #define ntohs(x) lwip_ntohs(x)
slowness 0:58c3d014a4e7 83 #define htonl(x) lwip_htonl(x)
slowness 0:58c3d014a4e7 84 #define ntohl(x) lwip_ntohl(x)
slowness 0:58c3d014a4e7 85 #endif /* LWIP_PREFIX_BYTEORDER_FUNCS */
slowness 0:58c3d014a4e7 86
slowness 0:58c3d014a4e7 87 #if BYTE_ORDER == BIG_ENDIAN
slowness 0:58c3d014a4e7 88 #define lwip_htons(x) (x)
slowness 0:58c3d014a4e7 89 #define lwip_ntohs(x) (x)
slowness 0:58c3d014a4e7 90 #define lwip_htonl(x) (x)
slowness 0:58c3d014a4e7 91 #define lwip_ntohl(x) (x)
slowness 0:58c3d014a4e7 92 #define PP_HTONS(x) (x)
slowness 0:58c3d014a4e7 93 #define PP_NTOHS(x) (x)
slowness 0:58c3d014a4e7 94 #define PP_HTONL(x) (x)
slowness 0:58c3d014a4e7 95 #define PP_NTOHL(x) (x)
slowness 0:58c3d014a4e7 96 #else /* BYTE_ORDER != BIG_ENDIAN */
slowness 0:58c3d014a4e7 97 #if LWIP_PLATFORM_BYTESWAP
slowness 0:58c3d014a4e7 98 #define lwip_htons(x) LWIP_PLATFORM_HTONS(x)
slowness 0:58c3d014a4e7 99 #define lwip_ntohs(x) LWIP_PLATFORM_HTONS(x)
slowness 0:58c3d014a4e7 100 #define lwip_htonl(x) LWIP_PLATFORM_HTONL(x)
slowness 0:58c3d014a4e7 101 #define lwip_ntohl(x) LWIP_PLATFORM_HTONL(x)
slowness 0:58c3d014a4e7 102 #else /* LWIP_PLATFORM_BYTESWAP */
slowness 0:58c3d014a4e7 103 u16_t lwip_htons(u16_t x);
slowness 0:58c3d014a4e7 104 u16_t lwip_ntohs(u16_t x);
slowness 0:58c3d014a4e7 105 u32_t lwip_htonl(u32_t x);
slowness 0:58c3d014a4e7 106 u32_t lwip_ntohl(u32_t x);
slowness 0:58c3d014a4e7 107 #endif /* LWIP_PLATFORM_BYTESWAP */
slowness 0:58c3d014a4e7 108
slowness 0:58c3d014a4e7 109 /* These macros should be calculated by the preprocessor and are used
slowness 0:58c3d014a4e7 110 with compile-time constants only (so that there is no little-endian
slowness 0:58c3d014a4e7 111 overhead at runtime). */
slowness 0:58c3d014a4e7 112 #define PP_HTONS(x) ((((x) & 0xff) << 8) | (((x) & 0xff00) >> 8))
slowness 0:58c3d014a4e7 113 #define PP_NTOHS(x) PP_HTONS(x)
slowness 0:58c3d014a4e7 114 #define PP_HTONL(x) ((((x) & 0xff) << 24) | \
slowness 0:58c3d014a4e7 115 (((x) & 0xff00) << 8) | \
slowness 0:58c3d014a4e7 116 (((x) & 0xff0000UL) >> 8) | \
slowness 0:58c3d014a4e7 117 (((x) & 0xff000000UL) >> 24))
slowness 0:58c3d014a4e7 118 #define PP_NTOHL(x) PP_HTONL(x)
slowness 0:58c3d014a4e7 119
slowness 0:58c3d014a4e7 120 #endif /* BYTE_ORDER == BIG_ENDIAN */
slowness 0:58c3d014a4e7 121
slowness 0:58c3d014a4e7 122 #ifdef __cplusplus
slowness 0:58c3d014a4e7 123 }
slowness 0:58c3d014a4e7 124 #endif
slowness 0:58c3d014a4e7 125
slowness 0:58c3d014a4e7 126 #endif /* __LWIP_DEF_H__ */
slowness 0:58c3d014a4e7 127