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