Migrate clashtcpip to gVisor tcpip copied
This commit is contained in:
parent
7f8e556bb0
commit
1793988a6d
43 changed files with 7370 additions and 1340 deletions
35
internal/gtcpip/header/netip.go
Normal file
35
internal/gtcpip/header/netip.go
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
package header
|
||||
|
||||
import "net/netip"
|
||||
|
||||
func (b IPv4) SourceAddr() netip.Addr {
|
||||
return netip.AddrFrom4([4]byte(b[srcAddr : srcAddr+IPv4AddressSize]))
|
||||
}
|
||||
|
||||
func (b IPv4) DestinationAddr() netip.Addr {
|
||||
return netip.AddrFrom4([4]byte(b[dstAddr : dstAddr+IPv4AddressSize]))
|
||||
}
|
||||
|
||||
func (b IPv4) SetSourceAddr(addr netip.Addr) {
|
||||
copy(b[srcAddr:srcAddr+IPv4AddressSize], addr.AsSlice())
|
||||
}
|
||||
|
||||
func (b IPv4) SetDestinationAddr(addr netip.Addr) {
|
||||
copy(b[dstAddr:dstAddr+IPv4AddressSize], addr.AsSlice())
|
||||
}
|
||||
|
||||
func (b IPv6) SourceAddr() netip.Addr {
|
||||
return netip.AddrFrom16([16]byte(b[v6SrcAddr:][:IPv6AddressSize]))
|
||||
}
|
||||
|
||||
func (b IPv6) DestinationAddr() netip.Addr {
|
||||
return netip.AddrFrom16([16]byte(b[v6DstAddr:][:IPv6AddressSize]))
|
||||
}
|
||||
|
||||
func (b IPv6) SetSourceAddr(addr netip.Addr) {
|
||||
copy(b[v6SrcAddr:][:IPv6AddressSize], addr.AsSlice())
|
||||
}
|
||||
|
||||
func (b IPv6) SetDestinationAddr(addr netip.Addr) {
|
||||
copy(b[v6DstAddr:][:IPv6AddressSize], addr.AsSlice())
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue