[問題] kernel的值→ user space: C program

作者: hardware (哈味)   2015-07-07 23:08:22
我在 net/core/dev.c
int(myPacket)(struct sk_buff)=0;
int netif_rx(struct sk_buff *skb)
{
if(myPacket)
{
myPacket(skb);
}
...
}
extern int(myPacket)(strcut sk_buff)=0;
EXPORT_SYMBOL(myPacket);
接著寫了一個 kernel module
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/skbuff.h>
#lnclude <linux/ip.h>
extern int(*myPacket)(strcut sk_buff*)=0;
int myPacketAnalyze(struct sk_buff* skb)
{
struct iphdr *iph;
iph = ip_hdr(skb);
printk("version = %d\n",iph->version);
printk("header_len = %d\n",iph->ihl);
printk("tos = %d\n",iph->tos);
printk("total_len = %hu\n",ntohs(iph->tot_len));
printk("id = %hu\n",ntohs(iph->id));
printk("frag = %hu\n",(nthos(iph->frag_off))>>13);
printk("frag_off = %hu\n",(ntohs(iph->frag_off))&0x1111111111111);
printk("protocol = %d\n",iph->protocol);
printk("ttl = %d\n",iph->ttl);
printk("souce_addr = %u.%u.%u.%u\n",NIPQUAD(iph->saddr));
printk("dest_addr = %u.%u.%u.%u\n",NIPQUAD(iph->daddr));
}
int init_module(void)
{
myPacket = myPacketAnalyze;
return 0;
}
void cleanup_module(void)
{
myPacket = 0;
}
在 var/log/message
印出來的值是對的 有跑出我想要的結果
但是這個值抓到我的C程式裡面
outputpkt.c
不曉得要怎麼做
我找網路上 有人說要用system call
有人有經驗嗎?謝謝~
作者: dou0228 (7777)   2015-07-08 10:45:00
libpcap 好東西不用嗎?

Links booklink

Contact Us: admin [ a t ] ucptt.com