作者hardware (硬体)
看板Linux
标题[问题] kernel的值→ user space: C program
时间Tue Jul 7 23:08:22 2015
我在 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
有人有经验吗?谢谢~
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 140.117.164.19
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Linux/M.1436281704.A.EA6.html
1F:→ dou0228: libpcap 好东西不用吗? 07/08 10:45