diff --git a/internal/runner/errors.go b/internal/runner/errors.go new file mode 100644 index 0000000..750fc2b --- /dev/null +++ b/internal/runner/errors.go @@ -0,0 +1,5 @@ +package runner + +import "errors" + +var errDestUnreachable = errors.New("destination address unreachable") diff --git a/internal/runner/runner.go b/internal/runner/runner.go index 7c79a9a..c49fdee 100644 --- a/internal/runner/runner.go +++ b/internal/runner/runner.go @@ -15,6 +15,11 @@ import ( ) func New(opt *common.Options) error { + reachable := isReachable(opt.Destination, 5*time.Second) + if !reachable { + return errDestUnreachable + } + tun, err := tunnel.NewTunnel(opt.Port, opt.Destination, opt.Config.Path, opt.Config.Format) if err != nil { return err diff --git a/internal/runner/utils.go b/internal/runner/utils.go new file mode 100644 index 0000000..a8f3e1f --- /dev/null +++ b/internal/runner/utils.go @@ -0,0 +1,17 @@ +package runner + +import ( + "net" + "time" +) + +func isReachable(dest string, timeout time.Duration) bool { + conn, err := net.DialTimeout("tcp", dest, timeout) + if err != nil { + return false + } + + defer conn.Close() + + return true +}