version 1.1, 2008/11/05 17:02:55
|
version 1.2, 2010/01/20 00:04:45
|
Line 12
|
Line 12
|
static int crc_Errno; |
static int crc_Errno; |
static char crc_Error[MAX_STR + 1]; |
static char crc_Error[MAX_STR + 1]; |
|
|
|
// Adler module |
const u_long crc_modAdler = 0xFFF1L; |
const u_long crc_modAdler = 0xFFF1L; |
|
|
|
// All known library CRC types ... |
const crcPoly_t crc_Poly[] = { |
const crcPoly_t crc_Poly[] = { |
{ 1, (u_long) 0x1, "CRC-1-Parity" }, |
{ 1, (u_long) 0x1, "CRC-1-Parity" }, |
{ 4, (u_long) 0x3, "CRC-4-ITU" }, |
{ 4, (u_long) 0x3, "CRC-4-ITU" }, |
Line 33 const crcPoly_t crc_Poly[] = {
|
Line 35 const crcPoly_t crc_Poly[] = {
|
|
|
// ---------------------------------------------------------- |
// ---------------------------------------------------------- |
|
|
|
// |
|
// Error maintenance functions ... |
|
// |
|
|
|
// crc_GetErrno() Get error code of last operation |
inline int crc_GetErrno() |
inline int crc_GetErrno() |
{ |
{ |
return crc_Errno; |
return crc_Errno; |
} |
} |
|
|
|
// crc_GetError() Get error text of last operation |
inline const char *crc_GetError() |
inline const char *crc_GetError() |
{ |
{ |
return crc_Error; |
return crc_Error; |
} |
} |
|
|
|
// crcSetErr() Set error to variables for internal use!!! |
|
inline void crcSetErr(int eno, char *estr, ...) |
|
{ |
|
va_list lst; |
|
|
|
crc_Errno = eno; |
|
memset(crc_Error, 0, MAX_STR + 1); |
|
va_start(lst, estr); |
|
vsnprintf(crc_Error, MAX_STR + 1, estr, lst); |
|
va_end(lst); |
|
} |
|
|
// ---------------------------------------------------------- |
// ---------------------------------------------------------- |
|
|
|
/* |
|
* crcReflect() Reflect all bits of number |
|
* @crcNum = Number for reflection |
|
* @crcBits = Number width bits |
|
* return: -1 error, !=-1 reflecting number |
|
*/ |
inline u_long crcReflect(u_long crcNum, u_char crcBits) |
inline u_long crcReflect(u_long crcNum, u_char crcBits) |
{ |
{ |
register u_long i, j, rev; |
register u_long i, j, rev; |
Line 57 inline u_long crcReflect(u_long crcNum, u_char crcBits
|
Line 83 inline u_long crcReflect(u_long crcNum, u_char crcBits
|
return rev; |
return rev; |
} |
} |
|
|
|
/* |
|
* crcCalc() Generic CRC calculation function for many sub variants of CRC algorithms |
|
* @psBuf = Data for calculation |
|
* @bufLen = Length of data |
|
* @crcBits = CRC algorithm bits (1, 4, 5, 6, 7, 8, 10, 11, 12, 15, 16, 24, 30, 32) |
|
* @RevOpts = Options for computation (REVOPTS_REVERTBYTE, REVOPTS_REVERTCRC) |
|
* @initCRC = Initial CRC value |
|
* @xorCRC = Last xor CRC value |
|
* return: -1 error, !=-1 CRC checksum |
|
*/ |
inline u_long crcCalc(u_char * __restrict psBuf, u_int bufLen, u_char crcBits, u_char RevOpts, u_long initCRC, u_long xorCRC) |
inline u_long crcCalc(u_char * __restrict psBuf, u_int bufLen, u_char crcBits, u_char RevOpts, u_long initCRC, u_long xorCRC) |
{ |
{ |
const u_long bits = sizeof(long) * 8 - crcBits; |
const u_long bits = sizeof(long) * 8 - crcBits; |
Line 152 inline u_long crcCalc(u_char * __restrict psBuf, u_int
|
Line 188 inline u_long crcCalc(u_char * __restrict psBuf, u_int
|
|
|
// ---------------------------------------------------------- |
// ---------------------------------------------------------- |
|
|
|
/* |
|
* crcIP() Checksum in IP communication |
|
* @nBuf = Data for calculation |
|
* @bufLen = Length of data |
|
* return: -1 error, !=-1 Checksum |
|
*/ |
inline u_short crcIP(u_short * __restrict nBuf, int bufLen) |
inline u_short crcIP(u_short * __restrict nBuf, int bufLen) |
{ |
{ |
register u_long sum; |
register u_long sum; |
Line 172 inline u_short crcIP(u_short * __restrict nBuf, int bu
|
Line 214 inline u_short crcIP(u_short * __restrict nBuf, int bu
|
return (u_short) ~sum; |
return (u_short) ~sum; |
} |
} |
|
|
|
/* |
|
* crcFletcher() Fletcher-16 Checksum computing |
|
* @nBuf = Data for calculation |
|
* @bufLen = Length of data |
|
* return: -1 error, !=-1 Checksum |
|
*/ |
inline u_long crcFletcher(u_short * __restrict nBuf, int bufLen) |
inline u_long crcFletcher(u_short * __restrict nBuf, int bufLen) |
{ |
{ |
register u_long s1, s2, clen; |
register u_long s1, s2, clen; |
Line 200 inline u_long crcFletcher(u_short * __restrict nBuf, i
|
Line 248 inline u_long crcFletcher(u_short * __restrict nBuf, i
|
return (s2 << 16) | s1; |
return (s2 << 16) | s1; |
} |
} |
|
|
|
/* |
|
* crcAdler() crcAdler-32 Checksum computing |
|
* @psBuf = Data for calculation |
|
* @bufLen = Length of data |
|
* return: -1 error, !=-1 Checksum |
|
*/ |
inline u_long crcAdler(u_char * __restrict psBuf, int bufLen) |
inline u_long crcAdler(u_char * __restrict psBuf, int bufLen) |
{ |
{ |
register u_long s1, s2, clen; |
register u_long s1, s2, clen; |