MCPcopy Index your code
hub / github.com/secdev/scapy / __init__

Method __init__

scapy/arch/libpcap.py:288–387  ·  view source on GitHub ↗
(self,
                     device,  # type: _GlobInterfaceType
                     snaplen,  # type: int
                     promisc,  # type: bool
                     to_ms,  # type: int
                     monitor=None,  # type: Optional[bool]
                     )

Source from the content-addressed store, hash-verified

286 """Wrapper for the libpcap calls"""
287
288 def __init__(self,
289 device, # type: _GlobInterfaceType
290 snaplen, # type: int
291 promisc, # type: bool
292 to_ms, # type: int
293 monitor=None, # type: Optional[bool]
294 ):
295 # type: (...) -> None
296 self.errbuf = create_string_buffer(PCAP_ERRBUF_SIZE)
297 self.iface = create_string_buffer(
298 network_name(device).encode("utf8")
299 )
300 self.dtl = -1
301 if not WINDOWS or conf.use_npcap:
302 from scapy.libs.winpcapy import pcap_create
303 self.pcap = pcap_create(self.iface, self.errbuf)
304 if not self.pcap:
305 error = decode_locale_str(bytearray(self.errbuf).strip(b"\x00"))
306 if error:
307 raise OSError(error)
308 # Non-winpcap functions
309 from scapy.libs.winpcapy import (
310 pcap_set_snaplen,
311 pcap_set_promisc,
312 pcap_set_timeout,
313 pcap_set_rfmon,
314 pcap_activate,
315 pcap_statustostr,
316 pcap_geterr,
317 )
318 if pcap_set_snaplen(self.pcap, snaplen) != 0:
319 error = decode_locale_str(bytearray(self.errbuf).strip(b"\x00"))
320 if error:
321 raise OSError(error)
322 log_runtime.error("Could not set snaplen")
323 if pcap_set_promisc(self.pcap, promisc) != 0:
324 error = decode_locale_str(bytearray(self.errbuf).strip(b"\x00"))
325 if error:
326 raise OSError(error)
327 log_runtime.error("Could not set promisc")
328 if pcap_set_timeout(self.pcap, to_ms) != 0:
329 error = decode_locale_str(bytearray(self.errbuf).strip(b"\x00"))
330 if error:
331 raise OSError(error)
332 log_runtime.error("Could not set timeout")
333 if monitor:
334 if pcap_set_rfmon(self.pcap, 1) != 0:
335 error = decode_locale_str(bytearray(self.errbuf).strip(b"\x00"))
336 if error:
337 raise OSError(error)
338 log_runtime.error("Could not set monitor mode")
339 status = pcap_activate(self.pcap)
340 # status == 0 means success
341 # status < 0 means error
342 # status > 0 means success, but with a warning
343 if status < 0:
344 # self.iface, and strings we get back from
345 # pcap_geterr() and pcap_statustostr(), have the

Callers

nothing calls this directly

Calls 4

network_nameFunction · 0.90
decode_locale_strFunction · 0.90
bpf_programClass · 0.85
encodeMethod · 0.80

Tested by

no test coverage detected