/****************************************************************************** * * Name: icmp.c * * Description: ICMP function * * Copyright: (c) 2005-2050 IC Plus Corp. * All rights reserved. By Chance * *******************************************************************************/ //20051021 #include #include #include "icmp.h" /****************************************************************************** * * Function: ICMP_Process * * Description: Handle ICMP packet for ping * * Parameters: NONE * * Returns: NONE * *******************************************************************************/ void ICMP_Process() { u16_t Rx_data_len=0;//Rx_sum=0,i,sum=0; //add ipchecksum //if(icmp_header->type==ICMP_ECHO_REQUEST)//ICMP Echo //{ if ((uip_len-(UIP_LLH_LEN+IP_HEADER_LENGTH)) >= sizeof (icmp_header)) { //Rx_sum=icmp_header->icmpchksum;//checksum of receive packet //icmp_header->icmpchksum=0; //re calculate the checksum //sum=~(uip_chksum((u16_t *)&uip_buf[(UIP_LLH_LEN+IP_HEADER_LENGTH)], (uip_len-UIP_LLH_LEN-IP_HEADER_LENGTH))) ; //if ((sum-Rx_sum)== 0) //{ switch (icmp_header->type & 0xff) { case ICMP_ECHO_REQUEST: Rx_data_len=iphdr->len-(IP_HEADER_LENGTH+ICMP_Header_Len); //Ethernet Header*************** //Set Remote MAC address memcpy(rx_eth->dest_mac, rx_eth->src_mac, 6); //Set My MAC address memcpy(rx_eth->src_mac, icp_netinfo.MY_MAC, 6); //Type at the same with echo request packet //IP Header******************** // //set remote ip address memcpy(iphdr->destipaddr, iphdr->srcipaddr, 4); //set my ip address iphdr->srcipaddr[0]=uip_hostaddr[0]; iphdr->srcipaddr[1]=uip_hostaddr[1]; //set ipid ipid++; iphdr->ipid[0]=ipid>>8; iphdr->ipid[1]=ipid & 0xff; //set ip header checksum iphdr->ipchksum=0; //iphdr->ipchksum=(~(uip_ipchksum())); //ICMP Header****************** //Set ICMP TYPE icmp_header->type=ICMP_ECHO_REPLY; //icmp_header->icode=0; use the same with echo request //icmp_header->id=0; use the same with echo request //icmp_header->seqno=0; use the same with echo request //Set ICMP Checksum icmp_header->icmpchksum=0; //icmp_header->icmpchksum=~(uip_chksum((u16_t *)&uip_buf[(UIP_LLH_LEN+IP_HEADER_LENGTH)], (uip_len-UIP_LLH_LEN-IP_HEADER_LENGTH))) ; uip_len=UIP_LLH_LEN+IP_HEADER_LENGTH+ICMP_Header_Len+Rx_data_len; break; /* case 0x03: printf ("ICMP error: destination unreachable\n"); break; case 0x04: printf ("ICMP error: source quench\n"); break; case 0x05: printf ("ICMP error: redirect\n"); break; case 0x0b: printf ("ICMP error: time-to-live exceeded\n"); break; case 0x0c: printf ("ICMP error: parameter problem\n"); break;*/ default: uip_len = 0; break; }//switch end //}//checksum end }//uip_len end else { uip_len=0; return; } //} }