Copy of NetServicesMin with the HTTP Client library. Includes modification for HTTP servers which send the HTTP status line in its own packet.

Committer:
andrewbonney
Date:
Thu May 26 10:02:40 2011 +0000
Revision:
0:18dd877d2c77

        

Who changed what in which revision?

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