Skip to content

Commit

Permalink
fix: bindIP not work on udp
Browse files Browse the repository at this point in the history
  • Loading branch information
fregie committed May 17, 2024
1 parent d304516 commit 0ea4a8a
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,18 @@ func (sf *Server) handleAssociate(ctx context.Context, writer io.Writer, request
return net.Dial(net_, addr)
}
}
bindLn, err := net.ListenUDP("udp", nil)
var udpAddr *net.UDPAddr
if sf.bindIP != nil {
var err error
udpAddr, err = net.ResolveUDPAddr("udp", sf.bindIP.String()+":0")
if err != nil {
if err := SendReply(writer, statute.RepServerFailure, nil); err != nil {
return fmt.Errorf("failed to send reply, %v", err)

Check warning on line 184 in handle.go

View check run for this annotation

Codecov / codecov/patch

handle.go#L180-L184

Added lines #L180 - L184 were not covered by tests
}
return fmt.Errorf("resolve udp addr failed, %v", err)

Check warning on line 186 in handle.go

View check run for this annotation

Codecov / codecov/patch

handle.go#L186

Added line #L186 was not covered by tests
}
}
bindLn, err := net.ListenUDP("udp", udpAddr)
if err != nil {
if err := SendReply(writer, statute.RepServerFailure, nil); err != nil {
return fmt.Errorf("failed to send reply, %v", err)
Expand Down

0 comments on commit 0ea4a8a

Please sign in to comment.