kernel的值→ user space: C program - Linux

By Robert
at 2015-07-07T23:08
at 2015-07-07T23:08
Table of Contents
我在 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
有人有經驗嗎?謝謝~
--
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
有人有經驗嗎?謝謝~
--
Tags:
Linux
All Comments

By Lily
at 2015-07-11T14:20
at 2015-07-11T14:20
Related Posts
Ubuntu 14.04更新出錯

By Odelette
at 2015-07-07T14:53
at 2015-07-07T14:53
tar指令應用之問題

By Hardy
at 2015-07-07T14:47
at 2015-07-07T14:47
Linux 工程師10項不可不知的技能

By Franklin
at 2015-07-07T03:07
at 2015-07-07T03:07
tr替換文字會亂替換

By Emma
at 2015-07-07T00:54
at 2015-07-07T00:54
tr替換文字會亂替換

By Daniel
at 2015-07-07T00:17
at 2015-07-07T00:17