How to use the fbtftp.constants function in fbtftp

To help you get started, we’ve selected a few fbtftp 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 axbaretto / fbtftp / fbtftp / base_server.py View on Github external
"""
        Deals with incoming RRQ packets. This is called by `run_once` when data
        is available on the listening socket.
        This method deals with extracting all the relevant information from the
        request (like file, transfer mode, path, and options).
        If all is good it will run the `get_handler` method, which returns a
        `BaseHandler` object. `BaseHandler` is a subclass of a
        `multiprocessing.Process` class so calling `start()` on it will cause
        a `fork()`.
        """
        data, peer = self._listener.recvfrom(constants.DEFAULT_BLKSIZE)
        code = struct.unpack('!H', data[:2])[0]
        if code != constants.OPCODE_RRQ:
            logging.warning(
                'unexpected TFTP opcode %d, expected %d' %
                (code, constants.OPCODE_RRQ)
            )
            return

        # extract options
        tokens = list(filter(bool, data[2:].decode('latin-1').split('\x00')))
        if len(tokens) < 2 or len(tokens) % 2 != 0:
            logging.error(
                'Received malformed packet, ignoring '
                '(tokens length: {tl})'.format(tl=len(tokens))
            )
            return

        path = tokens[0]
        options = collections.OrderedDict([
            ('mode', tokens[1].lower()),
            ('default_timeout', self._timeout),