github.com/sagernet/sing@v0.4.0-beta.19.0.20240518125136-f67a0988a636/common/control/frag_darwin.go (about) 1 package control 2 3 import ( 4 "os" 5 "syscall" 6 7 "golang.org/x/sys/unix" 8 ) 9 10 func DisableUDPFragment() Func { 11 return func(network, address string, conn syscall.RawConn) error { 12 return Raw(conn, func(fd uintptr) error { 13 switch network { 14 case "udp4": 15 if err := unix.SetsockoptInt(int(fd), unix.IPPROTO_IP, unix.IP_DONTFRAG, 1); err != nil { 16 return os.NewSyscallError("SETSOCKOPT IP_DONTFRAG", err) 17 } 18 case "udp6": 19 if err := unix.SetsockoptInt(int(fd), unix.IPPROTO_IPV6, unix.IPV6_DONTFRAG, 1); err != nil { 20 return os.NewSyscallError("SETSOCKOPT IPV6_DONTFRAG", err) 21 } 22 } 23 return nil 24 }) 25 } 26 }