First step: AutoIP compiled in and working

Dependencies:   mbed

Committer:
darran
Date:
Fri Jun 18 15:54:21 2010 +0000
Revision:
1:4218cacaf696
Parent:
0:55a05330f8cc

        

Who changed what in which revision?

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