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
9941bd10
Commit
9941bd10
authored
Jun 30, 2022
by
nanamicat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
beautify
parent
d43161dd
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
32 additions
and
14 deletions
+32
-14
.dockerignore
.dockerignore
+4
-0
.gitignore
.gitignore
+2
-2
CMakeLists.txt
CMakeLists.txt
+1
-1
Dockerfile
Dockerfile
+12
-0
entrypoint.sh
entrypoint.sh
+2
-0
main.cpp
main.cpp
+11
-11
No files found.
.dockerignore
0 → 100644
View file @
9941bd10
# Project exclude paths
cmake-build-debug
.idea
Dockerfile
\ No newline at end of file
.gitignore
View file @
9941bd10
# Project exclude paths
/cmake-build-debug/
/.idea/
\ No newline at end of file
cmake-build-debug
.idea
\ No newline at end of file
CMakeLists.txt
View file @
9941bd10
...
...
@@ -8,5 +8,5 @@ add_executable(tun main.cpp)
find_package
(
Threads REQUIRED
)
target_link_libraries
(
tun Threads::Threads
)
#target_link_libraries(tun fmt
)
target_link_libraries
(
tun -static-libgcc -static-libstdc++
)
Dockerfile
0 → 100644
View file @
9941bd10
FROM
alpine AS builder
RUN
apk
--no-cache
add build-base cmake linux-headers
WORKDIR
/usr/src/app
COPY
. .
RUN
cmake
-DCMAKE_BUILD_TYPE
=
Release .
RUN
make
FROM
alpine
COPY
--from=builder /usr/src/app/tun .
RUN
[
"./tun"
]
\ No newline at end of file
entrypoint.sh
0 → 100644
View file @
9941bd10
./tun
$1
\ No newline at end of file
main.cpp
View file @
9941bd10
...
...
@@ -16,14 +16,14 @@ in_addr_t remote;
// internet -> tun
void
inbound
(
int
raw
,
int
tun
)
{
char
buf
[
ETH_DATA_LEN
];
sockaddr_in
addr
{
AF_INET
};
socklen_t
addr
len
;
size_t
nread
;
while
((
nread
=
recvfrom
(
raw
,
buf
,
sizeof
(
buf
),
0
,
(
sockaddr
*
)
&
addr
,
&
addrlen
))
>=
0
)
{
std
::
cout
<<
"recv "
<<
nread
<<
" bytes from"
<<
inet_ntoa
(
addr
.
sin_addr
)
<<
std
::
endl
;
sockaddr_in
addr
ess
{.
sin_family
=
AF_INET
};
socklen_t
addr
ess_length
;
size_t
packet_length
;
while
((
packet_length
=
recvfrom
(
raw
,
buf
,
sizeof
(
buf
),
0
,
(
sockaddr
*
)
&
address
,
&
address_length
))
>=
0
)
{
// 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
,
nread
-
overhead
)
<
0
)
{
if
(
write
(
tun
,
buf
+
overhead
,
packet_length
-
overhead
)
<
0
)
{
perror
(
"inbound write"
);
}
}
...
...
@@ -33,11 +33,11 @@ void inbound(int raw, int tun) {
// tun -> internet
void
outbound
(
int
raw
,
int
tun
)
{
char
buf
[
ETH_DATA_LEN
];
sockaddr_in
addr
{
AF_INET
};
addr
.
sin_addr
.
s_addr
=
remote
;
size_t
nread
;
while
((
nread
=
read
(
tun
,
buf
,
sizeof
(
buf
)))
>=
0
)
{
if
(
sendto
(
raw
,
buf
,
nread
,
0
,
(
sockaddr
*
)
&
addr
,
sizeof
(
addr
))
<
0
)
{
sockaddr_in
addr
ess
{.
sin_family
=
AF_INET
};
addr
ess
.
sin_addr
.
s_addr
=
remote
;
size_t
packet_length
;
while
((
packet_length
=
read
(
tun
,
buf
,
sizeof
(
buf
)))
>=
0
)
{
if
(
sendto
(
raw
,
buf
,
packet_length
,
0
,
(
sockaddr
*
)
&
address
,
sizeof
(
address
))
<
0
)
{
perror
(
"outbound write"
);
}
}
...
...
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