コード例 #1
0
ファイル: protocol.py プロジェクト: jeetbhatt-sys/PyPCAPKit
    def _import_next_layer(self, proto, length=None):  # pylint: disable=unused-argument
        """Import next layer extractor.

        Arguments:
            proto (int): next layer protocol index
            length (int): valid (*non-padding*) length

        Returns:
            pcapkit.protocols.protocol.Protocol: instance of next layer

        """
        if length is not None and length == 0:
            from pcapkit.protocols.null import NoPayload as protocol  # pylint: disable=import-outside-toplevel
        elif self._sigterm:
            from pcapkit.protocols.raw import Raw as protocol  # pylint: disable=import-outside-toplevel
        else:
            module, name = self.__proto__[proto]
            protocol = getattr(importlib.import_module(module), name)

        next_ = protocol(io.BytesIO(self._read_fileng(length)),
                         length,
                         layer=self._exlayer,
                         protocol=self._exproto)

        return next_
コード例 #2
0
ファイル: link.py プロジェクト: JarryShaw/PyPCAPKit
    def _import_next_layer(self, proto, length=None):
        """Import next layer extractor.

        This method currently supports following protocols as registered in
        :data:`~pcapkit.const.reg.ethertype.EtherType`:

        .. list-table::
           :header-rows: 1

           * - ``proto``
             - Protocol
           * - 0x0806
             - :class:`~pcapkit.protocols.link.arp.ARP`
           * - 0x8035
             - :class:`~pcapkit.protocols.link.rarp.RARP`
           * - 0x8100
             - :class:`~pcapkit.protocols.link.vlan.VLAN`
           * - 0x0800
             - :class:`~pcapkit.protocols.internet.ipv4.IPv4`
           * - 0x86DD
             - :class:`~pcapkit.protocols.internet.ipv6.IPv6`
           * - 0x8137
             - :class:`~pcapkit.protocols.internet.ipx.IPX`


        Arguments:
            proto (int): next layer protocol index
            length (int): valid (*non-padding*) length

        Returns:
            pcapkit.protocols.protocol.Protocol: instance of next layer

        """
        if length == 0:
            from pcapkit.protocols.null import \
                NoPayload as protocol  # pylint: disable=import-outside-toplevel
        elif self._sigterm:
            from pcapkit.protocols.raw import \
                Raw as protocol  # pylint: disable=import-outside-toplevel
        else:
            module, name = self.__proto__[proto]
            try:
                protocol = getattr(importlib.import_module(module), name)
            except (ImportError, AttributeError):
                from pcapkit.protocols.raw import \
                    Raw as protocol  # pylint: disable=import-outside-toplevel

        next_ = protocol(self._file,
                         length,
                         error=self._onerror,
                         layer=self._exlayer,
                         protocol=self._exproto)

        return next_
コード例 #3
0
    def _import_next_layer(self,
                           proto,
                           length=None,
                           *,
                           version=4,
                           extension=False):  # pylint: disable=arguments-differ
        """Import next layer extractor.

        This method currently supports following protocols as registered in
        :data:`~pcapkit.const.reg.transtype.TransType`:

        .. list-table::
           :header-rows: 1

           * - ``proto``
             - Class
           * - 0
             - :class:`~pcapkit.protocols.internet.hopopt.HOPOPT`
           * - 4
             - :class:`~pcapkit.protocols.internet.ipv4.IPv4`
           * - 6
             - :class:`~pcapkit.protocols.transport.tcp.TCP`
           * - 17
             - :class:`~pcapkit.protocols.transport.udp.UDP`
           * - 41
             - :class:`~pcapkit.protocols.internet.ipv6.IPv6`
           * - 43
             - :class:`~pcapkit.protocols.internet.ipv6_route.IPv6_Route`
           * - 44
             - :class:`~pcapkit.protocols.internet.ipv6_frag.IPv6_Frag`
           * - 51
             - :class:`~pcapkit.protocols.internet.ah.AH`
           * - 60
             - :class:`~pcapkit.protocols.internet.ipv6_opts.IPv6_Opts`
           * - 111
             - :class:`~pcapkit.protocols.internet.ipx.IPX`
           * - 135
             - :class:`~pcapkit.protocols.internet.mh.MH`
           * - 139
             - :class:`~pcapkit.protocols.internet.hip.HIP`

        Arguments:
            proto (int): next layer protocol index
            length (int): valid (*non-padding*) length

        Keyword Arguments:
            version (Literal[4, 6]): IP protocol version
            extension (bool): if is extension header

        Returns:
            pcapkit.protocols.protocol.Protocol: instance of next layer

        """
        if length == 0:
            from pcapkit.protocols.null import NoPayload as protocol  # pylint: disable=import-outside-toplevel
        elif self._sigterm or proto == 59:  # No Next Header for IPv6
            from pcapkit.protocols.raw import Raw as protocol  # pylint: disable=import-outside-toplevel
        else:
            module, name = self.__proto__[proto]
            try:
                protocol = getattr(importlib.import_module(module), name)
            except (ImportError, AttributeError):
                from pcapkit.protocols.raw import Raw as protocol  # pylint: disable=import-outside-toplevel

        next_ = protocol(self._file,
                         length,
                         version=version,
                         extension=extension,
                         error=self._onerror,
                         layer=self._exlayer,
                         protocol=self._exproto)
        return next_