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