utils.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:scapy-bpf 作者: guedou 项目源码 文件源码
def read_packet(self, size=MTU):
        """Read blocks until it reaches either EOF or a packet, and
        returns None or (packet, (linktype, sec, usec, wirelen)),
        where packet is a string.

        """
        while True:
            try:
                blocktype, blocklen = struct.unpack(self.endian + "2I",
                                                    self.f.read(8))
            except struct.error:
                return None
            block = self.f.read(blocklen - 12)
            try:
                if (blocklen,) != struct.unpack(self.endian + 'I',
                                                self.f.read(4)):
                    raise Scapy_Exception(
                        "Invalid pcapng block (bad blocklen)"
                    )
            except struct.error:
                return None
            res = self.blocktypes.get(blocktype,
                                      lambda block, size: None)(block, size)
            if res is not None:
                return res
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号