Stripped down version of Segundos NetService library (http://mbed.org/users/segundo/libraries/NetServices ). I have removed all NetServices, and all functions which had been disabled. Use this version when you need only pure TCP or UDP functions - this library compiles faster.

Dependencies:   lwip lwip-sys

Dependents:   christmasLights device_server pop3demo device_server_udp ... more

Committer:
hlipka
Date:
Mon Jan 10 21:03:11 2011 +0000
Revision:
0:8b387bed54c2
initial version

Who changed what in which revision?

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