Skip to content

Commit

Permalink
Merge pull request #22 from TrekkieCoder/main
Browse files Browse the repository at this point in the history
Use given hint to select laddr in case of tcp probes
  • Loading branch information
TrekkieCoder authored Aug 26, 2024
2 parents 7ac692a + 4bf2b99 commit 6929c7b
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion serviceprobe.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,20 @@ func L4ServiceProber(sType string, sName string, sHint, req, resp string) bool {
return sOk
}

c, err := net.DialTimeout(sType, sName, timeout)
var c net.Conn
if sHint == "" {
c, err = net.DialTimeout(sType, sName, timeout)
} else {
dialer := &net.Dialer{
LocalAddr: &net.TCPAddr{
IP: net.ParseIP(sHint),
Port: 0,
},
}
ctx, cancel := context.WithTimeout(context.Background(), 300*time.Millisecond)
defer cancel()
c, err = dialer.DialContext(ctx, sType, sName)
}
if err != nil {
sOk = false
} else {
Expand Down

0 comments on commit 6929c7b

Please sign in to comment.