Version of http://mbed.org/cookbook/NetServicesTribute with setting set the same for LPC2368

Dependents:   UDPSocketExample 24LCxx_I2CApp WeatherPlatform_pachube HvZServerLib ... more

Committer:
simon
Date:
Tue Nov 23 14:15:36 2010 +0000
Revision:
0:350011bf8be7
Experimental version for testing UDP

Who changed what in which revision?

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