示例#1
0
 def __str__(self):
     if (self.nxt == 6 or self.nxt == 17 or self.nxt == 58) and not self.data.sum:
         # XXX - set TCP, UDP, and ICMPv6 checksums
         p = str(self.data)
         s = dpkt.in_cksum_add(0, self.src + self.dst)
         s = dpkt.in_cksum_add(s, p)
         try:
             self.data.sum = dpkt.in_cksum_done(s + self.nxt + len(p))
         except AttributeError:
             pass
     return dpkt.Packet.__str__(self)
示例#2
0
 def __str__(self):
     if (self.nxt == 6 or self.nxt == 17 or self.nxt == 58) and not self.data.sum:
         # XXX - set TCP, UDP, and ICMPv6 checksums
         p = str(self.data)
         s = dpkt.struct.pack('>16s16sxBH', self.src, self.dst, self.nxt, len(p))
         s = dpkt.in_cksum_add(0, s)
         s = dpkt.in_cksum_add(s, p)
         try:
             self.data.sum = dpkt.in_cksum_done(s)
         except AttributeError:
             pass
     return self.pack_hdr() + self.headers_str() + str(self.data)
示例#3
0
    def __verify_checksums(cls, ippacket):
        if dpkt.in_cksum(ippacket.pack_hdr() + str(ippacket.opts)) != 0:
            return False

        if (ippacket.off & (dpkt.ip.IP_MF | dpkt.ip.IP_OFFMASK)) != 0:
            return True

        p = str(ippacket.data)
        s = dpkt.struct.pack('>4s4sxBH', ippacket.src, ippacket.dst,
                             ippacket.p, len(p))
        s = dpkt.in_cksum_add(0, s)
        s = dpkt.in_cksum_add(s, p)
        return dpkt.in_cksum_done(s) == 0
示例#4
0
文件: ip.py 项目: birnbap/dpkt
 def __str__(self):
     if self.sum == 0:
         self.sum = dpkt.in_cksum(self.pack_hdr() + str(self.opts))
         if (self.p == 6 or self.p == 17) and (self.off & (IP_MF | IP_OFFMASK)) == 0 and \
                 isinstance(self.data, dpkt.Packet) and self.data.sum == 0:
             # Set zeroed TCP and UDP checksums for non-fragments.
             p = str(self.data)
             s = dpkt.struct.pack('>4s4sxBH', self.src, self.dst,
                                  self.p, len(p))
             s = dpkt.in_cksum_add(0, s)
             s = dpkt.in_cksum_add(s, p)
             self.data.sum = dpkt.in_cksum_done(s)
             if self.p == 17 and self.data.sum == 0:
                 self.data.sum = 0xffff  # RFC 768
                 # XXX - skip transports which don't need the pseudoheader
     return self.pack_hdr() + str(self.opts) + str(self.data)