Beispiel #1
0
 def cksum(self):
     # must take IP header into account: in pseud...        
     mem = self.cs.Val
     self.cs.Val = 0
     icmpstr = str(self)
     self.cs.Val = mem
     return checksum(icmpstr)
Beispiel #2
0
 def cksum(self):
     # must take IPv4 options into account...
     mem = self.cs.Val
     self.cs.Val = 0
     s = str(self)
     self.cs.Val = mem
     # big thanks to scapy /p.biondy:
     return checksum(s)
Beispiel #3
0
 def cksum(self):
     # must take IP header into account: in pseud...        
     mem = self.cs.Val
     self.cs.Val = 0
     tcpstr = str(self)
     hdrstr = str(self.get_header())
     paystr = str(self.get_payload())
     self.cs.Val = mem
     ln = len(tcpstr) + len(paystr)
     if len(hdrstr)>=20 and ord(hdrstr[0])>>4 == 4 :
         pseudstr = ''.join((hdrstr[12:20], '\0', hdrstr[9:10], pack('!H', ln)))
     elif len(hdrstr)>=40 and ord(hdrstr[0])>>4 == 6 :
         # TODO: do it correctly!
         # warning, not considering IPv6 options when selecting proto field
         # double warning, not sure its the right way to do...
         # and anyway, IPv6 is has-been
         pseudstr = ''.join((hdrstr[8:40], '\0' , hdrstr[6:7], pack('!H', ln)))
     else:
         pseudstr = ''.join(('\0\0', pack('!H', ln)))
     return checksum(''.join((pseudstr, tcpstr, paystr)))