google / google/gopacket

Set afpacket socket in promiscuous mode

Open
#564 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
6.8k
Forks
1.2k
PR merge metrics
No merged PRs in 30d

Description

It would be nice to be able to set the socket in promiscuous mode.

perhaps something like this:
```
func (h *TPacket) SetPromiscMode(ifaceName string) error {
ifIndex := 0
// An empty string here means to listen to all interfaces
if ifaceName != "" {
iface, err := net.InterfaceByName(ifaceName)
if err != nil {
return fmt.Errorf("InterfaceByName: %v", err)
}
ifIndex = iface.Index
}
var sp C.struct_packet_mreq
sp.mr_ifindex = C.int(ifIndex)
sp.mr_type = unix.PACKET_MR_PROMISC
sp.mr_alen = 0
sp.mr_address = [8]C.uchar{0,0,0,0,0,0,0,0}
if err := setsockopt(h.fd, unix.SOL_PACKET, unix.PACKET_ADD_MEMBERSHIP, unsafe.Pointer(&sp), unsafe.Sizeof(sp)); err != nil {
return fmt.Errorf("setsockopt promisc mode: %v", err)
}
return nil
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.