How to use the dpkt.dpkt.Packet 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 / rfb.py View on Github external
class RFB(dpkt.Packet):
    """Remote Framebuffer Protocol.

    TODO: Longer class information....

    Attributes:
        __hdr__: Header fields of RADIUS.
        TODO.
    """
    
    __hdr__ = (
        ('type', 'B', 0),
    )


class SetPixelFormat(dpkt.Packet):
    __hdr__ = (
        ('pad', '3s', b''),
        ('pixel_fmt', '16s', b'')
    )


class SetEncodings(dpkt.Packet):
    __hdr__ = (
        ('pad', '1s', b''),
        ('num_encodings', 'H', 0)
    )


class FramebufferUpdateRequest(dpkt.Packet):
    __hdr__ = (
        ('incremental', 'B', 0),
github mike01 / pypacker / dpkt / ieee80211.py View on Github external
)
		def unpack(self, buf):
			dpkt.Packet.unpack(self, buf)
			self.info = buf[2:self.len+ 2]

	class FH(dpkt.Packet):
		__hdr__ = (
			('id', 'B', 0),
			('len', 'B', 0),
			('tu', 'H', 0),
			('hopset', 'B', 0),
			('hoppattern', 'B', 0),
			('hopindex', 'B', 0)
			)

	class DS(dpkt.Packet):
		__hdr__ = (
			('id', 'B', 0),
			('len', 'B', 0),
			('ch', 'B', 0)
			)

	class CF(dpkt.Packet):
		__hdr__ = (
			('id', 'B', 0),
			('len', 'B', 0),
			('count', 'B', 0),
			('period', 'B', 0),
			('max', 'H', 0),
			('dur', 'H', 0)
			)
github kbandla / dpkt / dpkt / ssl.py View on Github external
pointer = 2
    while pointer < extensions_length:
        ext_type = struct.unpack('!H', buf[pointer:pointer+2])[0]
        pointer += 2
        ext_data, parsed = parse_variable_array(buf[pointer:], 2)
        extensions.append((ext_type, ext_data))
        pointer += parsed
    return extensions


class SSL3Exception(Exception):
    pass


class TLSRecord(dpkt.Packet):

    """
    SSLv3 or TLSv1+ packet.

    In addition to the fields specified in the header, there are
    compressed and decrypted fields, indicating whether, in the language
    of the spec, this is a TLSPlaintext, TLSCompressed, or
    TLSCiphertext. The application will have to figure out when it's
    appropriate to change these values.
    """

    __hdr__ = (
        ('type', 'B', 0),
        ('version', 'H', 0),
        ('length', 'H', 0),
    )
github kbandla / dpkt / dpkt / http2.py View on Github external
HTTP2_FRAME_SIZE_ERROR: 'FRAME_SIZE_ERROR',
    HTTP2_REFUSED_STREAM: 'REFUSED_STREAM',
    HTTP2_CANCEL: 'CANCEL',
    HTTP2_COMPRESSION_ERROR: 'COMPRESSION_ERROR',
    HTTP2_CONNECT_ERROR: 'CONNECT_ERROR',
    HTTP2_ENHANCE_YOUR_CALM: 'ENHANCE_YOUR_CALM',
    HTTP2_INADEQUATE_SECURITY: 'INADEQUATE_SECURITY',
    HTTP2_HTTP_1_1_REQUIRED: 'HTTP_1_1_REQUIRED',
}


class HTTP2Exception(Exception):
    pass


class Preface(dpkt.Packet):
    __hdr__ = (
        ('preface', '24s', HTTP2_PREFACE),
    )

    def unpack(self, buf):
        dpkt.Packet.unpack(self, buf)
        if self.preface != HTTP2_PREFACE:
            raise HTTP2Exception('Invalid HTTP/2 preface')
        self.data = ''


class Frame(dpkt.Packet):

    """
    An HTTP/2 frame as defined in RFC 7540
    """
