Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
jedi
smrtlink
Commits
e077b4ca
Commit
e077b4ca
authored
Oct 06, 2015
by
/jdi/
Browse files
minor improvements
parent
30ebdde2
Changes
14
Hide whitespace changes
Inline
Side-by-side
Makefile
View file @
e077b4ca
CC
=
g++
CFLAGS
=
-g
-Wall
-std
=
c++11
CFLAGS
=
-Wall
-std
=
c++11
TARGET
=
smrtlink
all
:
$(TARGET)
$(TARGET)
:
src/*.cpp
$(CC)
$(CFLAGS)
-o
$(TARGET)
src/
*
.cpp src/
*
.h
$(TARGET)
:
Types.o Program.o
$(CC)
$(CFLAGS)
-o
$(TARGET)
*
.o
Types.o
:
src/Types/*.cpp src/Types*.h
$(CC)
$(CFLAGS)
-c
src/Types/
*
.cpp
Program.o
:
src/*.cpp src/*.h
$(CC)
$(CFLAGS)
-c
src/
*
.cpp
clean
:
rm
src/
$(TARGET)
.g
rm
*
.o
src/Host.cpp
View file @
e077b4ca
...
...
@@ -5,8 +5,10 @@
* Author: jdi
*/
//TODO clean up
#include
<cstdio>
#include
<cerrno>
//
#include <cerrno>
#include
<cstring>
#include
<cstdlib>
#include
<iostream>
...
...
@@ -16,25 +18,21 @@
#include
<netdb.h>
#include
<ifaddrs.h>
#include
<unistd.h>
#include
<linux/if_link.h>
#include
"
Util
s.h"
//
#include <linux/if_link.h>
#include
"
Option
s.h"
#include
"Host.h"
Host
::
Host
()
{
// TODO Auto-generated constructor stub
}
#include
"Types.h"
#include
"Types/bytes.h"
macAddr
Host
::
getMac
()
{
macAddr
ret
{
{
0x08
,
0x3e
,
0x8e
,
0x16
,
0x17
,
0x2c
}
};
//TODO find actual MAC Address
macAddr
ret
{
0x08
,
0x3e
,
0x8e
,
0x16
,
0x17
,
0x2c
};
//TODO find actual MAC Address
return
ret
;
}
i
net
Addr
Host
::
getIp
(
std
::
string
iface
)
{
i
p
Addr
Host
::
getIp
()
{
struct
ifaddrs
*
ifaddr
,
*
ifa
;
int
n
;
i
net
Addr
data
{
{
0
,
0
,
0
,
0
}
};
i
p
Addr
data
{
0
,
0
,
0
,
0
};
if
(
getifaddrs
(
&
ifaddr
)
==
-
1
)
{
perror
(
"getifaddrs"
);
...
...
@@ -46,7 +44,7 @@ inetAddr Host::getIp(std::string iface) {
continue
;
if
(
ifa
->
ifa_addr
->
sa_family
==
AF_INET
)
{
if
(
i
face
.
compare
(
ifa
->
ifa_name
)
==
0
)
{
if
(
options
.
inter
face
.
compare
(
ifa
->
ifa_name
)
==
0
)
{
memcpy
(
&
data
[
0
],
&
ifa
->
ifa_addr
->
sa_data
[
2
],
4
);
return
data
;
}
...
...
@@ -54,7 +52,6 @@ inetAddr Host::getIp(std::string iface) {
}
freeifaddrs
(
ifaddr
);
return
data
;
}
src/Host.h
View file @
e077b4ca
...
...
@@ -12,9 +12,9 @@
class
Host
{
public:
Host
();
Host
()
{}
;
macAddr
getMac
();
i
net
Addr
getIp
(
std
::
string
);
i
p
Addr
getIp
();
};
#endif
/* HOST_H_ */
src/Packet.cpp
View file @
e077b4ca
...
...
@@ -11,7 +11,8 @@
#include
<ctime>
#include
"Packet.h"
#include
"Types.h"
#include
"Utils.h"
#include
"Types/bytes.h"
#include
"Types/datasets.h"
Packet
::
Packet
(
OpCode
c
)
{
srand
(
time
(
NULL
));
...
...
@@ -23,9 +24,8 @@ void Packet::printHeader() {
printf
(
"Header:
\n\t
OpCode:
\t\t
%s
\n\t
ID:
\t\t
%d
\n\t
Version:
\t
%hhd
\n\t
Error:
\t\t
%.8X
\n\t
Switch MAC:
\t
"
,
opCodeToString
().
c_str
(),
sequenceId
,
version
,
errorCode
);
utils
::
print
(
switchMac
);
printf
(
"
\n\t
Host MAC:
\t
"
);
utils
::
print
(
hostMac
);
std
::
cout
<<
switchMac
<<
"
\n
"
;
std
::
cout
<<
"
\t
Host MAC:
\t
"
<<
hostMac
<<
"
\n
"
;
printf
(
"
\n\t
Length:
\t
%hd"
,
this
->
getLength
());
printf
(
"
\n\t
Offset:
\t
%hd"
,
fragmentOffset
);
printf
(
"
\n\t
Flags:
\t
%.4hX"
,
flag
);
...
...
@@ -161,32 +161,31 @@ std::string Packet::opCodeToString() {
void
Packet
::
encode
(
bytes
&
data
)
{
int
len
=
data
.
size
();
bytes
key
=
{
191
,
155
,
227
,
202
,
99
,
162
,
79
,
104
,
49
,
18
,
190
,
164
,
30
,
76
,
189
,
131
,
23
,
52
,
86
,
106
,
207
,
125
,
126
,
169
,
196
,
28
,
172
,
58
,
188
,
132
,
160
,
3
,
36
,
120
,
144
,
168
,
12
,
231
,
116
,
44
,
41
,
97
,
108
,
213
,
42
,
198
,
32
,
148
,
218
,
107
,
247
,
112
,
204
,
14
,
66
,
68
,
91
,
224
,
206
,
235
,
33
,
130
,
203
,
178
,
1
,
134
,
199
,
78
,
249
,
123
,
7
,
145
,
73
,
208
,
209
,
100
,
74
,
115
,
72
,
118
,
8
,
22
,
243
,
147
,
64
,
96
,
5
,
87
,
60
,
113
,
233
,
152
,
31
,
219
,
143
,
174
,
232
,
153
,
245
,
158
,
254
,
70
,
170
,
75
,
77
,
215
,
211
,
59
,
71
,
133
,
214
,
157
,
151
,
6
,
46
,
81
,
94
,
136
,
166
,
210
,
4
,
43
,
241
,
29
,
223
,
176
,
67
,
63
,
186
,
137
,
129
,
40
,
248
,
255
,
55
,
15
,
62
,
183
,
222
,
105
,
236
,
197
,
127
,
54
,
179
,
194
,
229
,
185
,
37
,
90
,
237
,
184
,
25
,
156
,
173
,
26
,
187
,
220
,
2
,
225
,
0
,
240
,
50
,
251
,
212
,
253
,
167
,
17
,
193
,
205
,
177
,
21
,
181
,
246
,
82
,
226
,
38
,
101
,
163
,
182
,
242
,
92
,
20
,
11
,
95
,
13
,
230
,
16
,
121
,
124
,
109
,
195
,
117
,
39
,
98
,
239
,
84
,
56
,
139
,
161
,
47
,
201
,
51
,
135
,
250
,
10
,
19
,
150
,
45
,
111
,
27
,
24
,
142
,
80
,
85
,
83
,
234
,
138
,
216
,
57
,
93
,
65
,
154
,
141
,
122
,
34
,
140
,
128
,
238
,
88
,
89
,
9
,
146
,
171
,
149
,
53
,
102
,
61
,
114
,
69
,
217
,
175
,
103
,
228
,
35
,
180
,
252
,
200
,
192
,
165
,
159
,
221
,
244
,
110
,
119
,
48
};
std
::
vector
<
unsigned
char
>
t
=
{
191
,
155
,
227
,
202
,
99
,
162
,
79
,
104
,
49
,
18
,
190
,
164
,
30
,
76
,
189
,
131
,
23
,
52
,
86
,
106
,
207
,
125
,
126
,
169
,
196
,
28
,
172
,
58
,
188
,
132
,
160
,
3
,
36
,
120
,
144
,
168
,
12
,
231
,
116
,
44
,
41
,
97
,
108
,
213
,
42
,
198
,
32
,
148
,
218
,
107
,
247
,
112
,
204
,
14
,
66
,
68
,
91
,
224
,
206
,
235
,
33
,
130
,
203
,
178
,
1
,
134
,
199
,
78
,
249
,
123
,
7
,
145
,
73
,
208
,
209
,
100
,
74
,
115
,
72
,
118
,
8
,
22
,
243
,
147
,
64
,
96
,
5
,
87
,
60
,
113
,
233
,
152
,
31
,
219
,
143
,
174
,
232
,
153
,
245
,
158
,
254
,
70
,
170
,
75
,
77
,
215
,
211
,
59
,
71
,
133
,
214
,
157
,
151
,
6
,
46
,
81
,
94
,
136
,
166
,
210
,
4
,
43
,
241
,
29
,
223
,
176
,
67
,
63
,
186
,
137
,
129
,
40
,
248
,
255
,
55
,
15
,
62
,
183
,
222
,
105
,
236
,
197
,
127
,
54
,
179
,
194
,
229
,
185
,
37
,
90
,
237
,
184
,
25
,
156
,
173
,
26
,
187
,
220
,
2
,
225
,
0
,
240
,
50
,
251
,
212
,
253
,
167
,
17
,
193
,
205
,
177
,
21
,
181
,
246
,
82
,
226
,
38
,
101
,
163
,
182
,
242
,
92
,
20
,
11
,
95
,
13
,
230
,
16
,
121
,
124
,
109
,
195
,
117
,
39
,
98
,
239
,
84
,
56
,
139
,
161
,
47
,
201
,
51
,
135
,
250
,
10
,
19
,
150
,
45
,
111
,
27
,
24
,
142
,
80
,
85
,
83
,
234
,
138
,
216
,
57
,
93
,
65
,
154
,
141
,
122
,
34
,
140
,
128
,
238
,
88
,
89
,
9
,
146
,
171
,
149
,
53
,
102
,
61
,
114
,
69
,
217
,
175
,
103
,
228
,
35
,
180
,
252
,
200
,
192
,
165
,
159
,
221
,
244
,
110
,
119
,
48
};
bytes
key
=
t
;
bytes
s
=
key
;
int
i
,
t
,
j
=
0
;
int
i
,
j
=
0
;
for
(
int
k
=
0
;
k
<
len
;
k
++
)
{
i
=
(
k
+
1
)
%
256
;
j
=
(
j
+
s
[
i
])
%
256
;
t
=
s
[
i
];
s
[
i
]
=
s
[
j
];
s
[
j
]
=
t
;
std
::
swap
(
s
[
i
],
s
[
j
]);
data
[
k
]
=
data
[
k
]
^
s
[(
s
[
i
]
+
s
[
j
])
%
256
];
}
}
...
...
@@ -205,14 +204,14 @@ void Packet::push(bytes &arr, int &index, bytes data) {
push
(
arr
,
index
,
data
[
j
]);
}
void
Packet
::
push
(
bytes
&
arr
,
int
&
index
,
i
net
Addr
&
data
)
{
void
Packet
::
push
(
bytes
&
arr
,
int
&
index
,
i
p
Addr
data
)
{
for
(
unsigned
j
=
0
;
j
<
4
;
j
++
)
push
(
arr
,
index
,
data
[
j
]);
push
(
arr
,
index
,
(
byte
)
data
[
j
]);
}
void
Packet
::
push
(
bytes
&
arr
,
int
&
index
,
macAddr
&
data
)
{
void
Packet
::
push
(
bytes
&
arr
,
int
&
index
,
macAddr
data
)
{
for
(
unsigned
j
=
0
;
j
<
6
;
j
++
)
push
(
arr
,
index
,
data
[
j
]);
push
(
arr
,
index
,
(
byte
)
data
[
j
]);
}
void
Packet
::
push
(
bytes
&
arr
,
int
&
index
,
short
data
)
{
...
...
@@ -254,7 +253,7 @@ void Packet::pull(bytes &arr, int &index, macAddr &ret) {
index
+=
6
;
}
void
Packet
::
pull
(
bytes
&
arr
,
int
&
index
,
i
net
Addr
&
ret
)
{
void
Packet
::
pull
(
bytes
&
arr
,
int
&
index
,
i
p
Addr
&
ret
)
{
memcpy
(
&
ret
[
0
],
&
arr
[
index
],
4
);
index
+=
4
;
}
...
...
src/Packet.h
View file @
e077b4ca
...
...
@@ -12,6 +12,8 @@
#define PACKET_END 0xFFFF0000
#include
"Types.h"
#include
"Types/bytes.h"
#include
"Types/datasets.h"
class
Packet
{
public:
...
...
@@ -19,8 +21,6 @@ public:
DISCOVERY
,
GET
,
SET
,
READ
};
Packet
(
OpCode
);
virtual
~
Packet
()
{
}
void
encode
(
bytes
&
);
bytes
getBytes
();
void
parse
(
bytes
);
...
...
@@ -64,15 +64,15 @@ private:
void
push
(
bytes
&
,
int
&
,
int
);
void
push
(
bytes
&
,
int
&
,
byte
);
void
push
(
bytes
&
,
int
&
,
bytes
);
void
push
(
bytes
&
,
int
&
,
i
net
Addr
&
);
void
push
(
bytes
&
,
int
&
,
macAddr
&
);
void
push
(
bytes
&
,
int
&
,
i
p
Addr
);
void
push
(
bytes
&
,
int
&
,
macAddr
);
void
push
(
bytes
&
,
int
&
,
dataset
);
void
pull
(
bytes
&
,
int
&
,
short
&
);
void
pull
(
bytes
&
,
int
&
,
int
&
);
void
pull
(
bytes
&
,
int
&
,
byte
&
);
void
pull
(
bytes
&
,
int
&
,
bytes
&
,
unsigned
);
void
pull
(
bytes
&
,
int
&
,
i
net
Addr
&
);
void
pull
(
bytes
&
,
int
&
,
i
p
Addr
&
);
void
pull
(
bytes
&
,
int
&
,
macAddr
&
);
void
pull
(
bytes
&
,
int
&
,
dataset
&
);
};
...
...
src/Program.cpp
View file @
e077b4ca
...
...
@@ -7,17 +7,13 @@
#include
<cstdio>
#include
<algorithm>
#include
"Utils.h"
#include
"Options.h"
#include
"Program.h"
#include
"Host.h"
#include
"Socket.h"
#include
"Switch.h"
#include
"Packet.h"
Program
::
Program
()
{
// TODO Auto-generated constructor stub
}
int
Program
::
list
()
{
//Device d = Device();
...
...
@@ -34,27 +30,21 @@ int Program::list() {
try
{
asio
::
io_service
io_service
;
Socket
s
(
io_service
);
s
.
setHostIp
(
h
.
getIp
(
options
.
interface
));
s
.
setHostIp
(
h
.
getIp
());
s
.
init
(
DST_PORT
,
SRC_PORT
);
s
.
callback
=
[](
Packet
a
)
{
if
(
options
.
flags
&
FLAG_HEADER
)
{
printf
(
"Received Header:
\t
"
);
utils
::
printHex
(
a
.
getHead
());
printf
(
"
\n
"
);
std
::
cout
<<
"Received Header:
\t
"
<<
a
.
getHead
()
<<
"
\n
"
;
}
if
(
options
.
flags
&
FLAG_HEX
)
{
printf
(
"Received Payload:
\t
"
);
utils
::
printHex
(
a
.
getBody
());
printf
(
"
\n
"
);
std
::
cout
<<
"Received Payload:
\t
"
<<
a
.
getBody
()
<<
"
\n
"
;
}
datasets
d
=
a
.
getPayload
();
printf
(
"
\t
%s (%s)
\t
MAC: "
,
&
d
[
2
].
value
[
0
],
&
d
[
1
].
value
[
0
]);
utils
::
printHex
(
d
[
3
].
value
);
printf
(
"
\t
IP: "
);
utils
::
printDec
(
d
[
4
].
value
);
printf
(
"
\n
"
);
return
1
;
};
std
::
cout
<<
"
\t
"
<<
d
[
2
].
value
<<
"("
<<
d
[
1
].
value
<<
")
\t
MAC: "
<<
d
[
3
].
value
<<
"
\t
IP: "
<<
d
[
4
].
value
<<
"
\n
"
;
Switch
s
=
Switch
();
std
::
cout
<<
"
\t
"
<<
s
.
settings
.
hostname
<<
"("
<<
s
.
device
.
type
<<
")
\t
MAC: "
<<
s
.
device
.
mac
<<
"
\t
IP: "
<<
s
.
settings
.
ip_addr
<<
"
\n
"
;
return
1
;
};
s
.
send
(
a
);
io_service
.
run
();
}
catch
(
std
::
exception
&
e
)
{
...
...
@@ -70,29 +60,26 @@ int Program::sniff() {
asio
::
io_service
io_service
;
Host
h
=
Host
();
Socket
s
(
io_service
);
s
.
setHostIp
(
h
.
getIp
(
options
.
interface
));
s
.
setHostIp
(
h
.
getIp
());
s
.
init
(
DST_PORT
,
SRC_PORT
);
s
.
callback
=
[](
Packet
p
)
{
if
(
options
.
flags
&
FLAG_HEADER
)
{
if
(
options
.
flags
&
FLAG_HEX
)
{
printf
(
"Received Header:
\t
"
);
utils
::
printHex
(
p
.
getHead
());
std
::
cout
<<
"Received Header:
\t
"
<<
p
.
getHead
()
<<
"
\n
"
;
}
else
{
p
.
printHeader
();
printf
(
"
\n
"
);
}
printf
(
"
\n
"
);
}
if
(
options
.
flags
&
FLAG_HEX
)
{
printf
(
"Received Payload:
\t
"
);
utils
::
printHex
(
p
.
getBody
());
printf
(
"
\n
"
);
std
::
cout
<<
"Received Payload:
\t
"
<<
p
.
getBody
()
<<
"
\n
"
;
}
for
(
auto
a
:
p
.
getPayload
())
{
dataset
d
=
a
.
second
;
printf
(
"#%d
\t
Length: %d
\n\t
Hex: "
,
d
.
type
,
d
.
len
);
utils
::
printHex
(
d
.
value
)
;
std
::
cout
<<
d
.
value
;
printf
(
"
\n\t
Dec: "
);
utils
::
printDec
(
d
.
value
)
;
std
::
cout
<<
d
.
value
;
d
.
value
.
push_back
(
0U
);
printf
(
"
\n\t
String: %s
\n
"
,
&
d
.
value
[
0
]);
}
...
...
@@ -108,7 +95,7 @@ int Program::sniff() {
}
int
Program
::
encode
(
std
::
string
s
)
{
bytes
d
=
utils
::
readHex
(
s
);
bytes
d
(
s
);
Packet
p
=
Packet
(
Packet
::
DISCOVERY
);
p
.
encode
(
d
);
printf
(
"%x"
,
d
[
0
]);
...
...
@@ -119,31 +106,30 @@ int Program::encode(std::string s) {
return
0
;
}
int
Program
::
setProperty
(){
int
Program
::
setProperty
()
{
return
0
;
}
int
Program
::
getProperty
(){
int
Program
::
getProperty
()
{
return
0
;
}
int
Program
::
save
(){
int
Program
::
save
()
{
//File = fopen(otions.file)
return
0
;
}
int
Program
::
restore
(){
int
Program
::
restore
()
{
//File = fopen(otions.file)
return
0
;
}
int
Program
::
flash
(){
int
Program
::
flash
()
{
return
0
;
}
int
Program
::
reboot
(){
int
Program
::
reboot
()
{
return
0
;
}
int
Program
::
reset
(){
int
Program
::
reset
()
{
return
0
;
}
src/Program.h
View file @
e077b4ca
...
...
@@ -15,9 +15,7 @@
class
Program
{
public:
Program
();
virtual
~
Program
()
{
}
Program
(){}
int
list
();
int
sniff
();
int
encode
(
std
::
string
);
...
...
src/Socket.cpp
View file @
e077b4ca
...
...
@@ -14,7 +14,6 @@
#include
"Socket.h"
#include
"Packet.h"
#include
"Types.h"
#include
"Utils.h"
#include
"Options.h"
#include
"Host.h"
...
...
@@ -30,9 +29,7 @@ void Socket::init(short dst_port, short src_port) {
src_port
=
p
;
}
printf
(
"IP:
\t
"
);
utils
::
print
(
local_ip
);
printf
(
"
\n
"
);
std
::
cout
<<
"IP:
\t
"
<<
local_ip
<<
"
\n
"
;
wildcard_endpoint_
=
asio
::
ip
::
udp
::
endpoint
(
asio
::
ip
::
address_v4
::
from_string
(
"0.0.0.0"
),
src_port
);
...
...
@@ -44,16 +41,16 @@ void Socket::init(short dst_port, short src_port) {
send_socket_
.
open
(
asio
::
ip
::
udp
::
v4
());
send_socket_
.
set_option
(
asio
::
socket_base
::
broadcast
(
true
));
send_socket_
.
set_option
(
asio
::
socket_base
::
reuse_address
(
true
));
send_socket_
.
bind
(
local_endpoint_
);
//TODO reuse Address
send_socket_
.
bind
(
local_endpoint_
);
receive_socket_
.
open
(
asio
::
ip
::
udp
::
v4
());
receive_socket_
.
set_option
(
asio
::
socket_base
::
broadcast
(
true
));
receive_socket_
.
set_option
(
asio
::
socket_base
::
reuse_address
(
true
));
receive_socket_
.
bind
(
wildcard_endpoint_
);
//TODO reuse Address
receive_socket_
.
bind
(
wildcard_endpoint_
);
}
void
Socket
::
setHostIp
(
i
net
Addr
ip
)
{
void
Socket
::
setHostIp
(
i
p
Addr
ip
)
{
local_ip
=
ip
;
}
...
...
src/Socket.h
View file @
e077b4ca
...
...
@@ -11,6 +11,7 @@
#include
<asio.hpp>
#include
"Packet.h"
#include
"Types.h"
//#include "Types.h"
#define MAX_LENGTH 1024
...
...
@@ -22,7 +23,7 @@ public:
void
init
(
short
,
short
);
void
send
(
bytes
);
void
listen
();
void
setHostIp
(
i
net
Addr
);
void
setHostIp
(
i
p
Addr
);
int
(
*
callback
)(
Packet
)
=
[](
Packet
a
)
{
return
0
;
};
...
...
@@ -36,7 +37,7 @@ private:
asio
::
ip
::
udp
::
endpoint
wildcard_endpoint_
;
asio
::
ip
::
udp
::
endpoint
local_endpoint_
;
bytes
data
=
bytes
(
MAX_LENGTH
);
i
net
Addr
local_ip
;
i
p
Addr
local_ip
;
};
...
...
src/Switch.cpp
View file @
e077b4ca
...
...
@@ -7,8 +7,7 @@
#include
"Switch.h"
Switch
::
Switch
()
{
// TODO Auto-generated constructor stub
void
Switch
::
parse
(
datasets
arr
){
}
src/Switch.h
View file @
e077b4ca
...
...
@@ -10,6 +10,8 @@
#include
<string>
#include
"Types.h"
#include
"Types/bytes.h"
#include
"Types/datasets.h"
#define DEFAULT_USER "admin"
#define DEFAULT_PASS "admin"
...
...
@@ -20,7 +22,8 @@ struct vlan {
};
struct
port
{
int
id
;
byte
id
;
byte
status
;
struct
{
std
::
vector
<
vlan
*>
tagged
;
std
::
vector
<
vlan
*>
untagged
;
...
...
@@ -30,26 +33,25 @@ struct port {
class
Switch
{
public:
Switch
();
Switch
()
{
}
void
parse
(
datasets
);
private:
struct
{
std
::
string
type
;
std
::
string
hardware_version
;
std
::
string
firmware_version
;
macAddr
mac
;
macAddr
mac
{
0x0
,
0x0
,
0x0
,
0x0
,
0x0
,
0x0
}
;
}
device
;
struct
{
std
::
string
password
=
DEFAULT_PASS
;
std
::
string
username
=
DEFAULT_USER
;
struct
{
std
::
string
hostname
;
inetAddr
ip_addr
;
inetAddr
ip_mask
;
inetAddr
gateway
;
byte
dhcp
;
}
network
;
std
::
string
hostname
;
ipAddr
ip_addr
{
0
,
0
,
0
,
0
,};
ipAddr
ip_mask
;
ipAddr
gateway
;
byte
dhcp
;
}
settings
;
private:
std
::
vector
<
vlan
>
vlans
;
std
::
vector
<
port
>
ports
;
};
...
...
src/Types.h
View file @
e077b4ca
...
...
@@ -8,10 +8,62 @@
#ifndef TYPES_H_
#define TYPES_H_
#include
<functional>
#include
<initializer_list>
#include
<algorithm>
#include
<iostream>
#include
<iomanip>
#include
<vector>
#include
<array>
#include
<map>
#include
"Types/bytes.h"
class
macAddr
:
public
std
::
array
<
byte
,
6
>
{
public:
friend
std
::
ostream
&
operator
<<
(
std
::
ostream
&
out
,
const
macAddr
&
arr
)
{
out
<<
std
::
hex
<<
std
::
setw
(
2
)
<<
std
::
setfill
(
'0'
)
<<
(
unsigned
)
arr
[
0
];
for
(
unsigned
i
=
1
;
i
<
6
;
i
++
)
{
out
<<
":"
<<
std
::
setw
(
2
)
<<
std
::
setfill
(
'0'
)
<<
(
unsigned
)
arr
[
i
];
}
return
out
;
}
macAddr
()
{
*
this
=
{
0
,
0
,
0
,
0
,
0
,
0
};
}
macAddr
(
std
::
initializer_list
<
byte
>
s
)
{
int
i
=
0
;
for
(
byte
b
:
s
)
{
if
(
i
<
6
)
(
*
this
)[
i
++
]
=
b
;
else
break
;
}
}
};
class
ipAddr
:
public
std
::
array
<
byte
,
4
>
{
public:
ipAddr
()
{
*
this
=
{
0
,
0
,
0
,
0
,
0
,
0
};
}
ipAddr
(
std
::
initializer_list
<
byte
>
s
)
{
int
i
=
0
;
for
(
byte
b
:
s
)
{
if
(
i
<
4
)
(
*
this
)[
i
++
]
=
b
;
else
break
;
}
}
friend
std
::
ostream
&
operator
<<
(
std
::
ostream
&
out
,
ipAddr
&
arr
)
{
out
<<
std
::
dec
<<
(
unsigned
)
arr
[
0
];
for
(
unsigned
i
=
1
;
i
<
4
;
i
++
)
{
out
<<
"."
<<
(
unsigned
)
arr
[
i
];
}
return
out
;
}
};
template
<
typename
T
>
std
::
vector
<
T
>
operator
+
(
const
std
::
vector
<
T
>
&
A
,
const
std
::
vector
<
T
>
&
B
)
{
...
...
@@ -29,23 +81,6 @@ std::vector<T> &operator+=(std::vector<T> &A, const std::vector<T> &B) {
return
A
;
}
typedef
std
::
array
<
unsigned
char
,
6
>
macAddr
;
typedef
std
::
array
<
unsigned
char
,
4
>
inetAddr
;
typedef
std
::
vector
<
unsigned
char
>
bytes
;
typedef
unsigned
char
byte
;
struct
dataset
{
short
type
;
short
len
;
bytes
value
;
};
//typedef std::vector<dataset> datasets;
typedef
std
::
map
<
short
,
dataset
>
datasets
;
//std::function<int()>;
//typedef int receiveCallback;
struct
Options
{
unsigned
flags
=
0x00
;
std
::
string
user
;
...
...
src/Utils.h
deleted
100644 → 0
View file @
30ebdde2
/*
* Utils.h
*
* Created on: 24.09.2015
* Author: jdi
*/