LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 888|回复: 2

大侠帮帮忙,关于用户层程序调用自己写的模块函数问题

[复制链接]
发表于 2009-3-30 02:10:27 | 显示全部楼层 |阅读模式
自己写了某一内核模块 通过insmod已经加载到了内核成功(kernel 2.6.25.14)

但用户程序这边需要调用模块的某一函数(如下的getDropCount())

模块代码如下:
static long count=0;

long getDropCount()
{
      return count;
}


由于某种原因,不能使此方法注册为一个系统调用(存储在sys_call_table里面)

跪求大侠帮忙,最好给出具体方法。

模块代码如下:

static unsigned int drop_ip = 16820416;
//static unsigned int drop_ip = 123456;

static long count=0;

long getDropCount()
{
      return count;
}

unsigned int hook_fund(unsigned int hooknum,struct sk_buff *skb,const struct net_device *in,const struct net_device *out,int(*okfn)(struct sk_buff*))
{
  .....
}

int init(void)
{
  nfho.hook=hook_fund;
  nfho.hooknum = 1;
  nfho.pf=PF_INET;
  nfho.priority = NF_IP_PRI_FIRST;
  nf_register_hook(&nfho);
  return 0;
}

void exit(void)
{
    nf_unregister_hook(&nfho);
}

module_init(init);
module_exit(exit);

MODULE_LICENSE("GPL");


//以上模块被加载到内核空间

现在用户要获取到那个count值,所以想调用那个getDropCount()方法???
 楼主| 发表于 2009-3-30 10:36:36 | 显示全部楼层
在这拜膜下chinaUnix的“独孤九剑”大哥!!! 问题继续~~~~~~~
回复 支持 反对

使用道具 举报

发表于 2009-3-30 18:10:53 | 显示全部楼层
把模块注册成一个字符设备驱动,然后用ioctl来进行调用。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表