forked from bigmacd/trapreceiver
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRawTrapData.cpp
More file actions
91 lines (76 loc) · 1.99 KB
/
RawTrapData.cpp
File metadata and controls
91 lines (76 loc) · 1.99 KB
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
#include "stdafx.h"
#include "traprcvr.h"
#include "RawTrapData.h"
#define BYTESPER 17
RawTrapData::RawTrapData(CWnd* pParent /*=NULL*/)
:CDialog(RawTrapData::IDD, pParent)
{
//{{AFX_DATA_INIT(RawTrapData)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
RawTrapData::RawTrapData(Packet* p)
:CDialog(RawTrapData::IDD, NULL),
mPacket(p)
{
}
void RawTrapData::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(RawTrapData)
DDX_Control(pDX, IDC_LIST1, mList);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(RawTrapData, CDialog)
//{{AFX_MSG_MAP(RawTrapData)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
BOOL
RawTrapData::OnInitDialog()
{
CDialog::OnInitDialog();
if (mPacket != NULL)
{
unsigned int l = mPacket->TotalLength();
unsigned char* c = new unsigned char[l];
mPacket->Build(c);
CString lineMsg;
char line[128];
unsigned int x = 0;
for (x = 0; x < l; x++)
{
memset(line, 0, 128);
if (x && ((x % BYTESPER) == 0))
{
lineMsg += " "; // printf(" ");
unsigned int y = (x - BYTESPER);
for (; y < x; y++)
// printf("%c", isprint(c[y]) ? c[y] : '.');
lineMsg += (char)(isprint(c[y]) ? c[y] : '.');
mList.AddString(lineMsg.GetBuffer(0));
lineMsg.ReleaseBuffer();
lineMsg.Empty();
// printf("\r\n");
}
sprintf_s(line, "%02x ", c[x]);
lineMsg += line;
// printf("%02x ", c[x]);
}
// ascii out the last charaters
lineMsg.Empty();
int bytesLeft = x % BYTESPER;
int spacesNeeded = ((BYTESPER - bytesLeft) * 3) + 2;
for (int z = 0; z < spacesNeeded; z++)
lineMsg += " "; // printf(" ");
unsigned int y = x - bytesLeft;
for (; y < x; y++)
// printf("%c", isprint(c[y]) ? c[y] : '.');
lineMsg += (char)isprint((c[y]) ? c[y] : '.');
// printf("\r\n\r\n");
mList.AddString(lineMsg.GetBuffer(0));
delete [] c;
}
else
mList.AddString("No Trap Data");
return TRUE;
}