diff --git a/pkg/transports/connecting/dtls/nat.go b/pkg/transports/connecting/dtls/nat.go index 8860316b..ab3716b9 100644 --- a/pkg/transports/connecting/dtls/nat.go +++ b/pkg/transports/connecting/dtls/nat.go @@ -5,7 +5,6 @@ import ( "fmt" "net" "os" - "syscall" "time" "github.com/pion/stun" @@ -58,7 +57,7 @@ func openUDPLimitTTL(ctx context.Context, laddr, addr string, dialer dialFunc) e defer fd.Close() // Set the TTL - err = syscall.SetsockoptInt(int(fd.Fd()), syscall.IPPROTO_IP, syscall.IP_TTL, ttl) + err = setSocketTTL(fd, ttl) if err != nil { return err } @@ -70,7 +69,7 @@ func openUDPLimitTTL(ctx context.Context, laddr, addr string, dialer dialFunc) e } // reset TTL - err = syscall.SetsockoptInt(int(fd.Fd()), syscall.IPPROTO_IP, syscall.IP_TTL, defaultTTL) + err = setSocketTTL(fd, defaultTTL) if err != nil { return err } diff --git a/pkg/transports/connecting/dtls/setsockopt_other.go b/pkg/transports/connecting/dtls/setsockopt_other.go new file mode 100644 index 00000000..eeba1ed6 --- /dev/null +++ b/pkg/transports/connecting/dtls/setsockopt_other.go @@ -0,0 +1,12 @@ +//go:build !windows + +package dtls + +import ( + "os" + "syscall" +) + +func setSocketTTL(f *os.File, ttl int) error { + return syscall.SetsockoptInt(int(f.Fd()), syscall.IPPROTO_IP, syscall.IP_TTL, ttl) +} diff --git a/pkg/transports/connecting/dtls/setsockopt_windows.go b/pkg/transports/connecting/dtls/setsockopt_windows.go new file mode 100644 index 00000000..6ab835ea --- /dev/null +++ b/pkg/transports/connecting/dtls/setsockopt_windows.go @@ -0,0 +1,12 @@ +//go:build windows + +package dtls + +import ( + "os" + "syscall" +) + +func setSocketTTL(f *os.File, ttl int) error { + return syscall.SetsockoptInt(syscall.Handle(f.Fd()), syscall.IPPROTO_IP, syscall.IP_TTL, ttl) +}