Ignore:
Timestamp:
2010-10-19T20:55:53Z (14 years ago)
Author:
Jakub Jermar <jakub@…>
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.
Message:

Merge mainline changes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/net/include/net_checksum.h

    r1882525 rf14291b  
    2727 */
    2828
    29 /** @addtogroup net
    30  *  @{
     29/** @addtogroup libnet
     30 * @{
    3131 */
    3232
    3333/** @file
    34  *  General CRC and checksum computation.
     34 * General CRC and checksum computation.
    3535 */
    3636
    37 #ifndef __NET_CHECKSUM_H__
    38 #define __NET_CHECKSUM_H__
     37#ifndef LIBNET_CHECKSUM_H_
     38#define LIBNET_CHECKSUM_H_
    3939
    4040#include <byteorder.h>
    41 
    4241#include <sys/types.h>
    4342
    4443/** IP checksum value for computed zero checksum.
    45  *  Zero is returned as 0xFFFF (not flipped)
     44 * Zero is returned as 0xFFFF (not flipped)
    4645 */
    47 #define IP_CHECKSUM_ZERO                        0xFFFFu
     46#define IP_CHECKSUM_ZERO        0xffffU
    4847
    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  */
    5548#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)
    5751#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)
    5954#endif
    6055
    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);
     56extern uint32_t compute_crc32_le(uint32_t, uint8_t *, size_t);
     57extern uint32_t compute_crc32_be(uint32_t, uint8_t *, size_t);
     58extern uint32_t compute_checksum(uint32_t, uint8_t *, size_t);
     59extern uint16_t compact_checksum(uint32_t);
     60extern uint16_t flip_checksum(uint16_t);
     61extern uint16_t ip_checksum(uint8_t *, size_t);
    10962
    11063#endif
Note: See TracChangeset for help on using the changeset viewer.