87 #define ARP_HWTYPE_ETH 1
96 {{0xff,0xff,0xff,0xff,0xff,0xff}};
97 static const uint16_t broadcast_ipaddr[2] = {0xffff,0xffff};
101 static uint8_t arptime;
102 static uint8_t tmpage;
107 #define PRINTF(...) printf(__VA_ARGS__)
112 const uip_ipaddr_t uip_all_zeroes_addr;
125 memset(&arp_table[i].ipaddr, 0, 4);
141 struct arp_entry *tabptr;
146 tabptr = &arp_table[i];
149 memset(&tabptr->ipaddr, 0, 4);
159 register struct arp_entry *tabptr = arp_table;
166 tabptr = &arp_table[i];
176 memcpy(tabptr->ethaddr.addr, ethaddr->addr, 6);
177 tabptr->time = arptime;
190 tabptr = &arp_table[i];
198 if(i == UIP_ARPTAB_SIZE) {
202 tabptr = &arp_table[i];
203 if(arptime - tabptr->time > tmpage) {
204 tmpage = arptime - tabptr->time;
209 tabptr = &arp_table[i];
214 uip_ip4addr_copy(&tabptr->ipaddr, ipaddr);
215 memcpy(tabptr->ethaddr.addr, ethaddr->addr, 6);
216 tabptr->time = arptime;
220 ip64_arp_arp_input(
const uint8_t *packet, uint16_t packet_len)
222 struct arp_hdr *arphdr = (
struct arp_hdr *)packet;
224 if(packet_len <
sizeof(
struct arp_hdr)) {
225 printf(
"ip64_arp_arp_input: len too small %d\n", packet_len);
229 switch(arphdr->opcode) {
233 printf(
"ip64_arp_arp_input: request for %d.%d.%d.%d (we are %d.%d.%d.%d)\n",
234 arphdr->dipaddr.u8[0], arphdr->dipaddr.u8[1],
235 arphdr->dipaddr.u8[2], arphdr->dipaddr.u8[3],
236 ip64_get_hostaddr()->u8[0], ip64_get_hostaddr()->u8[1],
237 ip64_get_hostaddr()->u8[2], ip64_get_hostaddr()->u8[3]);
242 arp_update(&arphdr->sipaddr, &arphdr->shwaddr);
246 memcpy(arphdr->dhwaddr.addr, arphdr->shwaddr.addr, 6);
249 memcpy(arphdr->ethhdr.dest.addr, arphdr->dhwaddr.addr, 6);
251 uip_ip4addr_copy(&arphdr->dipaddr, &arphdr->sipaddr);
252 uip_ip4addr_copy(&arphdr->sipaddr, ip64_get_hostaddr());
254 arphdr->ethhdr.type =
UIP_HTONS(IP64_ETH_TYPE_ARP);
255 return sizeof(
struct arp_hdr);
262 arp_update(&arphdr->sipaddr, &arphdr->shwaddr);
271 ip64_arp_check_cache(
const uint8_t *nlhdr)
273 struct ipv4_hdr *ipv4_hdr = (
struct ipv4_hdr *)nlhdr;
275 struct arp_entry *tabptr = arp_table;
277 printf(
"check cache %d.%d.%d.%d\n",
283 printf(
"Return 1\n");
285 }
else if(ipv4_hdr->destipaddr.u8[0] == 224) {
294 ip64_get_netmask())) {
298 uip_ip4addr_copy(&ipaddr, ip64_get_draddr());
301 uip_ip4addr_copy(&ipaddr, &ipv4_hdr->destipaddr);
310 if(i == UIP_ARPTAB_SIZE) {
319 ip64_arp_create_ethhdr(uint8_t *llhdr,
const uint8_t *nlhdr)
321 struct arp_entry *tabptr = arp_table;
322 struct ipv4_hdr *ipv4_hdr = (
struct ipv4_hdr *)nlhdr;
336 memcpy(ðhdr->dest.addr, &broadcast_ethaddr.addr, 6);
337 }
else if(ipv4_hdr->destipaddr.u8[0] == 224) {
339 ethhdr->dest.addr[0] = 0x01;
340 ethhdr->dest.addr[1] = 0x00;
341 ethhdr->dest.addr[2] = 0x5e;
342 ethhdr->dest.addr[3] = ipv4_hdr->destipaddr.u8[1];
343 ethhdr->dest.addr[4] = ipv4_hdr->destipaddr.u8[2];
344 ethhdr->dest.addr[5] = ipv4_hdr->destipaddr.u8[3];
351 ip64_get_netmask())) {
355 uip_ip4addr_copy(&ipaddr, ip64_get_draddr());
358 uip_ip4addr_copy(&ipaddr, &ipv4_hdr->destipaddr);
367 if(i == UIP_ARPTAB_SIZE) {
371 memcpy(ethhdr->dest.addr, tabptr->ethaddr.addr, 6);
376 ethhdr->type =
UIP_HTONS(IP64_ETH_TYPE_IP);
381 ip64_arp_create_arp_request(uint8_t *llhdr,
const uint8_t *nlhdr)
383 struct ipv4_hdr *ipv4_hdr = (
struct ipv4_hdr *)nlhdr;
384 struct arp_hdr *arp_hdr = (
struct arp_hdr *)llhdr;
389 ip64_get_netmask())) {
393 uip_ip4addr_copy(&ipaddr, ip64_get_draddr());
396 uip_ip4addr_copy(&ipaddr, &ipv4_hdr->destipaddr);
399 memset(arp_hdr->ethhdr.dest.addr, 0xff, 6);
400 memset(arp_hdr->dhwaddr.addr, 0x00, 6);
404 uip_ip4addr_copy(&arp_hdr->dipaddr, &ipaddr);
405 uip_ip4addr_copy(&arp_hdr->sipaddr, ip64_get_hostaddr());
406 arp_hdr->opcode =
UIP_HTONS(ARP_REQUEST);
407 arp_hdr->hwtype =
UIP_HTONS(ARP_HWTYPE_ETH);
408 arp_hdr->protocol =
UIP_HTONS(IP64_ETH_TYPE_IP);
410 arp_hdr->protolen = 4;
411 arp_hdr->ethhdr.type =
UIP_HTONS(IP64_ETH_TYPE_ARP);
415 return sizeof(
struct arp_hdr);
#define uip_ipaddr_maskcmp(addr1, addr2, mask)
Compare two IP addresses with netmasks.
#define UIP_ARPTAB_SIZE
The size of the ARP table.
#define uip_ip4addr_cmp(addr1, addr2)
Compare two IP addresses.
#define UIP_HTONS(n)
Convert 16-bit quantity from host byte order to network byte order.
#define UIP_ARP_MAXAGE
The maximum age of ARP table entries measured in 10ths of seconds.
#define UIP_LLH_LEN
The link level header length.
Representation of an IP address.
#define uip_ipaddr_to_quad(a)
Convert an IP address to four bytes separated by commas.
#define uip_ipaddr(addr, addr0, addr1, addr2, addr3)
Construct an IP address from four bytes.
uip_appdata
Pointer to the application data in the packet buffer.