TEST_F(ARPTest, DefaultContructor) { ARP arp; EXPECT_EQ(arp.target_ip_addr(), IPv4Address()); EXPECT_EQ(arp.sender_ip_addr(), IPv4Address()); EXPECT_EQ(arp.target_hw_addr(), empty_addr); EXPECT_EQ(arp.target_hw_addr(), empty_addr); EXPECT_EQ(arp.pdu_type(), PDU::ARP); }
void EthernetFrame::macdata2Arp(ARP &a) { WORD hardware_type = 0; WORD protocol_type = 0; BYTE hardware_address_length = 0; BYTE protocol_address_length = 0; WORD operation_code = 0; BYTE source_hardware_address[6] = {0}; DWORD source_protocol_address = 0; BYTE target_hardware_address[6] = {0}; DWORD target_protocol_address = 0; memcpy(&hardware_type, MACDATA, 2); memcpy(&protocol_type, MACDATA+2, 2); memcpy(&hardware_address_length, MACDATA+4, 1); memcpy(&protocol_address_length, MACDATA+5, 1); memcpy(&operation_code, MACDATA+6, 2); memcpy(source_hardware_address, MACDATA+8, 6); memcpy(&source_protocol_address, MACDATA+14, 4); memcpy(target_hardware_address, MACDATA+18, 6); memcpy(&target_protocol_address, MACDATA+24, 4); a.setHardwareType(hardware_type); a.setProtocolType(protocol_type); a.setHardwareAddressLength(hardware_address_length); a.setProtocolAddressLength(protocol_address_length); a.setOperationCode(operation_code); a.setSourceHardwareAddress(source_hardware_address); a.setSourceProtocolAddress(source_protocol_address); a.setTargetHardwareAddress(target_hardware_address); a.setTargetProtocolAddress(target_protocol_address); }
EthernetII ARP::make_arp_request(ipaddress_type target, ipaddress_type sender, const hwaddress_type& hw_snd) { // Create ARP packet and set its attributes ARP arp; arp.target_ip_addr(target); arp.sender_ip_addr(sender); arp.sender_hw_addr(hw_snd); arp.opcode(REQUEST); // Create the EthernetII PDU with the ARP PDU as its inner PDU return EthernetII(EthernetII::BROADCAST, hw_snd) / arp; }
TEST_F(ARPTest, TargetHWAddr) { ARP arp; arp.target_hw_addr(hw_addr1); EXPECT_EQ(arp.target_hw_addr(), hw_addr1); }
TEST_F(ARPTest, TargetIPAddrInt) { ARP arp; arp.target_ip_addr(addr1); EXPECT_EQ(arp.target_ip_addr(), addr1); }
TEST_F(ARPTest, SenderIPAddrInt) { ARP arp; arp.sender_ip_addr(addr1); EXPECT_EQ(arp.sender_ip_addr(), addr1); }
TEST_F(ARPTest, Opcode) { ARP arp; arp.opcode(ARP::REQUEST); EXPECT_EQ(arp.opcode(), ARP::REQUEST); }
void ARPTest::test_equals(const ARP& arp1, const ARP& arp2) { EXPECT_EQ(arp1.opcode(), arp2.opcode()); ASSERT_EQ(arp1.hw_addr_length(), arp2.hw_addr_length()); EXPECT_EQ(arp1.hw_addr_format(), arp2.hw_addr_format()); ASSERT_EQ(arp1.prot_addr_length(), arp2.prot_addr_length()); EXPECT_EQ(arp1.prot_addr_format(), arp2.prot_addr_format()); EXPECT_EQ(arp1.sender_ip_addr(), arp2.sender_ip_addr()); EXPECT_EQ(arp1.target_ip_addr(), arp2.target_ip_addr()); EXPECT_EQ(arp1.sender_hw_addr(), arp2.sender_hw_addr()); EXPECT_EQ(arp1.target_hw_addr(), arp2.target_hw_addr()); EXPECT_EQ(arp1.inner_pdu() != NULL, arp2.inner_pdu() != NULL); }
TEST_F(ARPTest, HWAddrLength) { ARP arp; arp.hw_addr_length(0xd1); EXPECT_EQ(arp.hw_addr_length(), 0xd1); }
TEST_F(ARPTest, HWAddrFormat) { ARP arp; arp.hw_addr_format(0x45fa); EXPECT_EQ(arp.hw_addr_format(), 0x45fa); }
TEST_F(ARPTest, ProtAddrLength) { ARP arp; arp.prot_addr_length(0x4f); EXPECT_EQ(arp.prot_addr_length(), 0x4f); }
TEST_F(ARPTest, ProtAddrFormat) { ARP arp; arp.prot_addr_format(0x45fa); EXPECT_EQ(arp.prot_addr_format(), 0x45fa); }
TEST_F(ARPTest, SenderHWAddr) { ARP arp; arp.sender_hw_addr(hw_addr1); EXPECT_EQ(arp.sender_hw_addr(), hw_addr1); }