This library is stripped down version of NetServices library. HTTP server and client function is NOT supported.
lwip/core/def.c@0:dcf3c92487ca, 2011-07-20 (annotated)
- Committer:
- idinor
- Date:
- Wed Jul 20 11:45:39 2011 +0000
- Revision:
- 0:dcf3c92487ca
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
idinor | 0:dcf3c92487ca | 1 | /** |
idinor | 0:dcf3c92487ca | 2 | * @file |
idinor | 0:dcf3c92487ca | 3 | * Common functions used throughout the stack. |
idinor | 0:dcf3c92487ca | 4 | * |
idinor | 0:dcf3c92487ca | 5 | */ |
idinor | 0:dcf3c92487ca | 6 | |
idinor | 0:dcf3c92487ca | 7 | /* |
idinor | 0:dcf3c92487ca | 8 | * Copyright (c) 2001-2004 Swedish Institute of Computer Science. |
idinor | 0:dcf3c92487ca | 9 | * All rights reserved. |
idinor | 0:dcf3c92487ca | 10 | * |
idinor | 0:dcf3c92487ca | 11 | * Redistribution and use in source and binary forms, with or without modification, |
idinor | 0:dcf3c92487ca | 12 | * are permitted provided that the following conditions are met: |
idinor | 0:dcf3c92487ca | 13 | * |
idinor | 0:dcf3c92487ca | 14 | * 1. Redistributions of source code must retain the above copyright notice, |
idinor | 0:dcf3c92487ca | 15 | * this list of conditions and the following disclaimer. |
idinor | 0:dcf3c92487ca | 16 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
idinor | 0:dcf3c92487ca | 17 | * this list of conditions and the following disclaimer in the documentation |
idinor | 0:dcf3c92487ca | 18 | * and/or other materials provided with the distribution. |
idinor | 0:dcf3c92487ca | 19 | * 3. The name of the author may not be used to endorse or promote products |
idinor | 0:dcf3c92487ca | 20 | * derived from this software without specific prior written permission. |
idinor | 0:dcf3c92487ca | 21 | * |
idinor | 0:dcf3c92487ca | 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
idinor | 0:dcf3c92487ca | 23 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
idinor | 0:dcf3c92487ca | 24 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT |
idinor | 0:dcf3c92487ca | 25 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
idinor | 0:dcf3c92487ca | 26 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT |
idinor | 0:dcf3c92487ca | 27 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
idinor | 0:dcf3c92487ca | 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
idinor | 0:dcf3c92487ca | 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
idinor | 0:dcf3c92487ca | 30 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY |
idinor | 0:dcf3c92487ca | 31 | * OF SUCH DAMAGE. |
idinor | 0:dcf3c92487ca | 32 | * |
idinor | 0:dcf3c92487ca | 33 | * This file is part of the lwIP TCP/IP stack. |
idinor | 0:dcf3c92487ca | 34 | * |
idinor | 0:dcf3c92487ca | 35 | * Author: Simon Goldschmidt |
idinor | 0:dcf3c92487ca | 36 | * |
idinor | 0:dcf3c92487ca | 37 | */ |
idinor | 0:dcf3c92487ca | 38 | |
idinor | 0:dcf3c92487ca | 39 | #include "lwip/opt.h" |
idinor | 0:dcf3c92487ca | 40 | #include "lwip/def.h" |
idinor | 0:dcf3c92487ca | 41 | |
idinor | 0:dcf3c92487ca | 42 | /** |
idinor | 0:dcf3c92487ca | 43 | * These are reference implementations of the byte swapping functions. |
idinor | 0:dcf3c92487ca | 44 | * Again with the aim of being simple, correct and fully portable. |
idinor | 0:dcf3c92487ca | 45 | * Byte swapping is the second thing you would want to optimize. You will |
idinor | 0:dcf3c92487ca | 46 | * need to port it to your architecture and in your cc.h: |
idinor | 0:dcf3c92487ca | 47 | * |
idinor | 0:dcf3c92487ca | 48 | * #define LWIP_PLATFORM_BYTESWAP 1 |
idinor | 0:dcf3c92487ca | 49 | * #define LWIP_PLATFORM_HTONS(x) <your_htons> |
idinor | 0:dcf3c92487ca | 50 | * #define LWIP_PLATFORM_HTONL(x) <your_htonl> |
idinor | 0:dcf3c92487ca | 51 | * |
idinor | 0:dcf3c92487ca | 52 | * Note ntohs() and ntohl() are merely references to the htonx counterparts. |
idinor | 0:dcf3c92487ca | 53 | */ |
idinor | 0:dcf3c92487ca | 54 | |
idinor | 0:dcf3c92487ca | 55 | #if (LWIP_PLATFORM_BYTESWAP == 0) && (BYTE_ORDER == LITTLE_ENDIAN) |
idinor | 0:dcf3c92487ca | 56 | |
idinor | 0:dcf3c92487ca | 57 | /** |
idinor | 0:dcf3c92487ca | 58 | * Convert an u16_t from host- to network byte order. |
idinor | 0:dcf3c92487ca | 59 | * |
idinor | 0:dcf3c92487ca | 60 | * @param n u16_t in host byte order |
idinor | 0:dcf3c92487ca | 61 | * @return n in network byte order |
idinor | 0:dcf3c92487ca | 62 | */ |
idinor | 0:dcf3c92487ca | 63 | u16_t |
idinor | 0:dcf3c92487ca | 64 | lwip_htons(u16_t n) |
idinor | 0:dcf3c92487ca | 65 | { |
idinor | 0:dcf3c92487ca | 66 | return ((n & 0xff) << 8) | ((n & 0xff00) >> 8); |
idinor | 0:dcf3c92487ca | 67 | } |
idinor | 0:dcf3c92487ca | 68 | |
idinor | 0:dcf3c92487ca | 69 | /** |
idinor | 0:dcf3c92487ca | 70 | * Convert an u16_t from network- to host byte order. |
idinor | 0:dcf3c92487ca | 71 | * |
idinor | 0:dcf3c92487ca | 72 | * @param n u16_t in network byte order |
idinor | 0:dcf3c92487ca | 73 | * @return n in host byte order |
idinor | 0:dcf3c92487ca | 74 | */ |
idinor | 0:dcf3c92487ca | 75 | u16_t |
idinor | 0:dcf3c92487ca | 76 | lwip_ntohs(u16_t n) |
idinor | 0:dcf3c92487ca | 77 | { |
idinor | 0:dcf3c92487ca | 78 | return lwip_htons(n); |
idinor | 0:dcf3c92487ca | 79 | } |
idinor | 0:dcf3c92487ca | 80 | |
idinor | 0:dcf3c92487ca | 81 | /** |
idinor | 0:dcf3c92487ca | 82 | * Convert an u32_t from host- to network byte order. |
idinor | 0:dcf3c92487ca | 83 | * |
idinor | 0:dcf3c92487ca | 84 | * @param n u32_t in host byte order |
idinor | 0:dcf3c92487ca | 85 | * @return n in network byte order |
idinor | 0:dcf3c92487ca | 86 | */ |
idinor | 0:dcf3c92487ca | 87 | u32_t |
idinor | 0:dcf3c92487ca | 88 | lwip_htonl(u32_t n) |
idinor | 0:dcf3c92487ca | 89 | { |
idinor | 0:dcf3c92487ca | 90 | return ((n & 0xff) << 24) | |
idinor | 0:dcf3c92487ca | 91 | ((n & 0xff00) << 8) | |
idinor | 0:dcf3c92487ca | 92 | ((n & 0xff0000UL) >> 8) | |
idinor | 0:dcf3c92487ca | 93 | ((n & 0xff000000UL) >> 24); |
idinor | 0:dcf3c92487ca | 94 | } |
idinor | 0:dcf3c92487ca | 95 | |
idinor | 0:dcf3c92487ca | 96 | /** |
idinor | 0:dcf3c92487ca | 97 | * Convert an u32_t from network- to host byte order. |
idinor | 0:dcf3c92487ca | 98 | * |
idinor | 0:dcf3c92487ca | 99 | * @param n u32_t in network byte order |
idinor | 0:dcf3c92487ca | 100 | * @return n in host byte order |
idinor | 0:dcf3c92487ca | 101 | */ |
idinor | 0:dcf3c92487ca | 102 | u32_t |
idinor | 0:dcf3c92487ca | 103 | lwip_ntohl(u32_t n) |
idinor | 0:dcf3c92487ca | 104 | { |
idinor | 0:dcf3c92487ca | 105 | return lwip_htonl(n); |
idinor | 0:dcf3c92487ca | 106 | } |
idinor | 0:dcf3c92487ca | 107 | |
idinor | 0:dcf3c92487ca | 108 | #endif /* (LWIP_PLATFORM_BYTESWAP == 0) && (BYTE_ORDER == LITTLE_ENDIAN) */ |