-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpacket.cpp
65 lines (51 loc) · 1.43 KB
/
packet.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
#include "packet.h"
packet::packet(Tins::PDU *pdu_ptr, int id)
{
this->pdu = pdu_ptr->clone();
this->hex_content = NULL;
this->id = id;
unsigned int length = pdu_ptr->size();
}
void string_parse(char* &parsed_content, char* content, int size)
{
parsed_content = (char*)malloc(sizeof(char)*size);
if(!parsed_content)
{
printf("malloc failed\n");
return;
}
memcpy(parsed_content ,content, size);
for(int i = 0; i < size; i++)
{
if(parsed_content[i]<0x20 || parsed_content[i]>0x7e)
parsed_content[i]='.';
}
}
//char* format_content(int is_hex = 1)
//{
// char *fm_ptr = (char*)malloc(sizeof(char)*size*(is_hex+2));
// char* dest = 0, *src;
// if(!is_hex) goto nohex;
// for(int i = 0; i < size; i += PACKET_LINE_W)
// {
// for(int j = 0; j < PACKET_LINE_W; j++)
// {
// dest = fm_ptr + (PACKET_LINE_W+1) * i + j;
// src = content + (PACKET_LINE_W+1) * i + j;
// sprintf(dest, "%2x", *src);
// }
// sprintf(dest+1,"\n");
// }
//nohex:
// for(int i = 0; i < size; i += PACKET_LINE_W)
// {
// for(int j = 0; j < PACKET_LINE_W; j++)
// {
// dest = fm_ptr + (PACKET_LINE_W+1) * i + j;
// src = content + (PACKET_LINE_W+1) * i + j;
// sprintf(dest, "%c", *src);
// }
// sprintf(dest+1,"\n");
// }
// return fm_ptr;
//}