?? icmp.c
字號:
#include "utils.h"
#include "eth.h"
#include "skbuff.h"
#include "ip.h"
#include "icmp.h"
static unsigned long client_ip;
extern void Uart_Printf(char *fmt,...);
extern struct sk_buff* sk_buff_alloc(void);
extern void skb_headerinit(struct sk_buff *skb);
extern void sk_buff_free(struct sk_buff* sk_buff_unused);
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 = (struct sk_buff*)sk_buff_alloc();
if(!skb)
{
Uart_Printf("sk_buff空閑鏈表為空!\n");
return -1;
}
skb_headerinit(skb);
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);
sk_buff_free(skb);
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:
//Uart_Printf("icmp\n");
icmp_rcv_echo(skb);
}
return 0;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -