Net stack with AutoIP enabled

Dependencies:   mbed

Committer:
darran
Date:
Fri Jul 02 17:21:58 2010 +0000
Revision:
0:ac21159e27f4

        

Who changed what in which revision?

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