Dependents:   SNMPAgent HTTPServer think_speak_a cyassl-client ... more

Committer:
mamezu
Date:
Thu Dec 09 01:33:56 2010 +0000
Revision:
0:0f6c82fcde82

        

Who changed what in which revision?

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