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
febc13c2
Commit
febc13c2
authored
Aug 17, 2022
by
nanamicat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
float ip
parent
e57f20c7
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
8 deletions
+22
-8
CMakeLists.txt
CMakeLists.txt
+4
-4
Dockerfile
Dockerfile
+2
-1
main.cpp
main.cpp
+16
-3
No files found.
CMakeLists.txt
View file @
febc13c2
...
...
@@ -5,11 +5,11 @@ set(CMAKE_CXX_STANDARD 23)
add_executable
(
tun main.cpp
)
target_link_libraries
(
tun
-static
)
target_link_libraries
(
tun
)
find_package
(
Threads REQUIRED
)
target_link_libraries
(
tun Threads::Threads
)
set
(
Boost_USE_STATIC_LIBS ON
)
find_package
(
Boost COMPONENTS program_options REQUIRED
)
target_link_libraries
(
tun Boost::program_options
)
#
set(Boost_USE_STATIC_LIBS ON)
#
find_package(Boost COMPONENTS program_options REQUIRED)
#
target_link_libraries(tun Boost::program_options)
Dockerfile
View file @
febc13c2
...
...
@@ -3,10 +3,11 @@ RUN apk --no-cache add build-base cmake linux-headers boost-dev boost-static
WORKDIR
/usr/src/app
COPY
. .
RUN
cmake
-DCMAKE_BUILD_TYPE
=
Release
.
RUN
cmake
-DCMAKE_BUILD_TYPE
=
Debug
.
RUN
make
FROM
alpine
RUN
apk
--no-cache
add libgcc libstdc++
COPY
--from=builder /usr/src/app/tun .
ENTRYPOINT
["./tun"]
main.cpp
View file @
febc13c2
...
...
@@ -60,7 +60,7 @@ void encrypt_package(unsigned char *buffer, size_t length) {
void
inbound
(
int
raw
,
int
tun
)
{
unsigned
char
buffer
[
ETH_DATA_LEN
];
sockaddr_in
address
{.
sin_family
=
AF_INET
};
socklen_t
address_length
;
socklen_t
address_length
=
sizeof
(
address
)
;
size_t
packet_length
;
while
((
packet_length
=
recvfrom
(
raw
,
buffer
,
sizeof
(
buffer
),
0
,
(
sockaddr
*
)
&
address
,
&
address_length
))
>=
0
)
{
auto
*
packet
=
(
iphdr
*
)
buffer
;
...
...
@@ -77,6 +77,9 @@ void inbound(int raw, int tun) {
// << " tot_len " << ntohs(packet->tot_len)
// << " inner->tot_len " << ntohs(inner->tot_len)
// << " from " << inet_ntoa(address.sin_addr) << std::endl;
if
(
remote_addr
.
sin_addr
.
s_addr
!=
address
.
sin_addr
.
s_addr
)
{
std
::
cout
<<
"float ip: "
<<
inet_ntoa
(
address
.
sin_addr
)
<<
std
::
endl
;
}
remote_addr
=
address
;
if
(
write
(
tun
,
inner
,
payload_length
)
<
0
)
{
...
...
@@ -95,7 +98,8 @@ void outbound(int raw, int tun) {
meta
->
reversed
=
0
;
auto
inner
=
buffer
+
sizeof
(
Meta
);
size_t
packet_length
;
while
((
packet_length
=
read
(
tun
,
inner
,
sizeof
(
buffer
)
-
sizeof
(
Meta
)))
>=
0
)
{
while
((
packet_length
=
read
(
tun
,
inner
,
sizeof
(
buffer
)
+
sizeof
(
Meta
)))
>=
0
)
{
// std::cout << "sendto: " << inet_ntoa(remote_addr.sin_addr) << std::endl;
if
(
!
remote_addr
.
sin_addr
.
s_addr
)
continue
;
encrypt_package
(
inner
,
packet_length
);
if
(
sendto
(
raw
,
buffer
,
packet_length
+
sizeof
(
Meta
),
0
,
(
sockaddr
*
)
&
remote_addr
,
sizeof
(
remote_addr
))
<
0
)
{
...
...
@@ -116,7 +120,15 @@ int main(int argc, char *argv[]) {
auto
up
=
getenv
(
"up"
);
if
(
endpoint
!=
nullptr
)
{
remote_addr
.
sin_addr
.
s_addr
=
((
in_addr
*
)
gethostbyname
(
endpoint
)
->
h_name
)
->
s_addr
;
auto
he
=
gethostbyname
(
endpoint
);
if
(
he
==
nullptr
)
{
perror
(
"gethostbyname"
);
return
-
1
;
}
if
(
he
->
h_addr_list
[
0
]
==
nullptr
)
{
perror
(
"gethostbyname 2"
);
}
remote_addr
.
sin_addr
.
s_addr
=
*
(
in_addr_t
*
)
he
->
h_addr_list
[
0
];
}
secret_length
=
strlen
(
secret
);
...
...
@@ -135,6 +147,7 @@ int main(int argc, char *argv[]) {
perror
(
"tun init error"
);
return
-
1
;
}
std
::
cout
<<
dev
<<
std
::
endl
;
if
(
ioctl
(
tun
,
TUNSETIFF
,
&
ifr
)
<
0
)
{
perror
(
"ioctl error"
);
...
...
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