Presume I have a route table with such entries:
typedef struct route_table_entry {
uint32_t prefix;
uint32_t next_hop;
uint32_t mask;
int interface;
} route_table_entry;
I have a network with 4 hosts and a router, all host are only bound to the router.
I try to ping from h0 to h1. The first request is an ARP request. So as the router I have to first: cache h0 IP and MAC into an ARP table like this:
typedef struct arp_table_entry {
uint32_t ipaddr; /* IP address */
uint8_t mac[ETH_ALEN]; /* MAC address */
int interface; /* Interface number */
int ttl; /* Time to live. */
} arp_table_entry;
But how do I find the interface if the ARP request or ether header doesn't include the interface? Should I use the route table? If so, how? Nevertheless, I get the ARP Request and I send it to all my available interfaces, right?
for (size_t i = 0; i < ROUTER_NUM_INTERFACES; ++i) {
rc = send_packet(interfaces[i], &m);
DIE (rc < 0, "send_message");
}
Isn't that what broadcast means? then I wait for a response, again I get a response an ARP-Reply this time, but I don't know to whom to send it, because I don't how from which interface the request came from, how should I go around it?