Beispiel #1
0
 def _compute_checksum_ipv4(self, ip4, xdata):
     if ip4 is None:
         return 0
     xhdr = struct.pack('!IIxBHHHHH', int(ip4.srcip), int(ip4.dstip),
                        ip4.protocol.value, self._len, self.srcport,
                        self.dstport, self._len, 0)
     return checksum(xhdr + xdata)
Beispiel #2
0
 def _compute_checksum_ipv4(self, ip4, xdata):
     if ip4 is None:
         return 0
     phdr = struct.pack('!IIxBH', int(ip4.srcip), int(ip4.dstip),
                        ip4.protocol.value, self._len)
     tcphdr = self._make_header(0)
     return checksum(phdr + tcphdr + xdata)
Beispiel #3
0
 def _compute_checksum_ipv4(self, ip4, xdata):
     if ip4 is None:
         return 0
     phdr = struct.pack('!IIxBH', int(ip4.srcip), int(ip4.dstip), 
         ip4.protocol.value, self._len)
     tcphdr = self._make_header(0)
     return checksum(phdr + tcphdr + xdata)
Beispiel #4
0
 def _compute_checksum_ipv4(self, ip4, xdata):
     if ip4 is None:
         return 0
     xhdr = struct.pack('!IIxBHHHHH', int(ip4.srcip), int(ip4.dstip), 
         ip4.protocol.value, self._len, 
         self.srcport, self.dstport, self._len, 0)
     return checksum(xhdr + xdata)
Beispiel #5
0
 def _compute_checksum(self):
     # FIXME: computed on IPv6 pseudoheader + full mobility header (starting with ext header)
     # pseudoheader: srcaddr(16),dstaddr(16),len of mobility header (4), 000 next header(4)
     self._checksum = 0
     exthdr = self.to_bytes(computecsum=False)
     self._checksum = checksum(
         struct.pack('16s16sIxxxB', self._srcip.packed, self._dstip.packed,
                     len(exthdr), IPProtocol.IPv6Mobility.value) + exthdr)
     return self._checksum
Beispiel #6
0
 def checksum(self):
     data = struct.pack(IPv4._PACKFMT,
                 (4 << 4) + self.hl, self.tos,
                 self._totallen, self.ipid,
                 (self.flags.value << 13) | self.fragment_offset, 
                 self.ttl,
                 self.protocol.value, 0, self.src.packed, self.dst.packed)
     data += self._options.to_bytes()
     self._csum = checksum(data, 0)
     return self._csum
Beispiel #7
0
 def checksum(self):
     self._checksum = checksum(b''.join(
         (struct.pack(ICMP._PACKFMT, self._type.value, self._code.value,
                      0), self._icmpdata.to_bytes())))
     return self._checksum