-
Notifications
You must be signed in to change notification settings - Fork 0
/
Scalar64Varbind.cpp
105 lines (88 loc) · 2.08 KB
/
Scalar64Varbind.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#ifndef __SCALAR64VARBIND_H__
# include "Scalar64Varbind.h"
#endif
#if _WIN32
# include <windows.h>
#else
# include <stdlib.h>
# include <string.h>
# include <stdio.h>
#endif
Scalar64Varbind::Scalar64Varbind(unsigned short type, const char* typeString)
:Varbind(type, typeString),
mValue(0)
{
}
Scalar64Varbind::Scalar64Varbind(unsigned char* &pduPart,
unsigned short type,
const char* typeString)
:Varbind(pduPart, type, typeString),
mValue(0)
{
}
Scalar64Varbind::Scalar64Varbind()
{
}
unsigned char*
Scalar64Varbind::Data()
{
unsigned char* data = new unsigned char [DataLength() + 2];
unsigned char* retVal = data;
Build(data);
return retVal;
}
const char*
Scalar64Varbind::Printable()
{
if (mPrintable == NULL)
{
int size = DataLength() * 10 + 10;
mPrintable = new char[size];
memset(mPrintable, 0, size);
#ifdef _WIN32
sprintf_s(mPrintable, size, "%I64lu", mValue);
#else
sprintf(mPrintable, "%I64lu", mValue);
#endif
}
return mPrintable;
}
void
Scalar64Varbind::Build(unsigned char*& pdu)
{
encodeLength(pdu, DataLength());
int shiftsize = 8 * (DataLength() - 1);
for (unsigned int i = 0; i < DataLength(); i++, shiftsize -= 8)
{
*pdu++ = (unsigned char)((mValue >> shiftsize) & 0x00000000000000ff);
}
}
void
Scalar64Varbind::Value(__int64 value)
{
mValue = value;
if (value == 0)
DataLength(1);
else
{
int intsize = sizeof(__int64);
//#if !defined(_LINUX) || !defined(_SOLARIS)
//#ifndef _SOLARIS
// __int64 mask = 0xff80000000000000;// >> ((8 * (sizeof(unsigned int) - 1)) - 1);
//#else
__int64 mask = 0xff800000;
mask <<= 16;
//#endif
__int64 valueIn = value;
while((((valueIn & mask) == 0) || ((valueIn & mask) == mask))
&& intsize > 1)
{
intsize--;
valueIn <<= 8;
}
// for (int x = 0; x < loopCount; x++)
// value >>= 8;
mValue = value;
DataLength(intsize);
}
}