88 uip_ipaddr_t srcipaddr, destipaddr;
94 #define ARP_HWTYPE_ETH 1
103 {{0xff,0xff,0xff,0xff,0xff,0xff}};
106 static uip_ipaddr_t ipaddr;
109 static uint8_t arptime;
110 static uint8_t tmpage;
112 #define BUF ((struct arp_hdr *)&uip_buf[0])
113 #define IPBUF ((struct ethip_hdr *)&uip_buf[0])
118 #define PRINTF(...) printf(__VA_ARGS__)
133 memset(&arp_table[i].ipaddr, 0, 4);
149 struct arp_entry *tabptr;
153 tabptr = &arp_table[i];
154 if(uip_ipaddr_cmp(&tabptr->ipaddr, &uip_all_zeroes_addr) &&
156 memset(&tabptr->ipaddr, 0, 4);
164 uip_arp_update(uip_ipaddr_t *ipaddr,
struct uip_eth_addr *ethaddr)
166 register struct arp_entry *tabptr = arp_table;
172 tabptr = &arp_table[i];
175 if(!uip_ipaddr_cmp(&tabptr->ipaddr, &uip_all_zeroes_addr)) {
179 if(uip_ipaddr_cmp(ipaddr, &tabptr->ipaddr)) {
182 memcpy(tabptr->ethaddr.addr, ethaddr->addr, 6);
183 tabptr->time = arptime;
196 tabptr = &arp_table[i];
197 if(uip_ipaddr_cmp(&tabptr->ipaddr, &uip_all_zeroes_addr)) {
204 if(i == UIP_ARPTAB_SIZE) {
208 tabptr = &arp_table[i];
209 if(arptime - tabptr->time > tmpage) {
210 tmpage = arptime - tabptr->time;
215 tabptr = &arp_table[i];
221 memcpy(tabptr->ethaddr.addr, ethaddr->addr, 6);
222 tabptr->time = arptime;
246 if((IPBUF->srcipaddr[0] & uip_netmask[0]) !=
247 (uip_hostaddr[0] & uip_netmask[0])) {
250 if((IPBUF->srcipaddr[1] & uip_netmask[1]) !=
251 (uip_hostaddr[1] & uip_netmask[1])) {
254 uip_arp_update(IPBUF->srcipaddr, &(IPBUF->ethhdr.src));
286 if(
uip_len <
sizeof(
struct arp_hdr)) {
292 switch(BUF->opcode) {
298 PRINTF(
"uip_arp_arpin: request for %d.%d.%d.%d (we are %d.%d.%d.%d)\n",
299 BUF->dipaddr.u8[0], BUF->dipaddr.u8[1],
300 BUF->dipaddr.u8[2], BUF->dipaddr.u8[3],
301 uip_hostaddr.u8[0], uip_hostaddr.u8[1],
302 uip_hostaddr.u8[2], uip_hostaddr.u8[3]);
303 if(uip_ipaddr_cmp(&BUF->dipaddr, &uip_hostaddr)) {
307 uip_arp_update(&BUF->sipaddr, &BUF->shwaddr);
311 memcpy(BUF->dhwaddr.addr, BUF->shwaddr.addr, 6);
312 memcpy(BUF->shwaddr.addr,
uip_lladdr.addr, 6);
313 memcpy(BUF->ethhdr.src.addr,
uip_lladdr.addr, 6);
314 memcpy(BUF->ethhdr.dest.addr, BUF->dhwaddr.addr, 6);
319 BUF->ethhdr.type =
UIP_HTONS(UIP_ETHTYPE_ARP);
320 uip_len =
sizeof(
struct arp_hdr);
326 if(uip_ipaddr_cmp(&BUF->dipaddr, &uip_hostaddr)) {
327 uip_arp_update(&BUF->sipaddr, &BUF->shwaddr);
365 struct arp_entry *tabptr = arp_table;
375 if(uip_ipaddr_cmp(&IPBUF->destipaddr, &uip_broadcast_addr)) {
376 memcpy(IPBUF->ethhdr.dest.addr, broadcast_ethaddr.addr, 6);
377 }
else if(IPBUF->destipaddr.u8[0] == 224) {
379 IPBUF->ethhdr.dest.addr[0] = 0x01;
380 IPBUF->ethhdr.dest.addr[1] = 0x00;
381 IPBUF->ethhdr.dest.addr[2] = 0x5e;
382 IPBUF->ethhdr.dest.addr[3] = IPBUF->destipaddr.u8[1];
383 IPBUF->ethhdr.dest.addr[4] = IPBUF->destipaddr.u8[2];
384 IPBUF->ethhdr.dest.addr[5] = IPBUF->destipaddr.u8[3];
397 if(uip_ipaddr_cmp(&ipaddr, &tabptr->ipaddr)) {
403 if(i == UIP_ARPTAB_SIZE) {
407 memset(BUF->ethhdr.dest.addr, 0xff, 6);
408 memset(BUF->dhwaddr.addr, 0x00, 6);
409 memcpy(BUF->ethhdr.src.addr,
uip_lladdr.addr, 6);
410 memcpy(BUF->shwaddr.addr,
uip_lladdr.addr, 6);
416 BUF->protocol =
UIP_HTONS(UIP_ETHTYPE_IP);
419 BUF->ethhdr.type =
UIP_HTONS(UIP_ETHTYPE_ARP);
423 uip_len =
sizeof(
struct arp_hdr);
428 memcpy(IPBUF->ethhdr.dest.addr, tabptr->ethaddr.addr, 6);
430 memcpy(IPBUF->ethhdr.src.addr,
uip_lladdr.addr, 6);
432 IPBUF->ethhdr.type =
UIP_HTONS(UIP_ETHTYPE_IP);
void uip_arp_out(void)
Prepend Ethernet header to an outbound IP packet and see if we need to send out an ARP request...
uip_len
The length of the packet in the uip_buf buffer.
CCIF uip_lladdr_t uip_lladdr
Host L2 address.
#define uip_ipaddr_maskcmp(addr1, addr2, mask)
Compare two IP addresses with netmasks.
#define UIP_ARPTAB_SIZE
The size of the ARP table.
void uip_arp_timer(void)
Periodic ARP processing function.
void uip_arp_init(void)
Initialize the ARP module.
#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.
Macros and definitions for the ARP module.
#define uip_ipaddr_copy(dest, src)
Copy an IP address from one place to another.
void uip_arp_arpin(void)
ARP processing for incoming IP packets.
uip_appdata
Pointer to the application data in the packet buffer.