mirror of
https://github.com/XTLS/Xray-core.git
synced 2024-09-17 15:56:25 +00:00
34 lines
701 B
Go
34 lines
701 B
Go
package internet_test
|
|
|
|
import (
|
|
"context"
|
|
"net"
|
|
"syscall"
|
|
"testing"
|
|
|
|
"github.com/sagernet/sing/common/control"
|
|
"github.com/xtls/xray-core/common"
|
|
"github.com/xtls/xray-core/transport/internet"
|
|
)
|
|
|
|
func TestRegisterListenerController(t *testing.T) {
|
|
var gotFd uintptr
|
|
|
|
common.Must(internet.RegisterListenerController(func(network, address string, conn syscall.RawConn) error {
|
|
return control.Raw(conn, func(fd uintptr) error {
|
|
gotFd = fd
|
|
return nil
|
|
})
|
|
}))
|
|
|
|
conn, err := internet.ListenSystemPacket(context.Background(), &net.UDPAddr{
|
|
IP: net.IPv4zero,
|
|
}, nil)
|
|
common.Must(err)
|
|
common.Must(conn.Close())
|
|
|
|
if gotFd == 0 {
|
|
t.Error("expected none-zero fd, but actually 0")
|
|
}
|
|
}
|