xrootd
XrdCksCalccrc32.hh
Go to the documentation of this file.
1 #ifndef __XRDCKSCALCCRC32_HH__
2 #define __XRDCKSCALCCRC32_HH__
3 /******************************************************************************/
4 /* */
5 /* X r d C k s C a l c c r c 3 2 . h h */
6 /* */
7 /* (c) 2011 by the Board of Trustees of the Leland Stanford, Jr., University */
8 /* All Rights Reserved */
9 /* Produced by Andrew Hanushevsky for Stanford University under contract */
10 /* DE-AC02-76-SFO0515 with the Department of Energy */
11 /******************************************************************************/
12 
13 #include <string.h>
14 #include <sys/types.h>
15 #include <netinet/in.h>
16 #include <inttypes.h>
17 
18 #include "XrdCks/XrdCksCalc.hh"
19 #include "XrdSys/XrdSysPlatform.hh"
20 
22 {
23 public:
24 
25 char *Final() {char buff[sizeof(long long)];
26  long long tLcs = TotLen;
27  int i = 0;
28  if (tLcs)
29  {while(tLcs) {buff[i++] = tLcs & 0xff ; tLcs >>= 8;}
30  Update(buff, i);
31  }
33 #ifndef Xrd_Big_Endian
34  TheResult = htonl(TheResult);
35 #endif
36  return (char *)&TheResult;
37  }
38 
39 void Init() {C32Result = CRC32_XINIT; TotLen = 0;}
40 
42 
43 void Update(const char *Buff, int BLen);
44 
45 const char *Type(int &csSz) {csSz = sizeof(TheResult); return "crc32";}
46 
48 virtual ~XrdCksCalccrc32() {}
49 
50 private:
51 static const unsigned int CRC32_XINIT = 0;
52 static const unsigned int CRC32_XOROT = 0xffffffff;
53 static unsigned int crctable[256];
54  unsigned int C32Result;
55  unsigned int TheResult;
56  long long TotLen;
57 };
58 #endif