| | 23 | from utils.my_exceptions import UMPAAttributeException |
| | 24 | |
| | 25 | class HVersion(base.Field): |
| | 26 | def fillout(self): |
| | 27 | pass |
| | 28 | |
| | 29 | class HIHL(base.Field): |
| | 30 | def fillout(self): |
| | 31 | pass |
| | 32 | |
| | 33 | class HTypeOfService(base.Field): |
| | 34 | def fillout(self): |
| | 35 | pass |
| | 36 | |
| | 37 | class HTotalLength(base.Field): |
| | 38 | def fillout(self): |
| | 39 | pass |
| | 40 | |
| | 41 | class HIdentification(base.Field): |
| | 42 | def fillout(self): |
| | 43 | pass |
| | 44 | |
| | 45 | class HFlags(base.Field): |
| | 46 | def fillout(self): |
| | 47 | pass |
| | 48 | |
| | 49 | class HFragmentOffset(base.Field): |
| | 50 | def fillout(self): |
| | 51 | pass |
| | 52 | |
| | 53 | class HTimeToLive(base.Field): |
| | 54 | def fillout(self): |
| | 55 | pass |
| | 56 | |
| | 57 | class HProtocol(base.Field): |
| | 58 | def fillout(self): |
| | 59 | pass |
| | 60 | |
| | 61 | class HHeaderChecksum(base.Field): |
| | 62 | def fillout(self): |
| | 63 | pass |
| | 64 | |
| | 65 | class HSourceAddress(base.Field): |
| | 66 | def fillout(self): |
| | 67 | pass |
| | 68 | |
| | 69 | class HDestinationAddress(base.Field): |
| | 70 | def fillout(self): |
| | 71 | pass |
| | 72 | |
| | 73 | class HOptions(base.Field): |
| | 74 | def fillout(self): |
| | 75 | pass |
| | 76 | |
| | 77 | class HPadding(base.Field): |
| | 78 | def fillout(self): |
| | 79 | pass |
| | 80 | |
| | 81 | # main IP class |
| | 84 | valid_fields = ['_version', '_ihl', 'type_of_service', '_total_length', |
| | 85 | 'identification', 'flags', '_fragment_offset', 'time_to_live', |
| | 86 | 'protocol', '_header_checksum', 'source_address', |
| | 87 | 'destination_address', 'options', '_padding',] |
| | 88 | |
| 28 | | self._version = None |
| 29 | | self._ihl = None |
| 30 | | self._total_length = None |
| 31 | | self._fragment_offset = None |
| 32 | | self._header_checksum = None |
| 33 | | self._padding = None |
| | 94 | self._fields = [ HVersion(4, True), HIHL(4, True), |
| | 95 | HTypeOfService(8), HTotalLength(16, True), |
| | 96 | HIdentification(16, True), HFlags(3, True), |
| | 97 | HFragmentOffset(13, True), HTimeToLive(8), |
| | 98 | HProtocol(8, True), HHeaderChecksum(16, True), |
| | 99 | HSourceAddress(16), HDestinationAddress(16), |
| | 100 | HOptions(0), HPadding(0, True), ] |
| 47 | | def set_identification(self, val): |
| 48 | | pass |
| 49 | | def get_identification(self): |
| 50 | | return self._identification |
| 51 | | identification = property(get_identification, set_identification) |
| | 113 | def __setattr__(self, attr, val): |
| | 114 | '''Set value of the field.''' |
| | 115 | if self._is_valid(attr): |
| | 116 | self._fields[valid_fields.index(attr)].set(val) |
| | 117 | else: |
| | 118 | raise UMPAAttributeException, attr + ' not allowed' |
| 53 | | def set_time_to_live(self, val): |
| 54 | | pass |
| 55 | | def get_time_to_live(self): |
| 56 | | return self._time_to_live |
| 57 | | time_to_live = property(get_time_to_live, set_time_to_live) |
| 58 | | |
| 59 | | def set_protocol(self, val): |
| 60 | | pass |
| 61 | | def get_protocol(self): |
| 62 | | return self._protocol |
| 63 | | protocol = property(get_protocol, set_protocol) |
| 64 | | |
| 65 | | def set_source_address(self, val): |
| 66 | | pass |
| 67 | | def get_source_address(self): |
| 68 | | return self._source_address |
| 69 | | source_address = property(get_source_address, set_source_address) |
| 70 | | |
| 71 | | def set_destination_address(self, val): |
| 72 | | pass |
| 73 | | def get_destination_address(self): |
| 74 | | return self._destination_address |
| 75 | | destination_address = property(get_destination_address, |
| 76 | | set_destination_address) |
| 77 | | |
| 78 | | def set_option(self, val): |
| 79 | | pass |
| 80 | | def get_option(self): |
| 81 | | return self._option |
| 82 | | option = property(get_option, set_option) |
| | 120 | def __getattr__(self, attr): |
| | 121 | '''Return value of the field.''' |
| | 122 | if self._is_valid(attr): |
| | 123 | return self._fields[valid_fields.index(attr)].get() |
| | 124 | else: |
| | 125 | raise UMPAAttributeException, attr + ' not allowed' |