Skip to content

Commit

Permalink
Set SO_REUSEADDR on UDP socket for scan
Browse files Browse the repository at this point in the history
  • Loading branch information
kasperl committed Dec 20, 2023
1 parent c04dde2 commit 9a11a20
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
17 changes: 16 additions & 1 deletion cmd/jag/commands/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ import (
"os"
"sort"
"strings"
"syscall"
"time"

"github.com/manifoldco/promptui"
"github.com/spf13/cobra"
"github.com/toitlang/jaguar/cmd/jag/directory"
"github.com/toitware/ubjson"
"golang.org/x/sys/unix"
"gopkg.in/yaml.v2"
)

Expand Down Expand Up @@ -236,7 +238,20 @@ func scan(ctx context.Context, ds deviceSelect, port uint) ([]Device, error) {
return []Device{*dev}, nil
}

pc, err := net.ListenPacket("udp4", fmt.Sprintf(":%d", port))
listenConfig := net.ListenConfig{
Control: func(network, address string, c syscall.RawConn) error {
var opErr error
err := c.Control(func(fd uintptr) {
opErr = unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_REUSEADDR, 1)

Check failure on line 245 in cmd/jag/commands/scan.go

View workflow job for this annotation

GitHub Actions / build_jag (windows-latest)

undefined: unix.SetsockoptInt

Check failure on line 245 in cmd/jag/commands/scan.go

View workflow job for this annotation

GitHub Actions / build_jag (windows-latest)

undefined: unix.SOL_SOCKET

Check failure on line 245 in cmd/jag/commands/scan.go

View workflow job for this annotation

GitHub Actions / build_jag (windows-latest)

undefined: unix.SO_REUSEADDR
})
if err != nil {
return err
}
return opErr
},
}

pc, err := listenConfig.ListenPacket(context.Background(), "udp4", fmt.Sprintf(":%d", port))
if err != nil {
return nil, err
}
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ require (
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa // indirect
golang.org/x/net v0.18.0
golang.org/x/sys v0.14.0 // indirect
golang.org/x/term v0.14.0
golang.org/x/tools v0.15.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231120223509-83a465c0220f // indirect
Expand Down

0 comments on commit 9a11a20

Please sign in to comment.