Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions scapy/arch/bpf/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,7 @@
BIOCSBLEN = 0xc0044266
BIOCGBLEN = 0x40044266
BIOCSETF = 0x80104267
BIOCSDLT = 0x80044278
BIOCSHDRCMPLT = 0x80044275
BIOCGDLT = 0x4004426a
DLT_IEEE802_11_RADIO = 127
18 changes: 15 additions & 3 deletions scapy/arch/bpf/supersocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
from scapy.arch.bpf.core import get_dev_bpf, attach_filter
from scapy.arch.bpf.consts import BIOCGBLEN, BIOCGDLT, BIOCGSTATS, \
BIOCIMMEDIATE, BIOCPROMISC, BIOCSBLEN, BIOCSETIF, BIOCSHDRCMPLT, \
BPF_BUFFER_LENGTH
BPF_BUFFER_LENGTH, BIOCSDLT, DLT_IEEE802_11_RADIO
from scapy.config import conf
from scapy.consts import FREEBSD, NETBSD
from scapy.consts import FREEBSD, NETBSD, DARWIN
from scapy.data import ETH_P_ALL
from scapy.error import Scapy_Exception, warning
from scapy.supersocket import SuperSocket
Expand All @@ -40,7 +40,8 @@ class _L2bpfSocket(SuperSocket):
ins = None
closed = False

def __init__(self, iface=None, type=ETH_P_ALL, promisc=None, filter=None, nofilter=0):
def __init__(self, iface=None, type=ETH_P_ALL, promisc=None, filter=None,
nofilter=0, monitor=False):

# SuperSocket mandatory variables
if promisc is None:
Expand Down Expand Up @@ -75,6 +76,17 @@ def __init__(self, iface=None, type=ETH_P_ALL, promisc=None, filter=None, nofilt
if self.promisc:
self.set_promisc(1)

# Set the interface to monitor mode
# Note: - trick from libpcap/pcap-bpf.c - monitor_mode()
# - it only works on OS X 10.5 and later
if DARWIN and monitor:
dlt_radiotap = struct.pack('I', DLT_IEEE802_11_RADIO)
try:
fcntl.ioctl(self.ins, BIOCSDLT, dlt_radiotap)
except IOError:
raise Scapy_Exception("Can't set %s into monitor mode!" %
self.iface)

# Don't block on read
try:
fcntl.ioctl(self.ins, BIOCIMMEDIATE, struct.pack('I', 1))
Expand Down