Open dawei73 opened 6 years ago
This would be very helpful as it could help in some scenarios where we don't see any packets unless it's set to promiscuous mode. Is there any plan to include this?
Current workaround is ip link set $INTERFACE promisc on
.
Using reflect, so very dirty :)
func setPromiscuous(tp *afpacket.TPacket, ifidx int, on bool) error {
mreq := unix.PacketMreq{
Ifindex: int32(ifidx),
Type: unix.PACKET_MR_PROMISC,
}
opt := unix.PACKET_DROP_MEMBERSHIP
if on {
opt = unix.PACKET_ADD_MEMBERSHIP
}
fd := int(reflect.ValueOf(tp).Elem().FieldByName("fd").Int())
return unix.SetsockoptPacketMreq(fd, unix.SOL_PACKET, opt, &mreq)
}
ifidx
is the interface index.
It would be nice to be able to set the socket in promiscuous mode.
perhaps something like this: