-
Notifications
You must be signed in to change notification settings - Fork 0
/
UsefulInfo.cpp
115 lines (99 loc) · 2.33 KB
/
UsefulInfo.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
106
107
108
109
110
111
112
113
114
115
/*
* UsefulInfo.cpp
*
* Created on: May 8, 2019
* Author: vittorio
*/
#include "UsefulInfo.h"
UsefulInfo::UsefulInfo() {
// TODO Auto-generated constructor stub
}
std::shared_ptr<std::vector<uint8_t>> UsefulInfo::bufferize()
{
int i;
uint8_t *ptr;
uint64_t temp64;
uint8_t temp8;
uint32_t temp32;
std::shared_ptr<std::vector<uint8_t>> buf= std::make_shared<std::vector<uint8_t>> ();
temp64=UsefulInfo::htonll(this->hash);
ptr=(uint8_t*) &temp64;
buf->push_back(ptr[0]);
buf->push_back(ptr[1]);
buf->push_back(ptr[2]);
buf->push_back(ptr[3]);
buf->push_back(ptr[4]);
buf->push_back(ptr[5]);
buf->push_back(ptr[6]);
buf->push_back(ptr[7]);
temp64=UsefulInfo::htonll(this->srcAddr);
ptr=(uint8_t*) &temp64;
buf->push_back(ptr[0]);
buf->push_back(ptr[1]);
buf->push_back(ptr[2]);
buf->push_back(ptr[3]);
buf->push_back(ptr[4]);
buf->push_back(ptr[5]);
buf->push_back(ptr[6]);
buf->push_back(ptr[7]);
/*temp64=UsefulInfo::htonll(this->dstAddr);
ptr=(uint8_t*) &temp64;
buf->push_back(ptr[0]);
buf->push_back(ptr[1]);
buf->push_back(ptr[2]);
buf->push_back(ptr[3]);
buf->push_back(ptr[4]);
buf->push_back(ptr[5]);
buf->push_back(ptr[6]);
buf->push_back(ptr[7]);*/
/*temp64=UsefulInfo::htonll(this->bssid);
ptr=(uint8_t*) &temp64;
buf->push_back(ptr[0]);
buf->push_back(ptr[1]);
buf->push_back(ptr[2]);
buf->push_back(ptr[3]);
buf->push_back(ptr[4]);
buf->push_back(ptr[5]);
buf->push_back(ptr[6]);
buf->push_back(ptr[7]);*/
/*ptr=(uint8_t*) this->type;
buf->push_back(ptr[0]);
buf->push_back(ptr[1]);
buf->push_back(ptr[2]);
buf->push_back(ptr[3]);
buf->push_back(ptr[4]);
buf->push_back(ptr[5]);
buf->push_back('\0');*/
temp8=this->intensity;
ptr=(uint8_t*) &temp8;
buf->push_back(ptr[0]);
temp32=htonl(this->time);
ptr=(uint8_t*) &temp32;
buf->push_back(ptr[0]);
buf->push_back(ptr[1]);
buf->push_back(ptr[2]);
buf->push_back(ptr[3]);
temp8=strlen(this->ssid);
ptr=(uint8_t*) &temp8;
buf->push_back(ptr[0]);
ptr=(uint8_t*) this->ssid;
for (i=0; i<strlen(this->ssid); i++)
{
buf->push_back(ptr[i]);
}
//buf->push_back('\0');
return buf;
}
uint64_t UsefulInfo::htonll(uint64_t n)
{
static const int num = 42;
// Check the endianness
if (*(char *)&num == 42)
{
return (((uint64_t)htonl(n)) << 32) + htonl(n >> 32);
}
else
{
return n;
}
}