Exemplo n.º 1
0
void icmp_received(unsigned char *etherframe,int etherlen)
{
	char tmp[80];

	ethernet_frame_str *ef = (ethernet_frame_str *)etherframe;
	ip_headder_str *ip = (ip_headder_str *)&ef->payload[0];

	// イーサフレームのMACアドレスを入れ替える
	memcpy(tmp,ef->dst_macaddr,6);
	memcpy(ef->dst_macaddr,ef->src_macaddr,6);
	memcpy(ef->src_macaddr,tmp,6);

	// IPヘッダのIPアドレスを入れ替える
	unsigned long tmpaddr = ip->dest_addr;
	ip->dest_addr = ip->src_addr;
	ip->src_addr = tmpaddr;
	ip->checksum = 0;
	
	// IPヘッダの処理
	unsigned char *icmpdata = (unsigned char *)ip + (ip->version_length & 0x0f) * 4;

/*
	sprintf(tmp,"\n[ICMP received %d bytes]\n",etherlen);
	sci_puts(tmp);
	packet_dump(etherframe,etherlen);
	sprintf(tmp,"ICMP Type %02x , process %d , ping seq %d \n",icmpdata[0], (icmpdata[5] << 8) | icmpdata[4] , (icmpdata[7] << 8) | icmpdata[6]);
	sci_puts(tmp);
*/

	if(icmpdata[0] == 0x00) // 受信したものがPingの応答だったら
	{
		printf("Reply from %ld.%ld.%ld.%ld:",ip->dest_addr & 0xff,(ip->dest_addr >> 8) & 0xff,(ip->dest_addr >> 16) & 0xff,(ip->dest_addr >> 24) & 0xff);
		printf("bytes=%d ",__builtin_rx_revw(ip->dglength));
		printf("time=%ld[us] ttl=%d\n",timer_get_us() - g_ping_timer,ip->ttl);
		g_ping_process = 0; // Pingは進行していない
		return ;
	}
int
half_word_swap (int arg)
{
  return __builtin_rx_revw (arg);
}