⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 icmp.c

📁 这是个S3C44B0的boot源代码程序
💻 C
字号:
#include "utils.h"
#include "console.h"
#include "eth.h"
#include "skbuff.h"
#include "ip.h"
#include "icmp.h"

static unsigned long client_ip;

static int icmp_send_echo(struct sk_buff *skb)
{
	struct icmphdr *icmp_hdr, *icmp_echo;	
	unsigned int tmp, sum, i, cnt;		
			
	cnt = skb->len;		
	if(cnt%2)
		cnt++;		
				
	icmp_hdr = (struct icmphdr *)(skb->data);
	skb = alloc_skb(ETH_FRAME_LEN);
	ip_skb_reserve(skb);		//reserve for eth and ip stack	
	icmp_echo = (struct icmphdr *)skb_put(skb, cnt);	
	
	icmp_echo->type  = 0;
	icmp_echo->code  = 0;	
	sum = 0;			
	for(i=2; i<cnt/2; i++)
	{	
		tmp = *((unsigned short *)(&icmp_hdr->type)+i);
		*((unsigned short *)(&icmp_echo->type)+i) = tmp;
		sum += tmp;				
	}
	i = sum>>16;
	icmp_echo->check = 0xffffu-(sum&0xffff)-i;			
	ip_send(skb, client_ip, ICMP);

	return 0;
}

static int icmp_rcv_echo(struct sk_buff *skb)
{
	client_ip = ip_get_source_ip(skb);
		
	icmp_send_echo(skb);
	
	return 0;
}

int icmp_rcv_packet(struct sk_buff *skb)
{
	struct icmphdr *icmp_hdr = (struct icmphdr *)(skb->data);
	
	switch(icmp_hdr->type)
	{
		case 8:
		icmp_rcv_echo(skb);
	}
	
	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -