52 lines
1.1 KiB
C
52 lines
1.1 KiB
C
#ifndef ETHERLIB_TEST_ARP_CACHE_H
|
|
#define ETHERLIB_TEST_ARP_CACHE_H
|
|
|
|
#include "prefab/packet_parsers/ethernet_frame.h"
|
|
#include "prefab/packet_parsers/ipv4_types.h"
|
|
|
|
/**
|
|
* ARP cache entry record.
|
|
*/
|
|
typedef struct {
|
|
EthernetAddress eth; ///< Ethernet address
|
|
ip4_addr ip; ///< IPv4 address
|
|
} ArpEntry;
|
|
|
|
/**
|
|
* ARP cache class.
|
|
*/
|
|
typedef struct {
|
|
uint16_t size; ///< Number of cache entries
|
|
uint16_t fill; ///< Fill level
|
|
ArpEntry entries[]; ///< Cache entries
|
|
} ArpCache;
|
|
|
|
/**
|
|
* Create new ARP cache table.
|
|
* @param size Number of available entries
|
|
* @return Pointer to newly allocated ARP cache
|
|
*/
|
|
ArpCache * arpc_new(uint16_t size);
|
|
|
|
/**
|
|
* Learn new assignment.
|
|
* @param arpc Pointer to ARP cache
|
|
* @param newEntry Pointer to map newEntry
|
|
*/
|
|
void arpc_learn(ArpCache * arpc, const ArpEntry * newEntry);
|
|
|
|
/**
|
|
* Get entry by IP-address.
|
|
* @param ip IP address
|
|
* @return Pointer to matching entry OR NULL if not found
|
|
*/
|
|
const ArpEntry *arpc_get(ArpCache *arpc, ip4_addr ip);
|
|
|
|
/**
|
|
* Free ARP cache.
|
|
* @param aprc Pointer to existing ARP cache.
|
|
*/
|
|
void arpc_free(ArpCache * aprc);
|
|
|
|
#endif //ETHERLIB_TEST_ARP_CACHE_H
|