mirror of
https://github.com/SagerNet/sing-tun.git
synced 2025-04-03 03:47:39 +03:00
Export interface for WireGuard
This commit is contained in:
parent
8a18f0c99e
commit
4ebeb2fa86
11 changed files with 269 additions and 49 deletions
34
stack_system_packet.go
Normal file
34
stack_system_packet.go
Normal file
|
@ -0,0 +1,34 @@
|
|||
package tun
|
||||
|
||||
import (
|
||||
"net/netip"
|
||||
"syscall"
|
||||
|
||||
"github.com/sagernet/sing-tun/internal/gtcpip/header"
|
||||
)
|
||||
|
||||
func PacketIPVersion(packet []byte) int {
|
||||
return header.IPVersion(packet)
|
||||
}
|
||||
|
||||
func PacketFillHeader(packet []byte, ipVersion int) {
|
||||
if PacketOffset > 0 {
|
||||
switch ipVersion {
|
||||
case header.IPv4Version:
|
||||
packet[3] = syscall.AF_INET
|
||||
case header.IPv6Version:
|
||||
packet[3] = syscall.AF_INET6
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func PacketDestination(packet []byte) netip.Addr {
|
||||
switch ipVersion := header.IPVersion(packet); ipVersion {
|
||||
case header.IPv4Version:
|
||||
return header.IPv4(packet).DestinationAddr()
|
||||
case header.IPv6Version:
|
||||
return header.IPv6(packet).DestinationAddr()
|
||||
default:
|
||||
return netip.Addr{}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue