Skip to content

Commit 17be1dd

Browse files
authored
Merge pull request #1215 from guedou/osx_802.11_monitor
801.11 monitor mode for OSX
2 parents 89a0771 + 5d9eecd commit 17be1dd

2 files changed

Lines changed: 17 additions & 3 deletions

File tree

scapy/arch/bpf/consts.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,7 @@
1919
BIOCSBLEN = 0xc0044266
2020
BIOCGBLEN = 0x40044266
2121
BIOCSETF = 0x80104267
22+
BIOCSDLT = 0x80044278
2223
BIOCSHDRCMPLT = 0x80044275
2324
BIOCGDLT = 0x4004426a
25+
DLT_IEEE802_11_RADIO = 127

scapy/arch/bpf/supersocket.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
from scapy.arch.bpf.core import get_dev_bpf, attach_filter
1515
from scapy.arch.bpf.consts import BIOCGBLEN, BIOCGDLT, BIOCGSTATS, \
1616
BIOCIMMEDIATE, BIOCPROMISC, BIOCSBLEN, BIOCSETIF, BIOCSHDRCMPLT, \
17-
BPF_BUFFER_LENGTH
17+
BPF_BUFFER_LENGTH, BIOCSDLT, DLT_IEEE802_11_RADIO
1818
from scapy.config import conf
19-
from scapy.consts import FREEBSD, NETBSD
19+
from scapy.consts import FREEBSD, NETBSD, DARWIN
2020
from scapy.data import ETH_P_ALL
2121
from scapy.error import Scapy_Exception, warning
2222
from scapy.supersocket import SuperSocket
@@ -40,7 +40,8 @@ class _L2bpfSocket(SuperSocket):
4040
ins = None
4141
closed = False
4242

43-
def __init__(self, iface=None, type=ETH_P_ALL, promisc=None, filter=None, nofilter=0):
43+
def __init__(self, iface=None, type=ETH_P_ALL, promisc=None, filter=None,
44+
nofilter=0, monitor=False):
4445

4546
# SuperSocket mandatory variables
4647
if promisc is None:
@@ -75,6 +76,17 @@ def __init__(self, iface=None, type=ETH_P_ALL, promisc=None, filter=None, nofilt
7576
if self.promisc:
7677
self.set_promisc(1)
7778

79+
# Set the interface to monitor mode
80+
# Note: - trick from libpcap/pcap-bpf.c - monitor_mode()
81+
# - it only works on OS X 10.5 and later
82+
if DARWIN and monitor:
83+
dlt_radiotap = struct.pack('I', DLT_IEEE802_11_RADIO)
84+
try:
85+
fcntl.ioctl(self.ins, BIOCSDLT, dlt_radiotap)
86+
except IOError:
87+
raise Scapy_Exception("Can't set %s into monitor mode!" %
88+
self.iface)
89+
7890
# Don't block on read
7991
try:
8092
fcntl.ioctl(self.ins, BIOCIMMEDIATE, struct.pack('I', 1))

0 commit comments

Comments
 (0)