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