2012-03-21 51 views
0

我正在嘗試發送ping pkt。通過寫一個內核模塊。當我檢查通過tcpdump發送的是什麼時,我看到了somthing,但它不是一個icmp header.so決定檢查標題transport_header和network_header(skb成員)中的內容。how我可以使用printk命令來執行它(或任何其他) 。請參見follwing代碼在skb中打印transport_header中的值

icmp.type = ICMP_ECHO; 
icmp.code = 0; 
icmp.un.echo.sequence = i++; 
icmp.un.echo.id = current->pid & 0xFFFF; 

skb->transport_header =skb_push(skb,sizeof(icmp)); 
memset(skb->transport_header,0,sizeof(struct icmphdr)); 
memcpy(skb->transport_header,&icmp,sizeof(struct icmphdr)); 

回答

1

這將是相當難看,但可讀:

unsigned int *p = skb->transport_header; 
for (i=0;i<sizeof(the header you want)/sizeof(int);i++) { 
    printk("%08x", ntohl(p_i[i])); 
} 
printk("\n");