diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-05-17 15:35:20 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-05-17 15:35:20 +0200 |
commit | c718f3940d6546f83cc14c4f121d52470a705c31 (patch) | |
tree | cb51832e060c782be265865778bcb36f17058c9e /device | |
parent | 95c70b803278a1725416498d58e04e0a93813a71 (diff) |
device: fail to give bind if it doesn't exist
Diffstat (limited to 'device')
-rw-r--r-- | device/boundif_android.go | 14 | ||||
-rw-r--r-- | device/device.go | 1 |
2 files changed, 13 insertions, 2 deletions
diff --git a/device/boundif_android.go b/device/boundif_android.go index ecc9331..6d0fecf 100644 --- a/device/boundif_android.go +++ b/device/boundif_android.go @@ -5,8 +5,14 @@ package device +import "errors" + func (device *Device) PeekLookAtSocketFd4() (fd int, err error) { - sysconn, err := device.net.bind.(*nativeBind).ipv4.SyscallConn() + nb, ok := device.net.bind.(*nativeBind) + if !ok { + return 0, errors.New("no socket exists") + } + sysconn, err := nb.ipv4.SyscallConn() if err != nil { return } @@ -20,7 +26,11 @@ func (device *Device) PeekLookAtSocketFd4() (fd int, err error) { } func (device *Device) PeekLookAtSocketFd6() (fd int, err error) { - sysconn, err := device.net.bind.(*nativeBind).ipv6.SyscallConn() + nb, ok := device.net.bind.(*nativeBind) + if !ok { + return 0, errors.New("no socket exists") + } + sysconn, err := nb.ipv6.SyscallConn() if err != nil { return } diff --git a/device/device.go b/device/device.go index ef269f5..fa7ed88 100644 --- a/device/device.go +++ b/device/device.go @@ -133,6 +133,7 @@ func deviceUpdateState(device *Device) { switch newIsUp { case true: if err := device.BindUpdate(); err != nil { + device.log.Error.Printf("Unable to update bind: %v\n", err) device.isUp.Set(false) break } |