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
aca82979
Commit
aca82979
authored
Sep 30, 2015
by
/jdi/
Browse files
some changes
parent
5544792b
Changes
13
Hide whitespace changes
Inline
Side-by-side
src/Device.cpp
deleted
100644 → 0
View file @
5544792b
/*
* Device.cpp
*
* Created on: 01.09.2015
* Author: jdi
*/
#include
"Device.h"
Device
::
Device
()
{
// TODO Auto-generated constructor stub
}
Device
::~
Device
()
{
// TODO Auto-generated destructor stub
}
src/Device.h
deleted
100644 → 0
View file @
5544792b
/*
* Device.h
*
* Created on: 01.09.2015
* Author: jdi
*/
#ifndef DEVICE_H_
#define DEVICE_H_
#include
<string>
class
Device
{
public:
Device
();
virtual
~
Device
();
int
getName
(
void
)
{
return
5
;
}
};
#endif
/* DEVICE_H_ */
src/Host.cpp
View file @
aca82979
...
...
@@ -25,14 +25,16 @@ Host::Host() {
}
bytes
Host
::
getMac
()
{
return
{
0x08
,
0x3e
,
0x8e
,
0x16
,
0x17
,
0x2c
};
byteArray
<
6
>
Host
::
getMac
()
{
byteArray
<
6
>
ret
=
{
0x08
,
0x3e
,
0x8e
,
0x16
,
0x17
,
0x2c
};
//TODO find actual MAC Address
return
ret
;
}
byte
s
Host
::
getIp
(
std
::
string
iface
)
{
byte
Array
<
4
>
Host
::
getIp
(
std
::
string
iface
)
{
struct
ifaddrs
*
ifaddr
,
*
ifa
;
int
n
;
byte
s
data
=
{
0
,
0
,
0
,
0
};
byte
Array
<
4
>
data
=
{
0
,
0
,
0
,
0
};
if
(
getifaddrs
(
&
ifaddr
)
==
-
1
)
{
perror
(
"getifaddrs"
);
...
...
@@ -45,7 +47,6 @@ bytes Host::getIp(std::string iface) {
if
(
ifa
->
ifa_addr
->
sa_family
==
AF_INET
)
{
if
(
iface
.
compare
(
ifa
->
ifa_name
)
==
0
)
{
data
.
resize
(
4
);
memcpy
(
&
data
[
0
],
&
ifa
->
ifa_addr
->
sa_data
[
2
],
4
);
return
data
;
}
...
...
src/Host.h
View file @
aca82979
...
...
@@ -13,9 +13,8 @@
class
Host
{
public:
Host
();
virtual
~
Host
()
{}
bytes
getMac
();
bytes
getIp
(
std
::
string
);
byteArray
<
6
>
getMac
();
byteArray
<
4
>
getIp
(
std
::
string
);
};
#endif
/* HOST_H_ */
src/Options.h
View file @
aca82979
...
...
@@ -14,6 +14,7 @@
#define USAGE "usage: %s [-bhrvx] [-i interface] [-u [password:]username]\n\
[-p password] <command>\n\n"
#define HELP "\
### for questions please contact <smrtlink@jdi.li> ###\n\
Option Summary:\n\
-h --help This help text\n\
-v --version Display version of this tool\n\
...
...
@@ -22,16 +23,25 @@
-x --hex Display Packets as Hex String\n\
-i --interface only use one Interface\n\
-u --user Login with user\n\
-p Password\n\n\
-p Password\n\
-f --file Not yet implemented:.choose a settings file\n\
-t --timeout Not yet implemented\n\
-s --permanent Not yet implemented: make changes immediately permanent\n\n\
Command Summary:\n\
help This help text\n\
list list all connected switches\n\
sniff capture and display all incoming or outgoing packets\n\
depending on the --reverse option\n\n"
depending on the --reverse option\n\
get Not yet implemented\n\
set Not yet implemented\n\
flash Not yet implemented: replace firmware\n\
reboot Not yet implemented\n\
reset Not yet implemented\n\n"
#define FLAG_HEX 1
#define FLAG_REVERSE 2
#define FLAG_HEADER 4
#define FLAG_PERMANENT 4
extern
Options
options
;
...
...
src/Packet.cpp
View file @
aca82979
...
...
@@ -20,14 +20,16 @@ Packet::Packet(OpCode c) {
}
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
::
printHex
(
switchMac
);
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
Hex
(
hostMac
);
printf
(
"
\n\t
Length:
\t
%hd"
,
this
->
getLength
());
printf
(
"
\n\t
Offset:
\t
%hd"
,
fragmentOffset
);
printf
(
"
\n\t
Flags:
\t
%.4hX"
,
flag
);
printf
(
"
\n\t
Checksum:
\t
%d"
,
checkSum
);
utils
::
print
(
hostMac
);
printf
(
"
\n\t
Length:
\t
%hd"
,
this
->
getLength
());
printf
(
"
\n\t
Offset:
\t
%hd"
,
fragmentOffset
);
printf
(
"
\n\t
Flags:
\t
%.4hX"
,
flag
);
printf
(
"
\n\t
Checksum:
\t
%d"
,
checkSum
);
}
bytes
Packet
::
getBytes
()
{
...
...
@@ -65,8 +67,8 @@ void Packet::parse(bytes data) {
short
checkLen
=
0x0
;
pull
(
head
,
i
,
version
);
pull
(
head
,
i
,
opCode
);
pull
(
head
,
i
,
switchMac
,
switchMac
.
size
()
);
pull
(
head
,
i
,
hostMac
,
hostMac
.
size
()
);
pull
(
head
,
i
,
switchMac
);
pull
(
head
,
i
,
hostMac
);
pull
(
head
,
i
,
sequenceId
);
pull
(
head
,
i
,
errorCode
);
pull
(
head
,
i
,
checkLen
);
...
...
@@ -101,7 +103,7 @@ void Packet::setBody(bytes data) {
this
->
body
=
data
;
}
void
Packet
::
setHostMac
(
byte
s
mac
)
{
void
Packet
::
setHostMac
(
byte
Array
<
6
>
mac
)
{
this
->
hostMac
=
mac
;
}
...
...
@@ -125,11 +127,11 @@ void Packet::setSequenceId(short sequenceId) {
this
->
sequenceId
=
sequenceId
;
}
const
byte
s
&
Packet
::
getSwitchMac
()
const
{
const
byte
Array
<
6
>
&
Packet
::
getSwitchMac
()
const
{
return
switchMac
;
}
void
Packet
::
setSwitchMac
(
byte
s
switchMac
)
{
void
Packet
::
setSwitchMac
(
byte
Array
<
6
>
switchMac
)
{
this
->
switchMac
=
switchMac
;
}
...
...
@@ -198,11 +200,18 @@ void Packet::push(bytes &arr, int &index, byte data) {
}
}
void
Packet
::
push
(
bytes
&
arr
,
int
&
index
,
bytes
data
)
{
for
(
unsigned
j
=
0
;
j
<
data
.
size
();
j
++
)
push
(
arr
,
index
,
data
[
j
]);
}
template
<
size_t
N
>
void
Packet
::
push
(
bytes
&
arr
,
int
&
index
,
byteArray
<
N
>
data
)
{
for
(
unsigned
j
=
0
;
j
<
N
;
j
++
)
push
(
arr
,
index
,
data
[
j
]);
}
void
Packet
::
push
(
bytes
&
arr
,
int
&
index
,
short
data
)
{
byte
a
=
(
data
>>
8
)
&
0xFF
;
push
(
arr
,
index
,
a
);
...
...
@@ -237,6 +246,12 @@ void Packet::pull(bytes &arr, int &index, bytes &ret, unsigned len) {
index
+=
len
;
}
template
<
size_t
N
>
void
Packet
::
pull
(
bytes
&
arr
,
int
&
index
,
byteArray
<
N
>
&
ret
)
{
memcpy
(
&
ret
[
0
],
&
arr
[
index
],
N
);
index
+=
N
;
}
void
Packet
::
pull
(
bytes
&
arr
,
int
&
index
,
short
&
ret
)
{
ret
=
(
arr
[
index
++
]
<<
8
);
ret
|=
arr
[
index
++
]
&
0xFF
;
...
...
src/Packet.h
View file @
aca82979
...
...
@@ -29,15 +29,15 @@ public:
short
getLength
()
const
;
int
getCheckSum
()
const
;
short
getSequenceId
()
const
;
const
byte
s
&
getSwitchMac
()
const
;
const
byte
Array
<
6
>
&
getSwitchMac
()
const
;
const
bytes
&
getBody
()
const
;
const
bytes
&
getHead
()
const
;
const
datasets
&
getPayload
()
const
;
void
setBody
(
bytes
);
void
setHostMac
(
bytes
);
void
setHostMac
(
byteArray
<
6
>
);
void
setSwitchMac
(
byteArray
<
6
>
);
void
setCheckSum
(
int
);
void
setSequenceId
(
short
);
void
setSwitchMac
(
bytes
);
void
setPayload
(
const
datasets
&
payload
);
private:
...
...
@@ -47,9 +47,9 @@ private:
byte
version
=
1
;
byte
opCode
;
byte
s
switchMac
=
{
0
,
0
,
0
,
0
,
0
,
0
};
byte
s
hostMac
=
{
0
,
0
,
0
,
0
,
0
,
0
};
// TODO set Mac
byte
s
broadcastMac
=
{
0xFF
,
0xFF
,
0xFF
,
0xFF
,
0xFF
,
0xFF
};
byte
Array
<
6
>
switchMac
=
{
0
,
0
,
0
,
0
,
0
,
0
};
byte
Array
<
6
>
hostMac
=
{
0
,
0
,
0
,
0
,
0
,
0
};
byte
Array
<
6
>
broadcastMac
=
{
0xFF
,
0xFF
,
0xFF
,
0xFF
,
0xFF
,
0xFF
};
short
sequenceId
;
short
tokenId
=
0
;
short
fragmentOffset
=
0
;
...
...
src/Program.cpp
View file @
aca82979
...
...
@@ -10,7 +10,6 @@
#include
"Utils.h"
#include
"Options.h"
#include
"Program.h"
#include
"Device.h"
#include
"Host.h"
#include
"Socket.h"
#include
"Packet.h"
...
...
src/Socket.cpp
View file @
aca82979
...
...
@@ -34,10 +34,9 @@ void Socket::init(short dst_port, short src_port) {
utils
::
printDec
(
local_ip
);
printf
(
"
\n
"
);
std
::
array
<
unsigned
char
,
4
>
ip
=
{
local_ip
[
0
],
local_ip
[
1
],
local_ip
[
21
],
local_ip
[
3
]
};
wildcard_endpoint_
=
asio
::
ip
::
udp
::
endpoint
(
asio
::
ip
::
address_v4
::
from_string
(
"0.0.0.0"
),
src_port
);
local_endpoint_
=
asio
::
ip
::
udp
::
endpoint
(
asio
::
ip
::
address_v4
(
ip
),
local_endpoint_
=
asio
::
ip
::
udp
::
endpoint
(
asio
::
ip
::
address_v4
(
local_
ip
),
src_port
);
broadcast_endpoint_
=
asio
::
ip
::
udp
::
endpoint
(
asio
::
ip
::
address_v4
::
from_string
(
"255.255.255.255"
),
dst_port
);
...
...
src/Socket.h
View file @
aca82979
...
...
@@ -36,7 +36,7 @@ private:
asio
::
ip
::
udp
::
endpoint
wildcard_endpoint_
;
asio
::
ip
::
udp
::
endpoint
local_endpoint_
;
bytes
data
=
bytes
(
MAX_LENGTH
);
byte
s
local_ip
=
bytes
(
4
);
byte
Array
<
4
>
local_ip
=
bytes
(
4
);
};
...
...
src/Types.h
View file @
aca82979
...
...
@@ -10,6 +10,7 @@
#include
<functional>
#include
<vector>
#include
<array>
#include
<map>
template
<
typename
T
>
...
...
@@ -28,6 +29,8 @@ std::vector<T> &operator+=(std::vector<T> &A, const std::vector<T> &B) {
return
A
;
}
template
<
size_t
N
>
using
byteArray
=
std
::
array
<
unsigned
char
,
N
>
;
typedef
std
::
vector
<
unsigned
char
>
bytes
;
typedef
unsigned
char
byte
;
...
...
@@ -47,6 +50,8 @@ struct Options {
std
::
string
user
;
std
::
string
password
;
std
::
string
interface
;
std
::
string
file
;
long
timeout
;
};
#endif
/* TYPES_H_ */
src/Utils.h
View file @
aca82979
...
...
@@ -22,6 +22,20 @@ static void printHex(bytes d) {
}
}
static
void
print
(
byteArray
<
6
>
d
)
{
printf
(
"%.2X"
,
d
[
0
]);
for
(
unsigned
i
=
1
;
i
<
6
;
i
++
)
{
printf
(
":%.2X"
,
d
[
i
]);
}
}
static
void
print
(
byteArray
<
4
>
d
)
{
printf
(
"%.1d"
,
d
[
0
]);
for
(
unsigned
i
=
1
;
i
<
4
;
i
++
)
{
printf
(
".%.1d"
,
d
[
i
]);
}
}
static
void
printDec
(
bytes
d
)
{
if
(
d
.
size
()
>
0
)
printf
(
"%.1d"
,
d
[
0
]);
...
...
src/smrtlink.cpp
View file @
aca82979
...
...
@@ -30,14 +30,16 @@ int main(int argc, char *argv[]) {
const
struct
option
longopts
[]
=
{
{
"version"
,
no_argument
,
0
,
'v'
},
{
"help"
,
no_argument
,
0
,
'h'
},
{
"reverse"
,
no_argument
,
0
,
'r'
},
{
"password"
,
required_argument
,
0
,
'p'
},
{
"user"
,
"permanent"
,
no_argument
,
0
,
's'
},
{
"password"
,
required_argument
,
0
,
'p'
},
{
"user"
,
required_argument
,
0
,
'u'
},
{
"interface"
,
required_argument
,
0
,
'i'
},
{
"header"
,
required_argument
,
0
,
'b'
},
{
"hex"
,
required_argument
,
0
,
'x'
},
{
0
,
0
,
0
,
0
},
};
0
,
'x'
},
{
"file"
,
required_argument
,
0
,
'f'
},
{
"timeout"
,
required_argument
,
0
,
't'
},
{
0
,
0
,
0
,
0
},
};
Program
p
=
Program
();
while
((
opt
=
getopt_long
(
argc
,
argv
,
"bhrvxp:u:i:"
,
longopts
,
&
index
))
while
((
opt
=
getopt_long
(
argc
,
argv
,
"bhr
s
vxp:u:i:
f:t:
"
,
longopts
,
&
index
))
!=
-
1
)
{
switch
(
opt
)
{
...
...
@@ -65,16 +67,28 @@ int main(int argc, char *argv[]) {
options
.
flags
|=
FLAG_HEX
;
break
;
case
's'
:
options
.
flags
|=
FLAG_PERMANENT
;
break
;
case
't'
:
options
.
timeout
=
atoi
(
optarg
);
break
;
case
'f'
:
options
.
file
=
std
::
string
(
optarg
);
break
;
case
'p'
:
options
.
password
=
std
::
string
(
optarg
);
options
.
password
=
std
::
string
(
optarg
);
break
;
case
'u'
:
options
.
user
=
std
::
string
(
optarg
);
options
.
user
=
std
::
string
(
optarg
);
break
;
case
'i'
:
options
.
interface
=
std
::
string
(
optarg
);
options
.
interface
=
std
::
string
(
optarg
);
break
;
default:
/* '?' */
...
...
@@ -96,6 +110,14 @@ int main(int argc, char *argv[]) {
fprintf
(
stderr
,
USAGE
,
argv
[
0
]);
fprintf
(
stderr
,
HELP
);
exit
(
EXIT_SUCCESS
);
}
else
if
(
strcmp
(
argv
[
optind
],
"get"
)
==
0
||
strcmp
(
argv
[
optind
],
"set"
)
==
0
||
strcmp
(
argv
[
optind
],
"reboot"
)
==
0
||
strcmp
(
argv
[
optind
],
"reset"
)
==
0
||
strcmp
(
argv
[
optind
],
"flash"
)
==
0
)
{
optind
++
;
fprintf
(
stderr
,
"Not yet implemented.
\n
"
);
exit
(
EXIT_FAILURE
);
}
else
if
(
strcmp
(
argv
[
optind
],
"list"
)
==
0
)
{
optind
++
;
if
(
p
.
list
())
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment