Update to match latest go version.

This commit is contained in:
2024-06-27 02:20:09 +08:00
parent a55aed58cb
commit ffb93ccd7e
2 changed files with 58 additions and 18 deletions

View File

@ -9,9 +9,9 @@ package server
// WARZONE BEGINS HERE! MIND YOUR HEAD!
import (
"reflect"
"net"
"golang.org/x/sys/unix"
"net"
"reflect"
)
const (
@ -19,13 +19,14 @@ const (
)
func GetFDFromTCPConn(conn *net.TCPConn) int {
// Actual fd is stored at: (*(*TCPConn).conn.fd).sysfd
// Actual fd is stored at: (*(*TCPConn).conn.fd).pfd.Sysfd
v := reflect.ValueOf(*conn)
c := v.FieldByName("conn")
fdp := c.FieldByName("fd")
fd := reflect.Indirect(fdp)
sysfd := fd.FieldByName("sysfd")
return int(sysfd.Int())
pfd := fd.FieldByName("pfd")
Sysfd := pfd.FieldByName("Sysfd")
return int(Sysfd.Int())
}
func GetAddr4FromFD(fd int) *net.TCPAddr {
@ -41,9 +42,9 @@ func GetAddr4FromFD(fd int) *net.TCPAddr {
Flowinfo 4byte ipv4 address
Addr 16byte ignore for ipv4
Scope_id 4byte ignore for ipv4
*/
*/
addr.Flowinfo = be32toh(addr.Flowinfo)
a, b, c, d := byte(addr.Flowinfo >> 24), byte((addr.Flowinfo >> 16) & 255), byte((addr.Flowinfo >> 8) & 255), byte(addr.Flowinfo & 255)
a, b, c, d := byte(addr.Flowinfo>>24), byte((addr.Flowinfo>>16)&255), byte((addr.Flowinfo>>8)&255), byte(addr.Flowinfo&255)
ip := net.IPv4(a, b, c, d)
return &net.TCPAddr{IP: ip, Port: int(be16toh(addr.Port)), Zone: ""}
}
@ -61,9 +62,9 @@ func GetAddr6FromFD(fd int) *net.TCPAddr {
Flowinfo 4byte ipv6 flowinfo ignore
Addr 16byte ipv6 addr
Scope_id 4byte ipv6 scope id ignore
*/
*/
v6addr := make(net.IP, 16)
// Make GC happy?
copy(v6addr, addr.Addr[:])
return &net.TCPAddr{IP: v6addr, Port: int(be16toh(addr.Port)), Zone: ""}
}
}