The Pedigree Project  0.1
inet_chksum.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008-2014, Pedigree Developers
3  *
4  * Please see the CONTRIB file in the root of the source tree for a full
5  * list of contributors.
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
25 /*
26  * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
27  * All rights reserved.
28  *
29  * Redistribution and use in source and binary forms, with or without modification,
30  * are permitted provided that the following conditions are met:
31  *
32  * 1. Redistributions of source code must retain the above copyright notice,
33  * this list of conditions and the following disclaimer.
34  * 2. Redistributions in binary form must reproduce the above copyright notice,
35  * this list of conditions and the following disclaimer in the documentation
36  * and/or other materials provided with the distribution.
37  * 3. The name of the author may not be used to endorse or promote products
38  * derived from this software without specific prior written permission.
39  *
40  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
41  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
42  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
43  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
44  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
45  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
46  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
47  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
48  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
49  * OF SUCH DAMAGE.
50  *
51  * This file is part of the lwIP TCP/IP stack.
52  *
53  * Author: Adam Dunkels <adam@sics.se>
54  *
55  */
56 #ifndef LWIP_HDR_INET_CHKSUM_H
57 #define LWIP_HDR_INET_CHKSUM_H
58 
59 #include "lwip/opt.h"
60 
61 #include "lwip/pbuf.h"
62 #include "lwip/ip_addr.h"
63 
65 #ifndef SWAP_BYTES_IN_WORD
66 #define SWAP_BYTES_IN_WORD(w) (((w) & 0xff) << 8) | (((w) & 0xff00) >> 8)
67 #endif /* SWAP_BYTES_IN_WORD */
68 
70 #ifndef FOLD_U32T
71 #define FOLD_U32T(u) (((u) >> 16) + ((u) & 0x0000ffffUL))
72 #endif
73 
74 #if LWIP_CHECKSUM_ON_COPY
75 
77 # ifndef LWIP_CHKSUM_COPY
78 # define LWIP_CHKSUM_COPY(dst, src, len) lwip_chksum_copy(dst, src, len)
79 # ifndef LWIP_CHKSUM_COPY_ALGORITHM
80 # define LWIP_CHKSUM_COPY_ALGORITHM 1
81 # endif /* LWIP_CHKSUM_COPY_ALGORITHM */
82 # else /* LWIP_CHKSUM_COPY */
83 # define LWIP_CHKSUM_COPY_ALGORITHM 0
84 # endif /* LWIP_CHKSUM_COPY */
85 #else /* LWIP_CHECKSUM_ON_COPY */
86 # define LWIP_CHKSUM_COPY_ALGORITHM 0
87 #endif /* LWIP_CHECKSUM_ON_COPY */
88 
89 #ifdef __cplusplus
90 extern "C" {
91 #endif
92 
93 u16_t inet_chksum(const void *dataptr, u16_t len);
94 u16_t inet_chksum_pbuf(struct pbuf *p);
95 #if LWIP_CHKSUM_COPY_ALGORITHM
96 u16_t lwip_chksum_copy(void *dst, const void *src, u16_t len);
97 #endif /* LWIP_CHKSUM_COPY_ALGORITHM */
98 
99 #if LWIP_IPV4
100 u16_t inet_chksum_pseudo(struct pbuf *p, u8_t proto, u16_t proto_len,
101  const ip4_addr_t *src, const ip4_addr_t *dest);
102 u16_t inet_chksum_pseudo_partial(struct pbuf *p, u8_t proto,
103  u16_t proto_len, u16_t chksum_len, const ip4_addr_t *src, const ip4_addr_t *dest);
104 #endif /* LWIP_IPV4 */
105 
106 #if LWIP_IPV6
107 u16_t ip6_chksum_pseudo(struct pbuf *p, u8_t proto, u16_t proto_len,
108  const ip6_addr_t *src, const ip6_addr_t *dest);
109 u16_t ip6_chksum_pseudo_partial(struct pbuf *p, u8_t proto, u16_t proto_len,
110  u16_t chksum_len, const ip6_addr_t *src, const ip6_addr_t *dest);
111 #endif /* LWIP_IPV6 */
112 
113 
114 u16_t ip_chksum_pseudo(struct pbuf *p, u8_t proto, u16_t proto_len,
115  const ip_addr_t *src, const ip_addr_t *dest);
116 u16_t ip_chksum_pseudo_partial(struct pbuf *p, u8_t proto, u16_t proto_len,
117  u16_t chksum_len, const ip_addr_t *src, const ip_addr_t *dest);
118 
119 #ifdef __cplusplus
120 }
121 #endif
122 
123 #endif /* LWIP_HDR_INET_H */
124 
u16_t inet_chksum_pbuf(struct pbuf *p)
Definition: inet_chksum.c:587
u16_t len
Definition: pbuf.h:178
Definition: pbuf.h:161