// // Created by epagris on 2022.12.10.. // #include #include "arp_cache.h" #include "dynmem.h" ArpCache *arpc_new(uint16_t size) { ArpCache * arcp = (ArpCache *) dynmem_alloc(2 * sizeof(uint16_t) + size * sizeof(ArpEntry)); arcp->size = size; arcp->fill = 0; return arcp; } void arpc_free(ArpCache *aprc) { dynmem_free(aprc); } void arpc_learn(ArpCache *arpc, const ArpEntry *newEntry) { // TODO: nagyon dummy... for (uint16_t i = 0; i < arpc->fill; i++) { ArpEntry * entry = arpc->entries + i; if (!memcmp(entry->eth, newEntry->eth, ETH_HW_ADDR_LEN) && (entry->ip == newEntry->ip)) { return; } } // if not found... arpc->entries[arpc->fill++] = *newEntry; } const ArpEntry *arpc_get(ArpCache *arpc, ip4_addr ip) { for (uint16_t i = 0; i < arpc->fill; i++) { ArpEntry * entry = arpc->entries + i; if (entry->ip == ip) { return entry; } } return NULL; }