How to use the dpkt.dpkt.Packet.unpack function in dpkt

To help you get started, we’ve selected a few dpkt examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github kbandla / dpkt / dpkt / radius.py View on Github external
def unpack(self, buf):
        dpkt.Packet.unpack(self, buf)
        self.attrs = parse_attrs(self.data)
        self.data = b''
github mike01 / pypacker / dpkt / rpc.py View on Github external
def unpack(self, buf):
			dpkt.Packet.unpack(self, buf)
			n = struct.unpack('>I', self.data[:4])[0]
			self.data = self.data[4:4+n]
		def __len__(self):
github kbandla / dpkt / dpkt / ssl.py View on Github external
def unpack(self, buf):
       try:
           dpkt.Packet.unpack(self, buf)
           all_certs, all_certs_len = parse_variable_array(self.data, 3)
           self.certificates = []
           pointer = 3
           while pointer < all_certs_len:
               cert, parsed = parse_variable_array(self.data[pointer:], 3)
               self.certificates.append((cert))
               pointer += parsed
       except struct.error:
            raise dpkt.NeedData
github mike01 / pypacker / dpkt / radius.py View on Github external
def unpack(self, buf):
		dpkt.Packet.unpack(self, buf)
		self.attrs = parse_attrs(self.data)
		self.data = ''
github mike01 / pypacker / dpkt / h225.py View on Github external
def unpack(self, buf):
		# TPKT header
		self.tpkt = tpkt.TPKT(buf)
		if self.tpkt.v != 3: 
			raise dpkt.UnpackError('invalid TPKT version')
		if self.tpkt.rsvd != 0:
			raise dpkt.UnpackError('invalid TPKT reserved value')
		n = self.tpkt.len - self.tpkt.__hdr_len__
		if n > len(self.tpkt.data):
			raise dpkt.UnpackError('invalid TPKT length')
		buf = self.tpkt.data

		# Q.931 payload
		dpkt.Packet.unpack(self, buf)
		buf = buf[self.__hdr_len__:]
		self.ref_val = buf[:self.ref_len]
		buf = buf[self.ref_len:]
		self.type = struct.unpack('B', buf[:1])[0]
		buf = buf[1:]

		# Information Elements
		l = []
		while buf:
			ie = self.IE(buf)
			l.append(ie)
			buf = buf[len(ie):]
		self.data = l
github mike01 / pypacker / dpkt / sctp.py View on Github external
def unpack(self, buf):
		dpkt.Packet.unpack(self, buf)
		l = []
		while self.data:
			chunk = Chunk(self.data)
			l.append(chunk)
			self.data = self.data[len(chunk):]
		self.data = self.chunks = l
github mike01 / pypacker / dpkt / ip6.py View on Github external
def unpack(self, buf):
		dpkt.Packet.unpack(self, buf)
		setattr(self, 'length', (self.len + 2) * 4)
		setattr(self, 'auth_data', self.data[:(self.len - 1) * 4])
github kbandla / dpkt / dpkt / bgp.py View on Github external
def unpack(self, buf):
                dpkt.Packet.unpack(self, buf)
                self.data = self.data[:self.len]

                if self.type == AUTHENTICATION:
                    self.data = self.authentication = self.Authentication(self.data)
                elif self.type == CAPABILITY:
                    self.data = self.capability = self.Capability(self.data)
github mike01 / pypacker / dpkt / ppp.py View on Github external
def unpack(self, buf):
		dpkt.Packet.unpack(self, buf)
		if self.p & PFC_BIT == 0:
			self.p = struct.unpack('>H', buf[:2])[0]
			self.data = self.data[1:]
		try:
			self.data = self._protosw[self.p](self.data)
			setattr(self, self.data.__class__.__name__.lower(), self.data)
		except (KeyError, struct.error, dpkt.UnpackError):
			pass
github kbandla / dpkt / dpkt / pppoe.py View on Github external
def unpack(self, buf):
        dpkt.Packet.unpack(self, buf)
        if self.p & ppp.PFC_BIT == 0:
            try:
                self.p = struct.unpack('>H', buf[:2])[0]
            except struct.error:
                raise dpkt.NeedData
            self.data = self.data[1:]
        try:
            self.data = self._protosw[self.p](self.data)
            setattr(self, self.data.__class__.__name__.lower(), self.data)
        except (KeyError, struct.error, dpkt.UnpackError):
            pass