pim.py 760 B

12345678910111213141516171819202122232425262728293031
  1. """Protocol Independent Multicast."""
  2. from pypacker import pypacker, checksum
  3. class PIM(pypacker.Packet):
  4. __hdr__ = (
  5. ("v_type", "B", 0x20),
  6. ("rsvd", "B", 0),
  7. ("sum", "H", 0) # _sum = sum
  8. )
  9. def __get_v(self):
  10. return self.v_type >> 4
  11. def __set_v(self, v):
  12. self.v_type = (v << 4) | (self.v_type & 0xf)
  13. v = property(__get_v, __set_v)
  14. def __get_type(self):
  15. return self.v_type & 0xf
  16. def __set_type(self, pimtype):
  17. self.v_type = (self.v_type & 0xf0) | pimtype
  18. type = property(__get_type, __set_type)
  19. def bin(self, update_auto_fields=True):
  20. if update_auto_fields and self._changed():
  21. self.sum = 0
  22. self.sum = checksum.in_cksum(pypacker.Packet.bin(self))
  23. return pypacker.Packet.bin(self, update_auto_fields=update_auto_fields)