Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[嚙踝蕭嚙瘩] kernel嚙踝蕭嚙褓∴蕭 user space: C program

9 views
Skip to first unread message

硬體

unread,
Jul 7, 2015, 11:37:02 AM7/7/15
to
我在 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://www.ptt.cc/bbs/Linux/M.1436281704.A.EA6.html

0 new messages