30 |
* |
* |
31 |
*/ |
*/ |
32 |
|
|
33 |
/*-----------------------------------------------------------------------------------*/ |
|
34 |
/* inet.c |
/* inet.c |
35 |
* |
* |
36 |
* Functions common to all TCP/IP modules, such as the Internet checksum and the |
* Functions common to all TCP/IP modules, such as the Internet checksum and the |
37 |
* byte order functions. |
* byte order functions. |
38 |
* |
* |
39 |
*/ |
*/ |
40 |
/*-----------------------------------------------------------------------------------*/ |
|
41 |
|
|
42 |
#include "lwip/opt.h" |
#include "lwip/opt.h" |
43 |
|
|
47 |
#include "lwip/inet.h" |
#include "lwip/inet.h" |
48 |
|
|
49 |
|
|
50 |
/*-----------------------------------------------------------------------------------*/ |
|
51 |
static u16_t |
static u16_t |
52 |
lwip_chksum(void *dataptr, int len) |
lwip_chksum(void *dataptr, int len) |
53 |
{ |
{ |
75 |
|
|
76 |
return (u16_t)acc; |
return (u16_t)acc; |
77 |
} |
} |
78 |
/*-----------------------------------------------------------------------------------*/ |
|
79 |
/* inet_chksum_pseudo: |
/* inet_chksum_pseudo: |
80 |
* |
* |
81 |
* Calculates the pseudo Internet checksum used by TCP and UDP for a pbuf chain. |
* Calculates the pseudo Internet checksum used by TCP and UDP for a pbuf chain. |
82 |
*/ |
*/ |
83 |
/*-----------------------------------------------------------------------------------*/ |
|
84 |
u16_t |
u16_t |
85 |
inet_chksum_pseudo(struct pbuf *p, |
inet_chksum_pseudo(struct pbuf *p, |
86 |
struct ip_addr *src, struct ip_addr *dest, |
struct ip_addr *src, struct ip_addr *dest, |
124 |
LWIP_DEBUGF(INET_DEBUG, ("inet_chksum_pseudo(): pbuf chain lwip_chksum()=%lx\n", acc)); |
LWIP_DEBUGF(INET_DEBUG, ("inet_chksum_pseudo(): pbuf chain lwip_chksum()=%lx\n", acc)); |
125 |
return ~(acc & 0xffffUL); |
return ~(acc & 0xffffUL); |
126 |
} |
} |
127 |
/*-----------------------------------------------------------------------------------*/ |
|
128 |
/* inet_chksum: |
/* inet_chksum: |
129 |
* |
* |
130 |
* Calculates the Internet checksum over a portion of memory. Used primarely for IP |
* Calculates the Internet checksum over a portion of memory. Used primarely for IP |
131 |
* and ICMP. |
* and ICMP. |
132 |
*/ |
*/ |
133 |
/*-----------------------------------------------------------------------------------*/ |
|
134 |
u16_t |
u16_t |
135 |
inet_chksum(void *dataptr, u16_t len) |
inet_chksum(void *dataptr, u16_t len) |
136 |
{ |
{ |
142 |
} |
} |
143 |
return ~(acc & 0xffff); |
return ~(acc & 0xffff); |
144 |
} |
} |
145 |
/*-----------------------------------------------------------------------------------*/ |
|
146 |
u16_t |
u16_t |
147 |
inet_chksum_pbuf(struct pbuf *p) |
inet_chksum_pbuf(struct pbuf *p) |
148 |
{ |
{ |
179 |
#define isspace(c) (c == ' ' || c == '\f' || c == '\n' || c == '\r' || c == '\t' || c == '\v') |
#define isspace(c) (c == ' ' || c == '\f' || c == '\n' || c == '\r' || c == '\t' || c == '\v') |
180 |
#endif |
#endif |
181 |
|
|
182 |
/*-----------------------------------------------------------------------------------*/ |
|
183 |
/* |
/* |
184 |
* Ascii internet address interpretation routine. |
* Ascii internet address interpretation routine. |
185 |
* The value returned is in network order. |
* The value returned is in network order. |
328 |
return str; |
return str; |
329 |
} |
} |
330 |
|
|
331 |
/*-----------------------------------------------------------------------------------*/ |
|
332 |
#ifndef BYTE_ORDER |
#ifndef BYTE_ORDER |
333 |
#error BYTE_ORDER is not defined |
#error BYTE_ORDER is not defined |
334 |
#endif |
#endif |
335 |
#if BYTE_ORDER == LITTLE_ENDIAN |
#if BYTE_ORDER == LITTLE_ENDIAN |
336 |
/*-----------------------------------------------------------------------------------*/ |
|
337 |
u16_t |
u16_t |
338 |
htons(u16_t n) |
htons(u16_t n) |
339 |
{ |
{ |
340 |
return ((n & 0xff) << 8) | ((n & 0xff00) >> 8); |
return ((n & 0xff) << 8) | ((n & 0xff00) >> 8); |
341 |
} |
} |
342 |
/*-----------------------------------------------------------------------------------*/ |
|
343 |
u16_t |
u16_t |
344 |
ntohs(u16_t n) |
ntohs(u16_t n) |
345 |
{ |
{ |
346 |
return htons(n); |
return htons(n); |
347 |
} |
} |
348 |
/*-----------------------------------------------------------------------------------*/ |
|
349 |
u32_t |
u32_t |
350 |
htonl(u32_t n) |
htonl(u32_t n) |
351 |
{ |
{ |
354 |
((n & 0xff0000) >> 8) | |
((n & 0xff0000) >> 8) | |
355 |
((n & 0xff000000) >> 24); |
((n & 0xff000000) >> 24); |
356 |
} |
} |
357 |
/*-----------------------------------------------------------------------------------*/ |
|
358 |
u32_t |
u32_t |
359 |
ntohl(u32_t n) |
ntohl(u32_t n) |
360 |
{ |
{ |
361 |
return htonl(n); |
return htonl(n); |
362 |
} |
} |
363 |
/*-----------------------------------------------------------------------------------*/ |
|
364 |
#endif /* BYTE_ORDER == LITTLE_ENDIAN */ |
#endif /* BYTE_ORDER == LITTLE_ENDIAN */ |