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
736011c3
Commit
736011c3
authored
Aug 17, 2022
by
神楽坂玲奈
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ipv6
parent
641f7806
Pipeline
#15704
passed with stages
in 40 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
13 deletions
+18
-13
src/main.cpp
src/main.cpp
+18
-13
No files found.
src/main.cpp
View file @
736011c3
...
...
@@ -20,7 +20,7 @@ struct Meta {
unsigned
char
local_id
;
unsigned
char
remote_id
;
sockaddr_
in
remote_addr
{.
sin_family
=
AF_INET
};
sockaddr_
storage
remote_addr
{
};
/* Checksum a block of data */
uint16_t
csum
(
uint16_t
*
packet
,
int
packlen
)
{
...
...
@@ -71,7 +71,7 @@ Secret *remoteSecret;
// internet -> tun
void
inbound
(
int
raw
,
int
tun
)
{
unsigned
char
buffer
[
ETH_DATA_LEN
];
sockaddr_
in
address
{.
sin_family
=
AF_INET
}
;
sockaddr_
storage
address
;
socklen_t
address_length
=
sizeof
(
address
);
size_t
packet_length
;
while
((
packet_length
=
recvfrom
(
raw
,
buffer
,
sizeof
(
buffer
),
0
,
(
sockaddr
*
)
&
address
,
&
address_length
))
>=
0
)
{
...
...
@@ -98,9 +98,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
;
}
//
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
)
{
...
...
@@ -121,7 +121,7 @@ void outbound(int raw, int tun) {
size_t
packet_length
;
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
.
s
in_addr
.
s_addr
)
continue
;
if
(
!
remote_addr
.
s
s_family
)
continue
;
localSecret
->
encrypt
(
inner
,
packet_length
);
if
(
sendto
(
raw
,
buffer
,
packet_length
+
sizeof
(
Meta
),
0
,
(
sockaddr
*
)
&
remote_addr
,
sizeof
(
remote_addr
))
<
0
)
{
perror
(
"outbound write"
);
...
...
@@ -158,15 +158,20 @@ int main(int argc, char *argv[]) {
auto
mark
=
get_var_number
(
"MARK"
);
if
(
endpoint
!=
nullptr
)
{
auto
he
=
gethostbyname
(
endpoint
);
if
(
he
==
nullptr
)
{
perror
(
"gethostbyname error"
);
return
-
1
;
addrinfo
hints
=
{
// .ai_family = AF_UNSPEC // AF_INET, AF_INET6 如果你需要只请求A或AAAA
};
addrinfo
*
result
;
if
(
getaddrinfo
(
argv
[
1
],
argv
[
2
],
&
hints
,
&
result
)
!=
0
)
{
perror
(
"getaddrinfo"
);
}
if
(
he
->
h_addr_list
[
0
]
==
nullptr
)
{
perror
(
"gethostbyname error 2"
);
for
(
auto
rp
=
result
;
rp
!=
nullptr
;
rp
=
rp
->
ai_next
)
{
remote_addr
=
*
(
sockaddr_storage
*
)
rp
->
ai_addr
;
break
;
// remote_addr.ss_family 如果你需要从结果里筛选
}
remote_addr
.
sin_addr
.
s_addr
=
*
(
in_addr_t
*
)
he
->
h_addr_list
[
0
];
freeaddrinfo
(
result
);
/* No longer needed */
}
ifreq
ifr
{};
ifr
.
ifr_flags
=
IFF_TUN
|
IFF_NO_PI
;
...
...
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