Skip to content

Commit

Permalink
Fix Windows build (#267)
Browse files Browse the repository at this point in the history
  • Loading branch information
rod-hynes authored Jan 30, 2024
1 parent 46fea9b commit c8df961
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
5 changes: 2 additions & 3 deletions pkg/transports/connecting/dtls/nat.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"net"
"os"
"syscall"
"time"

"github.com/pion/stun"
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down
12 changes: 12 additions & 0 deletions pkg/transports/connecting/dtls/setsockopt_other.go
Original file line number Diff line number Diff line change
@@ -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)
}
12 changes: 12 additions & 0 deletions pkg/transports/connecting/dtls/setsockopt_windows.go
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit c8df961

Please sign in to comment.