def recv(self, x=MTU): # type: (int) -> Optional[Packet] data, sa_ll, ts = self._recv_raw(self.ins, x) if sa_ll[2] == socket.PACKET_OUTGOING: return None if sa_ll[3] in conf.l2types: cls = conf.l2types.num2layer[sa_ll[3]] # type: Type[Packet] lvl = 2 elif sa_ll[1] in conf.l3types: cls = conf.l3types.num2layer[sa_ll[1]] lvl = 3 else: cls = conf.default_l2 warning("Unable to guess type (interface=%s protocol=%#x family=%i). Using %s", sa_ll[0], sa_ll[1], sa_ll[3], cls.name) # noqa: E501 lvl = 3 try: pkt = cls(data) except KeyboardInterrupt: raise except Exception: if conf.debug_dissector: raise pkt = conf.raw_layer(data) if lvl == 2: pkt = pkt.payload if pkt is not None: if ts is None: from scapy.arch.linux import get_last_packet_timestamp ts = get_last_packet_timestamp(self.ins) pkt.time = ts return pkt
def recv_raw(self, x=0xffff): # type: (int) -> Tuple[Optional[Type[Packet]], Optional[bytes], Optional[float]] # noqa: E501 """ Receives a packet, then returns a tuple containing (cls, pkt_data, time) """ try: pkt, _, ts = self._recv_raw(self.ins, x) except BlockingIOError: # noqa: F821 warning('Captured no data, socket in non-blocking mode.') return None, None, None except socket.timeout: warning('Captured no data, socket read timed out.') return None, None, None except OSError as e: # something bad happened (e.g. the interface went down) warning("Captured no data. %s" % e) if e.errno == 84: warning("Maybe a consecutive frame was missed. " "Increasing `stmin` could solve this problem.") elif e.errno == 110: warning('Captured no data, socket read timed out.') else: self.close() return None, None, None if ts is None: ts = get_last_packet_timestamp(self.ins) return self.basecls, pkt, ts
def recv(self, x=CAN_FRAME_SIZE): try: pkt, sa_ll = self.ins.recvfrom(x) except BlockingIOError: # noqa: F821 warning("Captured no data, socket in non-blocking mode.") return None except socket.timeout: warning("Captured no data, socket read timed out.") return None except OSError: # something bad happened (e.g. the interface went down) warning("Captured no data.") return None # need to change the byte order of the first four bytes, # required by the underlying Linux SocketCAN frame format if not conf.contribs['CAN']['swap-bytes']: pkt = struct.pack("<I12s", *struct.unpack(">I12s", pkt)) len = pkt[4] canpkt = self.basecls(pkt[:len + 8]) canpkt.time = get_last_packet_timestamp(self.ins) if self.remove_padding: return canpkt else: return canpkt / Padding(pkt[len + 8:])
def try_receive_packet(s, packet_class=IP): try: packet = packet_class(s.recv(1024)) packet.time = get_last_packet_timestamp(s) return packet except socket.error as e: if ERROR_NO_DATA == e[0]: return None else: raise
def try_receive_packet(s, packet_class=IP): try: packet = packet_class(s.recv(1024)) packet.time = get_last_packet_timestamp(s) return packet except socket.error as e: if ERROR_NO_DATA == e[0]: return None else: raise
def recv(self, x=0xffff): try: pkt, sa_ll = self.ins.recvfrom(x) except BlockingIOError: warning('Captured no data, socket in non-blocking mode.') return None except socket.timeout: warning('Captured no data, socket read timed out.') return None except OSError: # something bad happened (e.g. the interface went down) warning("Captured no data.") return None q = self.basecls(pkt) q.time = get_last_packet_timestamp(self.ins) return q
def recv_raw(self, x=0xffff): """Receives a packet, then returns a tuple containing (cls, pkt_data, time)""" try: pkt = self.ins.recvfrom(x)[0] except BlockingIOError: # noqa: F821 warning('Captured no data, socket in non-blocking mode.') return None except socket.timeout: warning('Captured no data, socket read timed out.') return None except OSError: # something bad happened (e.g. the interface went down) warning("Captured no data.") return None ts = get_last_packet_timestamp(self.ins) return self.basecls, pkt, ts
def recv_raw(self, x=0xffff): """Receives a packet, then returns a tuple containing (cls, pkt_data, time)""" # noqa: E501 try: pkt = self.ins.recvfrom(x)[0] except BlockingIOError: # noqa: F821 warning('Captured no data, socket in non-blocking mode.') return None except socket.timeout: warning('Captured no data, socket read timed out.') return None except OSError: # something bad happened (e.g. the interface went down) warning("Captured no data.") return None ts = get_last_packet_timestamp(self.ins) return self.basecls, pkt, ts
def recv(self, x=CAN_FRAME_SIZE): # Fetching the Arb ID, DLC and Data try: pkt, sa_ll = self.ins.recvfrom(x) except BlockingIOError: warning('Captured no data, socket in non-blocking mode.') return None except socket.timeout: warning('Captured no data, socket read timed out.') return None except OSError: # something bad happened (e.g. the interface went down) warning("Captured no data.") return None q = CAN(pkt) q.time = get_last_packet_timestamp(self.ins) return q
def recv_raw(self, x=CAN_MTU): # type: (int) -> Tuple[Optional[Type[Packet]], Optional[bytes], Optional[float]] # noqa: E501 """Returns a tuple containing (cls, pkt_data, time)""" pkt = None try: pkt = self.ins.recv(x) except BlockingIOError: # noqa: F821 warning("Captured no data, socket in non-blocking mode.") except socket.timeout: warning("Captured no data, socket read timed out.") except OSError: # something bad happened (e.g. the interface went down) warning("Captured no data.") # need to change the byte order of the first four bytes, # required by the underlying Linux SocketCAN frame format if not conf.contribs['CAN']['swap-bytes'] and pkt is not None: pkt = struct.pack("<I12s", *struct.unpack(">I12s", pkt)) return self.basecls, pkt, get_last_packet_timestamp(self.ins)
def recv_raw(self, x=0xffff): # type: (int) -> Tuple[Optional[Type[Packet]], Optional[bytes], Optional[float]] # noqa: E501 """ Receives a packet, then returns a tuple containing (cls, pkt_data, time) """ try: pkt, _, ts = self._recv_raw(self.ins, x) except BlockingIOError: # noqa: F821 warning('Captured no data, socket in non-blocking mode.') return None, None, None except socket.timeout: warning('Captured no data, socket read timed out.') return None, None, None except OSError: # something bad happened (e.g. the interface went down) warning("Captured no data.") self.close() return None, None, None if ts is None: ts = get_last_packet_timestamp(self.ins) return self.basecls, pkt, ts
def recv(self, x=CAN_FRAME_SIZE): try: pkt, sa_ll = self.ins.recvfrom(x) except BlockingIOError: # noqa: F821 warning("Captured no data, socket in non-blocking mode.") return None except socket.timeout: warning("Captured no data, socket read timed out.") return None except OSError: # something bad happened (e.g. the interface went down) warning("Captured no data.") return None # need to change the byteoder of the first four bytes, # required by the underlying Linux SocketCAN frame format pkt = struct.pack("<I12s", *struct.unpack(">I12s", pkt)) len = pkt[4] canpkt = CAN(pkt[:len + 8]) canpkt.time = get_last_packet_timestamp(self.ins) if self.remove_padding: return canpkt else: return canpkt / Padding(pkt[len + 8:])