Greg Steiert / pegasus_dev

Dependents:   blinky_max32630fthr

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers inet_chksum.h Source File

inet_chksum.h

Go to the documentation of this file.
00001 /**
00002  * @file
00003  * IP checksum calculation functions
00004  */
00005 
00006 /*
00007  * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
00008  * All rights reserved.
00009  *
00010  * Redistribution and use in source and binary forms, with or without modification,
00011  * are permitted provided that the following conditions are met:
00012  *
00013  * 1. Redistributions of source code must retain the above copyright notice,
00014  *    this list of conditions and the following disclaimer.
00015  * 2. Redistributions in binary form must reproduce the above copyright notice,
00016  *    this list of conditions and the following disclaimer in the documentation
00017  *    and/or other materials provided with the distribution.
00018  * 3. The name of the author may not be used to endorse or promote products
00019  *    derived from this software without specific prior written permission.
00020  *
00021  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
00022  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00023  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
00024  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00025  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
00026  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00027  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00028  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
00029  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
00030  * OF SUCH DAMAGE.
00031  *
00032  * This file is part of the lwIP TCP/IP stack.
00033  *
00034  * Author: Adam Dunkels <adam@sics.se>
00035  *
00036  */
00037 #ifndef LWIP_HDR_INET_CHKSUM_H
00038 #define LWIP_HDR_INET_CHKSUM_H
00039 
00040 #include "lwip/opt.h"
00041 
00042 #include "lwip/pbuf.h"
00043 #include "lwip/ip_addr.h"
00044 
00045 /** Swap the bytes in an u16_t: much like htons() for little-endian */
00046 #ifndef SWAP_BYTES_IN_WORD
00047 #if LWIP_PLATFORM_BYTESWAP && (BYTE_ORDER == LITTLE_ENDIAN)
00048 /* little endian and PLATFORM_BYTESWAP defined */
00049 #define SWAP_BYTES_IN_WORD(w) LWIP_PLATFORM_HTONS(w)
00050 #else /* LWIP_PLATFORM_BYTESWAP && (BYTE_ORDER == LITTLE_ENDIAN) */
00051 /* can't use htons on big endian (or PLATFORM_BYTESWAP not defined)... */
00052 #define SWAP_BYTES_IN_WORD(w) (((w) & 0xff) << 8) | (((w) & 0xff00) >> 8)
00053 #endif /* LWIP_PLATFORM_BYTESWAP && (BYTE_ORDER == LITTLE_ENDIAN)*/
00054 #endif /* SWAP_BYTES_IN_WORD */
00055 
00056 /** Split an u32_t in two u16_ts and add them up */
00057 #ifndef FOLD_U32T
00058 #define FOLD_U32T(u)          (((u) >> 16) + ((u) & 0x0000ffffUL))
00059 #endif
00060 
00061 #if LWIP_CHECKSUM_ON_COPY
00062 /** Function-like macro: same as MEMCPY but returns the checksum of copied data
00063     as u16_t */
00064 # ifndef LWIP_CHKSUM_COPY
00065 #  define LWIP_CHKSUM_COPY(dst, src, len) lwip_chksum_copy(dst, src, len)
00066 #  ifndef LWIP_CHKSUM_COPY_ALGORITHM
00067 #   define LWIP_CHKSUM_COPY_ALGORITHM 1
00068 #  endif /* LWIP_CHKSUM_COPY_ALGORITHM */
00069 # else /* LWIP_CHKSUM_COPY */
00070 #  define LWIP_CHKSUM_COPY_ALGORITHM 0
00071 # endif /* LWIP_CHKSUM_COPY */
00072 #else /* LWIP_CHECKSUM_ON_COPY */
00073 # define LWIP_CHKSUM_COPY_ALGORITHM 0
00074 #endif /* LWIP_CHECKSUM_ON_COPY */
00075 
00076 #ifdef __cplusplus
00077 extern "C" {
00078 #endif
00079 
00080 u16_t inet_chksum(const void *dataptr, u16_t len);
00081 u16_t inet_chksum_pbuf(struct pbuf *p);
00082 #if LWIP_CHKSUM_COPY_ALGORITHM
00083 u16_t lwip_chksum_copy(void *dst, const void *src, u16_t len);
00084 #endif /* LWIP_CHKSUM_COPY_ALGORITHM */
00085 
00086 #if LWIP_IPV4
00087 u16_t inet_chksum_pseudo(struct pbuf *p, u8_t proto, u16_t proto_len,
00088        const ip4_addr_t *src, const ip4_addr_t *dest);
00089 u16_t inet_chksum_pseudo_partial(struct pbuf *p, u8_t proto,
00090        u16_t proto_len, u16_t chksum_len, const ip4_addr_t *src, const ip4_addr_t *dest);
00091 #endif /* LWIP_IPV4 */
00092 
00093 #if LWIP_IPV6
00094 u16_t ip6_chksum_pseudo(struct pbuf *p, u8_t proto, u16_t proto_len,
00095        const ip6_addr_t *src, const ip6_addr_t *dest);
00096 u16_t ip6_chksum_pseudo_partial(struct pbuf *p, u8_t proto, u16_t proto_len,
00097        u16_t chksum_len, const ip6_addr_t *src, const ip6_addr_t *dest);
00098 #endif /* LWIP_IPV6 */
00099 
00100 
00101 u16_t ip_chksum_pseudo(struct pbuf *p, u8_t proto, u16_t proto_len,
00102        const ip_addr_t *src, const ip_addr_t *dest);
00103 u16_t ip_chksum_pseudo_partial(struct pbuf *p, u8_t proto, u16_t proto_len,
00104        u16_t chksum_len, const ip_addr_t *src, const ip_addr_t *dest);
00105 
00106 #ifdef __cplusplus
00107 }
00108 #endif
00109 
00110 #endif /* LWIP_HDR_INET_H */
00111