Changeset f14291b in mainline for uspace/lib/net/include/net_checksum.h
- Timestamp:
- 2010-10-19T20:55:53Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- a93d79a
- Parents:
- 1882525 (diff), a7a85d16 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/net/include/net_checksum.h
r1882525 rf14291b 27 27 */ 28 28 29 /** @addtogroup net30 * 29 /** @addtogroup libnet 30 * @{ 31 31 */ 32 32 33 33 /** @file 34 * 34 * General CRC and checksum computation. 35 35 */ 36 36 37 #ifndef __NET_CHECKSUM_H__38 #define __NET_CHECKSUM_H__37 #ifndef LIBNET_CHECKSUM_H_ 38 #define LIBNET_CHECKSUM_H_ 39 39 40 40 #include <byteorder.h> 41 42 41 #include <sys/types.h> 43 42 44 43 /** IP checksum value for computed zero checksum. 45 * 44 * Zero is returned as 0xFFFF (not flipped) 46 45 */ 47 #define IP_CHECKSUM_ZERO 0xFFFFu46 #define IP_CHECKSUM_ZERO 0xffffU 48 47 49 /** Computes CRC32 value.50 * @param[in] seed Initial value. Often used as 0 or ~0.51 * @param[in] data Pointer to the beginning of data to process.52 * @param[in] length Length of the data in bits.53 * @returns The computed CRC32 of the length bits of the data.54 */55 48 #ifdef ARCH_IS_BIG_ENDIAN 56 #define compute_crc32(seed, data, length) compute_crc32_be(seed, (uint8_t *) data, length) 49 #define compute_crc32(seed, data, length) \ 50 compute_crc32_be(seed, (uint8_t *) data, length) 57 51 #else 58 #define compute_crc32(seed, data, length) compute_crc32_le(seed, (uint8_t *) data, length) 52 #define compute_crc32(seed, data, length) \ 53 compute_crc32_le(seed, (uint8_t *) data, length) 59 54 #endif 60 55 61 /** Computes CRC32 value in the little-endian environment. 62 * @param[in] seed Initial value. Often used as 0 or ~0. 63 * @param[in] data Pointer to the beginning of data to process. 64 * @param[in] length Length of the data in bits. 65 * @returns The computed CRC32 of the length bits of the data. 66 */ 67 extern uint32_t compute_crc32_le(uint32_t seed, uint8_t * data, size_t length); 68 69 /** Computes CRC32 value in the big-endian environment. 70 * @param[in] seed Initial value. Often used as 0 or ~0. 71 * @param[in] data Pointer to the beginning of data to process. 72 * @param[in] length Length of the data in bits. 73 * @returns The computed CRC32 of the length bits of the data. 74 */ 75 extern uint32_t compute_crc32_be(uint32_t seed, uint8_t * data, size_t length); 76 77 /** Computes sum of the 2 byte fields. 78 * Padds one zero (0) byte if odd. 79 * @param[in] seed Initial value. Often used as 0 or ~0. 80 * @param[in] data Pointer to the beginning of data to process. 81 * @param[in] length Length of the data in bytes. 82 * @returns The computed checksum of the length bytes of the data. 83 */ 84 extern uint32_t compute_checksum(uint32_t seed, uint8_t * data, size_t length); 85 86 /** Compacts the computed checksum to the 16 bit number adding the carries. 87 * @param[in] sum Computed checksum. 88 * @returns Compacted computed checksum to the 16 bits. 89 */ 90 extern uint16_t compact_checksum(uint32_t sum); 91 92 /** Returns or flips the checksum if zero. 93 * @param[in] checksum The computed checksum. 94 * @returns The internet protocol header checksum. 95 * @returns 0xFFFF if the computed checksum is zero. 96 */ 97 extern uint16_t flip_checksum(uint16_t checksum); 98 99 /** Computes the ip header checksum. 100 * To compute the checksum of a new packet, the checksum header field must be zero. 101 * To check the checksum of a received packet, the checksum may be left set. 102 * The zero (0) value will be returned in this case if valid. 103 * @param[in] data The header data. 104 * @param[in] length The header length in bytes. 105 * @returns The internet protocol header checksum. 106 * @returns 0xFFFF if the computed checksum is zero. 107 */ 108 extern uint16_t ip_checksum(uint8_t * data, size_t length); 56 extern uint32_t compute_crc32_le(uint32_t, uint8_t *, size_t); 57 extern uint32_t compute_crc32_be(uint32_t, uint8_t *, size_t); 58 extern uint32_t compute_checksum(uint32_t, uint8_t *, size_t); 59 extern uint16_t compact_checksum(uint32_t); 60 extern uint16_t flip_checksum(uint16_t); 61 extern uint16_t ip_checksum(uint8_t *, size_t); 109 62 110 63 #endif
Note:
See TracChangeset
for help on using the changeset viewer.