Beispiel #1
0
 def __str__(self):
     if self.nxt == 6 or self.nxt == 17 or self.nxt == 58:
         # XXX - set TCP, UDP, and ICMPv6 checksums
         p = str(self.data)
         s = _ip_cksum_add(0, self.src + self.dst)
         s = _ip_cksum_add(s, p)
         try: self.data.sum = _ip_cksum_done(s + self.p + len(p))
         except AttributeError: pass
     return Packet.__str__(self)
Beispiel #2
0
 def __str__(self):
     if not self.sum:
         if self.p == 6 or self.p == 17 and self.data.sum == 0 and \
            self.off & (IP_MF|IP_OFFMASK) == 0:
             try:
                 # Set zeroed TCP and UDP checksums for non-fragments.
                 s = _ip_cksum_add(self.data.sum, self.src + self.dst)
                 p = str(self.data)
                 s = _ip_cksum_add(s, p)
                 self.data.sum = _ip_cksum_done(s + self.p + len(p))
                 if self.p == 17 and not self.data.sum:
                     self.data.sum = 0xffff	# RFC 768
             except AttributeError:
                 pass
         self.sum = _ip_cksum(self.pack_hdr())
     return self.pack_hdr() + self.opts + str(self.data)