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