Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
T
tun
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Railgun
tun
Commits
42ed93d4
Commit
42ed93d4
authored
Jul 01, 2022
by
nanamicat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
encrypt
parent
648d0b93
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
1 deletion
+18
-1
main.cpp
main.cpp
+18
-1
No files found.
main.cpp
View file @
42ed93d4
...
...
@@ -15,6 +15,18 @@
in_addr_t
remote
;
auto
cipher
=
"Mathematics is the art of giving the same name to different things"
;
void
encrypt
(
char
*
buffer
,
size_t
length
)
{
for
(
auto
i
=
0
;
i
<
length
;
i
++
)
{
buffer
[
i
]
^=
cipher
[
i
];
}
}
void
decrypt
(
char
*
buffer
,
size_t
length
)
{
encrypt
(
buffer
,
length
);
}
// internet -> tun
void
inbound
(
int
raw
,
int
tun
)
{
char
buf
[
ETH_DATA_LEN
];
...
...
@@ -25,7 +37,10 @@ void inbound(int raw, int tun) {
// std::cout << "received " << packet_length << " bytes from " << inet_ntoa(address.sin_addr) << std::endl;
auto
*
packet
=
(
iphdr
*
)
buf
;
auto
overhead
=
packet
->
ihl
*
4
;
if
(
write
(
tun
,
buf
+
overhead
,
packet_length
-
overhead
)
<
0
)
{
auto
payload
=
buf
+
overhead
;
auto
payload_length
=
packet_length
-
overhead
;
decrypt
(
payload
,
payload_length
);
if
(
write
(
tun
,
payload
,
payload_length
)
<
0
)
{
perror
(
"inbound write"
);
}
}
...
...
@@ -39,6 +54,7 @@ void outbound(int raw, int tun) {
address
.
sin_addr
.
s_addr
=
remote
;
size_t
packet_length
;
while
((
packet_length
=
read
(
tun
,
buf
,
sizeof
(
buf
)))
>=
0
)
{
encrypt
(
buf
,
packet_length
);
if
(
sendto
(
raw
,
buf
,
packet_length
,
0
,
(
sockaddr
*
)
&
address
,
sizeof
(
address
))
<
0
)
{
perror
(
"outbound write"
);
}
...
...
@@ -46,6 +62,7 @@ void outbound(int raw, int tun) {
perror
(
"outbound read"
);
}
namespace
po
=
boost
::
program_options
;
int
main
(
int
argc
,
char
*
argv
[])
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a 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