/****************************************************************************** * * Name: uip_arp.c * * Description: ARP function * * Copyright: (c) 2005-2050 IC Plus Corp. * All rights reserved. By Chance * *******************************************************************************/ //20051021 #include "arp.h" #include #include /****************************************************************************** * * Function: uip_arp_arpin * * Description: while system get the arp packet, it will send here to process * * Parameters: None * * Returns: None * *******************************************************************************/ void uip_arp_arpin(void) { if(uip_len < sizeof(struct arp_hdr)) { uip_len = 0; return; } uip_len = 0; switch(ARP_BUF->opcode) { case HTONS(ARP_REQUEST): /* ARP request. If it asked for our address, we send out a reply. */ if(ARP_BUF->dipaddr[0] == uip_hostaddr[0] && ARP_BUF->dipaddr[1] == uip_hostaddr[1]) { //add remote mac and ip to arp table /* The reply opcode is 2. */ ARP_BUF->opcode = HTONS(ARP_REPLY); //set the remote MAC address to ethernet header memcpy(ARP_BUF->ethhdr.dest_mac, ARP_BUF->shwaddr, 6); //set the remote MAC address to ARP header memcpy(ARP_BUF->dhwaddr, ARP_BUF->shwaddr, 6); //set the MY MAC address to ethernet header memcpy(ARP_BUF->ethhdr.src_mac, icp_netinfo.MY_MAC, 6); //set the MY MAC address to ARP header memcpy(ARP_BUF->shwaddr, icp_netinfo.MY_MAC, 6); //set remote ipaddress ARP_BUF->dipaddr[0] = ARP_BUF->sipaddr[0]; ARP_BUF->dipaddr[1] = ARP_BUF->sipaddr[1]; //set the my ip address ARP_BUF->sipaddr[0] = uip_hostaddr[0]; ARP_BUF->sipaddr[1] = uip_hostaddr[1]; ARP_BUF->ethhdr.type = HTONS(UIP_ETHTYPE_ARP); uip_len = sizeof(struct arp_hdr); } else { uip_len = 0; } break; case HTONS(ARP_REPLY): uip_len = 0; return; /* ARP reply. We insert or update the ARP table if it was meant for us. */ // printf("\n\r Not support!"); break; } return; }