set IFF_PROMISC

This commit is contained in:
Kioubit 2022-01-04 15:48:28 -05:00
parent 1f294666f3
commit 48486cc205
2 changed files with 5 additions and 5 deletions

View File

@ -37,7 +37,7 @@ type iflags struct {
flags uint16 flags uint16
} }
func setAllMulti(fd int, iface string, enable bool) { func setPromisc(fd int, iface string, enable bool) {
var ifl iflags var ifl iflags
copy(ifl.name[:], []byte(iface)) copy(ifl.name[:], []byte(iface))
_, _, ep := syscall.Syscall(syscall.SYS_IOCTL, uintptr(fd), syscall.SIOCGIFFLAGS, uintptr(unsafe.Pointer(&ifl))) _, _, ep := syscall.Syscall(syscall.SYS_IOCTL, uintptr(fd), syscall.SIOCGIFFLAGS, uintptr(unsafe.Pointer(&ifl)))
@ -46,9 +46,9 @@ func setAllMulti(fd int, iface string, enable bool) {
} }
if enable { if enable {
ifl.flags |= uint16(syscall.IFF_ALLMULTI) ifl.flags |= uint16(syscall.IFF_PROMISC)
} else { } else {
ifl.flags &^= uint16(syscall.IFF_ALLMULTI) ifl.flags &^= uint16(syscall.IFF_PROMISC)
} }
_, _, ep = syscall.Syscall(syscall.SYS_IOCTL, uintptr(fd), syscall.SIOCSIFFLAGS, uintptr(unsafe.Pointer(&ifl))) _, _, ep = syscall.Syscall(syscall.SYS_IOCTL, uintptr(fd), syscall.SIOCSIFFLAGS, uintptr(unsafe.Pointer(&ifl)))

View File

@ -34,7 +34,7 @@ func listen(iface string, responder chan *ndpRequest, requestType ndpType, stopW
} }
go func() { go func() {
<-stopChan <-stopChan
setAllMulti(fd, iface, false) setPromisc(fd, iface, false)
_ = syscall.Close(fd) _ = syscall.Close(fd)
stopWG.Done() // syscall.read does not release when the file descriptor is closed stopWG.Done() // syscall.read does not release when the file descriptor is closed
}() }()
@ -51,7 +51,7 @@ func listen(iface string, responder chan *ndpRequest, requestType ndpType, stopW
panic(err.Error()) panic(err.Error())
} }
setAllMulti(fd, iface, true) setPromisc(fd, iface, true)
var protocolNo uint32 var protocolNo uint32
if requestType == ndp_SOL { if requestType == ndp_SOL {