Files
v2ray_simple/netLayer/netlayer.go
2022-03-23 10:41:42 +08:00

43 lines
849 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
Package netLayer contains definitions in network layer AND transport layer.
比如路由功能一般是 netLayer去做.
以后如果要添加 domain socket, kcp 或 raw socket 等底层协议时或者要控制tcp/udp拨号的细节时也要在此包里实现.
*/
package netLayer
import (
"io"
"log"
"syscall"
"github.com/hahahrfool/v2ray_simple/utils"
)
//net.IPConn, net.TCPConn, net.UDPConn, net.UnixConn
func IsBasicConn(r interface{}) bool {
if _, ok := r.(syscall.Conn); ok {
return true
}
return false
}
func GetRawConn(reader io.Reader) syscall.RawConn {
if sc, ok := reader.(syscall.Conn); ok {
rawConn, err := sc.SyscallConn()
if err != nil {
if utils.CanLogDebug() {
log.Println("can't convert syscall.Conn to syscall.RawConn", reader, err)
}
return nil
}
return rawConn
}
return nil
}