1 /* 2 * Copyright 2005, Ingo Weinhold <bonefish@cs.tu-berlin.de>. 3 * All rights reserved. Distributed under the terms of the MIT License. 4 */ 5 6 #ifndef _BOOT_ARP_H 7 #define _BOOT_ARP_H 8 9 #include <boot/net/Ethernet.h> 10 11 #include <OS.h> 12 13 class ARPService : public EthernetSubService { 14 // actually ARP for IP over ethernet 15 public: 16 ARPService(EthernetService *ethernet); 17 virtual ~ARPService(); 18 19 status_t Init(); 20 21 virtual uint16 EthernetProtocol() const; 22 23 virtual void HandleEthernetPacket(EthernetService *ethernet, 24 const mac_addr_t &targetAddress, const void *data, size_t size); 25 26 status_t GetMACForIP(ip_addr_t ip, mac_addr_t &mac); 27 28 private: 29 enum { MAP_ENTRY_COUNT = 10 }; 30 enum { ARP_REQUEST_RETRY_COUNT = 3 }; 31 enum { ARP_REPLY_TIMEOUT = 5000 }; 32 33 struct MapEntry { 34 int32 age; 35 ip_addr_t ip; 36 mac_addr_t mac; 37 }; 38 39 status_t _SendARPPacket(ip_addr_t ip, const mac_addr_t &mac, uint16 opcode); 40 41 MapEntry *_FindEntry(ip_addr_t ip); 42 void _PutEntry(ip_addr_t ip, const mac_addr_t &mac); 43 44 EthernetService *fEthernet; 45 int32 fAge; 46 MapEntry fEntries[MAP_ENTRY_COUNT]; 47 }; 48 49 #endif // _BOOT_ARP_H 50