github.com/database64128/shadowsocks-go@v1.10.2-0.20240315062903-143a773533f1/conn/conn_darwin.go (about) 1 package conn 2 3 import ( 4 "fmt" 5 6 "golang.org/x/sys/unix" 7 ) 8 9 func setRecvPktinfo(fd int, network string) error { 10 switch network { 11 case "udp4": 12 if err := unix.SetsockoptInt(fd, unix.IPPROTO_IP, unix.IP_RECVPKTINFO, 1); err != nil { 13 return fmt.Errorf("failed to set socket option IP_PKTINFO: %w", err) 14 } 15 case "udp6": 16 if err := unix.SetsockoptInt(fd, unix.IPPROTO_IPV6, unix.IPV6_RECVPKTINFO, 1); err != nil { 17 return fmt.Errorf("failed to set socket option IPV6_RECVPKTINFO: %w", err) 18 } 19 default: 20 return fmt.Errorf("unsupported network: %s", network) 21 } 22 return nil 23 } 24 25 func (lso ListenerSocketOptions) buildSetFns() setFuncSlice { 26 return setFuncSlice{}. 27 appendSetTrafficClassFunc(lso.TrafficClass). 28 appendSetReusePortFunc(lso.ReusePort). 29 appendSetPMTUDFunc(lso.PathMTUDiscovery). 30 appendSetRecvPktinfoFunc(lso.ReceivePacketInfo) 31 }