def Redirected_Header(class_object, original_packet): option_data = struct.pack('>BBBBBB', 0x00, 0x00, 0x00, 0x00, 0x00, 0x00) # Reserved bytes option_data += ImpactPacket.array_tobytes( array.array("B", original_packet)) option_length = (len(option_data) + 4) / 8 return class_object.__build_option(NDP_Option.REDIRECTED_HEADER, option_length, option_data)
def Neighbor_Advertisement(class_object, router_flag, solicited_flag, override_flag, target_address): flag_byte = 0x00 if (router_flag): flag_byte |= 0x80 if (solicited_flag): flag_byte |= 0x40 if (override_flag): flag_byte |= 0x20 message_data = struct.pack('>BBBB', flag_byte, 0x00, 0x00, 0x00) #Flag byte and three reserved bytes message_data += ImpactPacket.array_tobytes(target_address.as_bytes()) return class_object.__build_message(NDP.NEIGHBOR_ADVERTISEMENT, message_data)
def Prefix_Information(class_object, prefix_length, on_link_flag, autonomous_flag, valid_lifetime, preferred_lifetime, prefix): flag_byte = 0x00 if (on_link_flag): flag_byte |= 0x80 if (autonomous_flag): flag_byte |= 0x40 option_data = struct.pack('>BBLL', prefix_length, flag_byte, valid_lifetime, preferred_lifetime) option_data += struct.pack('>L', 0) #Reserved bytes option_data += ImpactPacket.array_tobytes(array.array("B", prefix)) option_length = 4 return class_object.__build_option(NDP_Option.PREFIX_INFORMATION, option_length, option_data)
def getter(self, o): b = ip.array_tobytes(o.header.get_bytes()[self.index:self.index + 3]) #unpack requires a string argument of length 4 and b is 3 bytes long (value, ) = struct.unpack('!L', b'\x00' + b) return value
def Redirect(class_object, target_address, destination_address): message_data = struct.pack('>L', 0)# Reserved bytes message_data += ImpactPacket.array_tobytes(target_address.as_bytes()) message_data += ImpactPacket.array_tobytes(destination_address.as_bytes()) return class_object.__build_message(NDP.REDIRECT, message_data)
def Neighbor_Solicitation(class_object, target_address): message_data = struct.pack('>L', 0) #Reserved bytes message_data += ImpactPacket.array_tobytes(target_address.as_bytes()) return class_object.__build_message(NDP.NEIGHBOR_SOLICITATION, message_data)
def __Link_Layer_Address(class_object, option_type, link_layer_address): option_length = (len(link_layer_address) / 8) + 1 option_data = ImpactPacket.array_tobytes(array.array("B", link_layer_address)) return class_object.__build_option(option_type, option_length, option_data)