From c2d85a6e1fc2e05664b552d4507767e9ccd1ae05 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Wed, 21 Aug 2019 12:55:10 +0100 Subject: [PATCH] Add tunnel address --- tunnel/default.go | 11 +++++++++++ tunnel/options.go | 2 +- tunnel/tunnel.go | 2 ++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/tunnel/default.go b/tunnel/default.go index e727a11b..e4328837 100644 --- a/tunnel/default.go +++ b/tunnel/default.go @@ -521,6 +521,17 @@ func (t *tun) close() error { return t.listener.Close() } +func (t *tun) Address() string { + t.RLock() + defer t.RUnlock() + + if !t.connected { + return t.options.Address + } + + return t.listener.Addr() +} + // Close the tunnel func (t *tun) Close() error { t.Lock() diff --git a/tunnel/options.go b/tunnel/options.go index f152c8ac..99406b05 100644 --- a/tunnel/options.go +++ b/tunnel/options.go @@ -8,7 +8,7 @@ import ( var ( // DefaultAddress is default tunnel bind address - DefaultAddress = ":9096" + DefaultAddress = ":0" ) type Option func(*Options) diff --git a/tunnel/tunnel.go b/tunnel/tunnel.go index 9388c296..f7bc91cb 100644 --- a/tunnel/tunnel.go +++ b/tunnel/tunnel.go @@ -11,6 +11,8 @@ import ( // the address being requested. type Tunnel interface { Init(opts ...Option) error + // Address the tunnel is listening on + Address() string // Connect connects the tunnel Connect() error // Close closes the tunnel