Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: bindIP not work on udp #63

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,18 @@
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
Loading