96 #define ARP_HWTYPE_ETH 1
105 {{0xff,0xff,0xff,0xff,0xff,0xff}};
106 static const u16_t broadcast_ipaddr[2] = {0xffff,0xffff};
115 #define BUF ((struct arp_hdr *)&uip_buf[0])
116 #define IPBUF ((struct ethip_hdr *)&uip_buf[0])
121 #define PRINTF(...) printf(__VA_ARGS__)
136 memset(&arp_table[i].ipaddr, 0, 4);
152 struct arp_entry *tabptr;
156 tabptr = &arp_table[i];
159 memset(&tabptr->ipaddr, 0, 4);
169 register struct arp_entry *tabptr = arp_table;
175 tabptr = &arp_table[i];
185 memcpy(tabptr->ethaddr.addr, ethaddr->addr, 6);
186 tabptr->time = arptime;
199 tabptr = &arp_table[i];
207 if(i == UIP_ARPTAB_SIZE) {
211 tabptr = &arp_table[i];
212 if(arptime - tabptr->time > tmpage) {
213 tmpage = arptime - tabptr->time;
218 tabptr = &arp_table[i];
224 memcpy(tabptr->ethaddr.addr, ethaddr->addr, 6);
225 tabptr->time = arptime;
249 if((IPBUF->srcipaddr[0] & uip_netmask[0]) !=
250 (uip_hostaddr[0] & uip_netmask[0])) {
253 if((IPBUF->srcipaddr[1] & uip_netmask[1]) !=
254 (uip_hostaddr[1] & uip_netmask[1])) {
257 uip_arp_update(IPBUF->srcipaddr, &(IPBUF->ethhdr.src));
289 if(
uip_len <
sizeof(
struct arp_hdr)) {
295 switch(BUF->opcode) {
301 PRINTF(
"uip_arp_arpin: request for %d.%d.%d.%d (we are %d.%d.%d.%d)\n",
302 BUF->dipaddr.u8[0], BUF->dipaddr.u8[1],
303 BUF->dipaddr.u8[2], BUF->dipaddr.u8[3],
304 uip_hostaddr.u8[0], uip_hostaddr.u8[1],
305 uip_hostaddr.u8[2], uip_hostaddr.u8[3]);
310 uip_arp_update(&BUF->sipaddr, &BUF->shwaddr);
314 memcpy(BUF->dhwaddr.addr, BUF->shwaddr.addr, 6);
315 memcpy(BUF->shwaddr.addr, uip_ethaddr.addr, 6);
316 memcpy(BUF->ethhdr.src.addr, uip_ethaddr.addr, 6);
317 memcpy(BUF->ethhdr.dest.addr, BUF->dhwaddr.addr, 6);
322 BUF->ethhdr.type =
UIP_HTONS(UIP_ETHTYPE_ARP);
323 uip_len =
sizeof(
struct arp_hdr);
330 uip_arp_update(&BUF->sipaddr, &BUF->shwaddr);
368 struct arp_entry *tabptr = arp_table;
379 memcpy(IPBUF->ethhdr.dest.addr, broadcast_ethaddr.addr, 6);
380 }
else if(IPBUF->destipaddr.u8[0] == 224) {
382 IPBUF->ethhdr.dest.addr[0] = 0x01;
383 IPBUF->ethhdr.dest.addr[1] = 0x00;
384 IPBUF->ethhdr.dest.addr[2] = 0x5e;
385 IPBUF->ethhdr.dest.addr[3] = IPBUF->destipaddr.u8[1];
386 IPBUF->ethhdr.dest.addr[4] = IPBUF->destipaddr.u8[2];
387 IPBUF->ethhdr.dest.addr[5] = IPBUF->destipaddr.u8[3];
406 if(i == UIP_ARPTAB_SIZE) {
410 memset(BUF->ethhdr.dest.addr, 0xff, 6);
411 memset(BUF->dhwaddr.addr, 0x00, 6);
412 memcpy(BUF->ethhdr.src.addr, uip_ethaddr.addr, 6);
413 memcpy(BUF->shwaddr.addr, uip_ethaddr.addr, 6);
419 BUF->protocol =
UIP_HTONS(UIP_ETHTYPE_IP);
422 BUF->ethhdr.type =
UIP_HTONS(UIP_ETHTYPE_ARP);
426 uip_len =
sizeof(
struct arp_hdr);
431 memcpy(IPBUF->ethhdr.dest.addr, tabptr->ethaddr.addr, 6);
433 memcpy(IPBUF->ethhdr.src.addr, uip_ethaddr.addr, 6);
435 IPBUF->ethhdr.type =
UIP_HTONS(UIP_ETHTYPE_IP);