def __build_node_information_message(class_object, type, code, payload = None): #Build ICMP6 header icmp_packet = ICMP6() icmp_packet.set_type(type) icmp_packet.set_code(code) #Pack ICMP payload qtype = 0 flags = 0 nonce = [0x00] * 8 icmp_bytes = struct.pack('>H', qtype) icmp_bytes += struct.pack('>H', flags) icmp_bytes += array.array('B', nonce).tostring() if payload is not None: icmp_bytes += array.array('B', payload).tostring() icmp_payload = Data() icmp_payload.set_data(icmp_bytes) #Link payload to header icmp_packet.contains(icmp_payload) return icmp_packet
def __build_error_message(class_object, type, code, data, originating_packet_data): #Build ICMP6 header icmp_packet = ICMP6() icmp_packet.set_type(type) icmp_packet.set_code(code) #Pack ICMP payload icmp_bytes = array.array('B', data).tostring() if (originating_packet_data is not None): icmp_bytes += array.array('B', originating_packet_data).tostring() icmp_payload = Data() icmp_payload.set_data(icmp_bytes) #Link payload to header icmp_packet.contains(icmp_payload) return icmp_packet
def __build_echo_message(class_object, type, id, sequence_number, arbitrary_data): #Build ICMP6 header icmp_packet = ICMP6() icmp_packet.set_type(type) icmp_packet.set_code(0) #Pack ICMP payload icmp_bytes = struct.pack('>H', id) icmp_bytes += struct.pack('>H', sequence_number) if (arbitrary_data is not None): icmp_bytes += array.array('B', arbitrary_data).tostring() icmp_payload = Data() icmp_payload.set_data(icmp_bytes) #Link payload to header icmp_packet.contains(icmp_payload) return icmp_packet
def test_30_radiotap_length_filed_with_payload(self): """Test RadioTap header length field with payload""" # RadioTap from scratch calling get_length() and then get_packet() rt = RadioTap() self.assertEqual(rt.get_header_length(), 0x08) data = Data(b"aa") rt.contains(data) self.assertEqual(rt.get_header_length(), 0x08) # The header length is the same raw_packet = rt.get_packet() self.assertEqual(raw_packet, b"\x00\x00\x08\x00\x00\x00\x00\x00aa")
def __build_neighbor_message(class_object, msg_type, target_address): #Build ICMP6 header icmp_packet = ICMP6() icmp_packet.set_type(msg_type) icmp_packet.set_code(0) # Flags + Reserved icmp_bytes = array.array('B', [0x00] * 4).tostring() # Target Address: The IP address of the target of the solicitation. # It MUST NOT be a multicast address. icmp_bytes += array.array('B', IP6_Address(target_address).as_bytes()).tostring() icmp_payload = Data() icmp_payload.set_data(icmp_bytes) #Link payload to header icmp_packet.contains(icmp_payload) return icmp_packet