Skip to content

Commit

Permalink
Set PACKET_ADD_MEMBERSHIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Kioubit committed Jan 4, 2022
1 parent d8c439a commit ede44e8
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions pndp/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package pndp
import (
"golang.org/x/net/bpf"
"golang.org/x/sys/unix"
"net"
"syscall"
"unsafe"
)
Expand Down Expand Up @@ -38,6 +39,7 @@ type iflags struct {
}

func setPromisc(fd int, iface string, enable bool) {
//TODO re-test ALLMULTI
var ifl iflags
copy(ifl.name[:], []byte(iface))
_, _, ep := syscall.Syscall(syscall.SYS_IOCTL, uintptr(fd), syscall.SIOCGIFFLAGS, uintptr(unsafe.Pointer(&ifl)))
Expand All @@ -55,4 +57,28 @@ func setPromisc(fd int, iface string, enable bool) {
if ep != 0 {
panic(ep)
}

// Also set Sockopt to promisc
intf, err := net.InterfaceByName(iface)
if err != nil {
panic(err.Error())
}

mreq := unix.PacketMreq{
Ifindex: int32(intf.Index),
Type: unix.PACKET_MR_PROMISC,
}

var opt int
if enable {
opt = unix.PACKET_ADD_MEMBERSHIP
} else {
opt = unix.PACKET_DROP_MEMBERSHIP
}

err = unix.SetsockoptPacketMreq(fd, unix.SOL_PACKET, opt, &mreq)
if err != nil {
panic(err)
}

}

0 comments on commit ede44e8

Please sign in to comment.