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

Method __init__

scapy/arch/windows/native.py:70–155  ·  view source on GitHub ↗
(self,
                 iface=None,  # type: Optional[_GlobInterfaceType]
                 ttl=128,  # type: int
                 ipv6=False,  # type: bool
                 promisc=True,  # type: bool
                 **kwargs  # type: Any
                 )

Source from the content-addressed store, hash-verified

68 __slots__ = ["promisc", "cls", "ipv6"]
69
70 def __init__(self,
71 iface=None, # type: Optional[_GlobInterfaceType]
72 ttl=128, # type: int
73 ipv6=False, # type: bool
74 promisc=True, # type: bool
75 **kwargs # type: Any
76 ):
77 # type: (...) -> None
78 from scapy.layers.inet import IP
79 from scapy.layers.inet6 import IPv6
80 for kwarg in kwargs:
81 log_runtime.warning("Dropping unsupported option: %s" % kwarg)
82 self.iface = iface and resolve_iface(iface) or conf.iface
83 if not self.iface.is_valid():
84 log_runtime.warning("Interface is invalid. This will fail.")
85 af = socket.AF_INET6 if ipv6 else socket.AF_INET
86 self.ipv6 = ipv6
87 self.cls = IPv6 if ipv6 else IP
88 # Promisc
89 if promisc is None:
90 promisc = conf.sniff_promisc
91 self.promisc = promisc
92 # Notes:
93 # - IPPROTO_RAW is broken. We don't use it.
94 # - IPPROTO_IPV6 exists in MSDN docs, but using it will result in
95 # no packets being received. Same for its options (IPV6_HDRINCL...)
96 # However, using IPPROTO_IP with AF_INET6 will still receive
97 # the IPv6 packets
98 try:
99 # Listening on AF_INET6 IPPROTO_IPV6 is broken. Use IPPROTO_IP
100 self.outs = self.ins = socket.socket(
101 af,
102 socket.SOCK_RAW,
103 socket.IPPROTO_IP,
104 )
105 except OSError as e:
106 if e.errno == 13:
107 raise OSError("Windows native L3 Raw sockets are only "
108 "usable as administrator ! "
109 "Please install Npcap to workaround !")
110 raise
111 self.ins.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
112 self.ins.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 2**30)
113 self.outs.setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 2**30)
114 # set TTL
115 self.ins.setsockopt(socket.IPPROTO_IP, socket.IP_TTL, ttl)
116 # Get as much data as possible: reduce what is cropped
117 if ipv6:
118 # IPV6_HDRINCL is broken. Use IP_HDRINCL even on IPv6
119 self.outs.setsockopt(socket.IPPROTO_IPV6, socket.IP_HDRINCL, 1)
120 try: # Not all Windows versions
121 self.ins.setsockopt(socket.IPPROTO_IPV6,
122 socket.IPV6_RECVTCLASS, 1)
123 self.ins.setsockopt(socket.IPPROTO_IPV6,
124 socket.IPV6_HOPLIMIT, 1)
125 except (OSError, socket.error):
126 pass
127 else:

Callers 1

__init__Method · 0.45

Calls 5

resolve_ifaceFunction · 0.90
get_if_addr6Function · 0.90
get_if_addrFunction · 0.90
is_validMethod · 0.80
bindMethod · 0.45

Tested by

no test coverage detected