device: do not crash on nil'd bind in windows binding

This commit is contained in:
Jason A. Donenfeld 2019-07-18 19:34:45 +02:00
parent 31ff9c02fe
commit 7bc0e11831

View File

@ -7,6 +7,7 @@ package device
import (
"encoding/binary"
"errors"
"unsafe"
"golang.org/x/sys/windows"
@ -23,6 +24,10 @@ func (device *Device) BindSocketToInterface4(interfaceIndex uint32) error {
binary.BigEndian.PutUint32(bytes, interfaceIndex)
interfaceIndex = *(*uint32)(unsafe.Pointer(&bytes[0]))
if device.net.bind == nil {
return errors.New("Bind is not yet initialized")
}
sysconn, err := device.net.bind.(*nativeBind).ipv4.SyscallConn()
if err != nil {
return err