2013-04-10 88 views
9

我正在編譯器錯誤在編譯時這是使用網絡鏈路功能,我的老kernel模塊工作。netlink_kernel_create不與最新的Linux內核

int 
init_module() 
{ 
    /* Initialize the Netlink kernel interface */ 
    nl_sk = netlink_kernel_create(&init_net, 17, 0, recv_cmd, NULL, THIS_MODULE); 
    if(!nl_sk) 
    { 
      printk(KERN_INFO "failed to initialize system (error: 1001)\n"); 
      return -ENOMEM; 
    } 
.... 

以前它工作正常,但現在我得到這個錯誤。

error: too many arguments to function 'netlink_kernel_create' 

OS信息

uname -a 

Linux ibrar-ahmed 3.8.0-17-generiC#27-Ubuntu SMP Sun Apr 7 19:39:35 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux 

回答

11

只是下面

struct netlink_kernel_cfg cfg = { 
    .input = recv_cmd, 
}; 

nl_sk = netlink_kernel_create(&init_net, 17, &cfg); 

更換

nl_sk = netlink_kernel_create(&init_net, 17, 0, recv_cmd, NULL, THIS_MODULE); 

,它應該工作。我遇到了同樣的問題。

+0

非常感謝您的朋友,它幫助了我很多! – 2013-08-27 14:00:55

6

這是因爲在3.8 netlink_kernel_create樣機已經改變:

netlink_kernel_create(結構網*網,INT單元,結構netlink_kernel_cfg * CFG)

(和QV http://lxr.linux.no/linux+v3.8/include/linux/netlink.h#L48

你沒有選擇,只能重寫內核模塊,並刪除額外的參數(THIS_MODULE),以及實現netlink_kernel_cfg結構。

+1

是否有任何可用的例子? – 2013-04-11 20:34:45

+1

有了這樣一個新的內核,可能不會。雖然它應該是一個相當簡單的過程,將實施修改,以適應新的API。不幸的是,這也是我們過去不得不面對的問題(因爲Linux內核API正在不斷髮展,並且通常很不穩定) – Technologeeks 2013-04-11 21:09:21