github.com/database64128/shadowsocks-go@v1.10.2-0.20240315062903-143a773533f1/conn/conn_darwinfreebsd.go (about) 1 //go:build darwin || freebsd 2 3 package conn 4 5 import ( 6 "fmt" 7 8 "golang.org/x/sys/unix" 9 ) 10 11 func setPMTUD(fd int, network string) error { 12 switch network { 13 case "udp4": 14 if err := unix.SetsockoptInt(int(fd), unix.IPPROTO_IP, unix.IP_DONTFRAG, 1); err != nil { 15 return fmt.Errorf("failed to set socket option IP_DONTFRAG: %w", err) 16 } 17 case "udp6": 18 if err := unix.SetsockoptInt(int(fd), unix.IPPROTO_IPV6, unix.IPV6_DONTFRAG, 1); err != nil { 19 return fmt.Errorf("failed to set socket option IPV6_DONTFRAG: %w", err) 20 } 21 default: 22 return fmt.Errorf("unsupported network: %s", network) 23 } 24 return nil 25 }