github kbandla / dpkt / dpkt / http2.py View on Github external
('flags', 'B', 0),
        ('stream_id', 'I', 0),
    )

    def unpack(self, buf):
        dpkt.Packet.unpack(self, buf)
        # only take the right number of bytes
        self.data = self.data[:self.length]
        if len(self.data) != self.length:
            raise dpkt.NeedData

    @property
    def length(self):
        return struct.unpack('!I', b'\x00' + self.length_bytes)[0]

class Priority(dpkt.Packet):

    """
    Payload of a PRIORITY frame, also used in HEADERS frame with FLAG_PRIORITY.

    Also used in the HEADERS frame if the PRIORITY flag is set.
    """

    __hdr__ = (
        ('stream_dep', 'I', 0),
        ('weight', 'B', 0),
    )

    def unpack(self, buf):
        dpkt.Packet.unpack(self, buf)
        if len(self.data) != 0:
            raise HTTP2Exception('Invalid number of bytes in PRIORITY frame')
github kbandla / dpkt / dpkt / aoecfg.py View on Github external
# -*- coding: utf-8 -*-
"""ATA over Ethernet ATA command"""
from __future__ import print_function
from __future__ import absolute_import

from . import dpkt


class AOECFG(dpkt.Packet):
    """ATA over Ethernet ATA command.

    See more about the AOE on \
    https://en.wikipedia.org/wiki/ATA_over_Ethernet

    Attributes:
        __hdr__: Header fields of AOECFG.
        data: Message data.
    """

    __hdr__ = (
        ('bufcnt', 'H', 0),
        ('fwver', 'H', 0),
        ('scnt', 'B', 0),
        ('aoeccmd', 'B', 0),
        ('cslen', 'H', 0),
github kbandla / dpkt / dpkt / radiotap.py View on Github external
if self.flags_present and self.flags.fcs:
                self.data = ieee80211.IEEE80211(self.data, fcs=self.flags.fcs)
            else:
                self.data = ieee80211.IEEE80211(self.data)

    class Antenna(dpkt.Packet):
        __hdr__ = (
            ('index', 'B', 0),
        )

    class AntennaNoise(dpkt.Packet):
        __hdr__ = (
            ('db', 'B', 0),
        )

    class AntennaSignal(dpkt.Packet):
        __hdr__ = (
            ('db', 'B', 0),
        )

    class Channel(dpkt.Packet):
        __hdr__ = (
            ('freq', 'H', 0),
            ('flags', 'H', 0),
        )

    class FHSS(dpkt.Packet):
        __hdr__ = (
            ('set', 'B', 0),
            ('pattern', 'B', 0),
        )
github mike01 / pypacker / dpkt / gre.py View on Github external
)
	_protosw = {}
	sre = ()
	def get_v(self):
		return self.flags & 0x7
	def set_v(self, v):
		self.flags = (self.flags & ~0x7) | (v & 0x7)
	v = property(get_v, set_v)

	def get_recur(self):
		return (self.flags >> 5) & 0x7
	def set_recur(self, v):
		self.flags = (self.flags & ~0xe0) | ((v & 0x7) << 5)
	recur = property(get_recur, set_recur)

	class SRE(dpkt.Packet):
		__hdr__ = [
			('family', 'H', 0),
			('off', 'B', 0),
			('len', 'B', 0)
			]
		def unpack(self, buf):
			# TODO: called twice? see dpkt.py
			dpkt.Packet.unpack(self, buf)
			self.data = self.data[:self.len]

	def opt_fields_fmts(self):
		if self.v == 0:
			fields, fmts = [], []
			opt_fields = GRE_opt_fields
		else:
			fields, fmts = [ 'len', 'callid' ], [ 'H', 'H' ]
github kbandla / dpkt / dpkt / aoe.py View on Github external
def pack_hdr(self):
        try:
            return dpkt.Packet.pack_hdr(self)
        except struct.error as e:
            raise dpkt.PackError(str(e))