參考文章:
內核文檔 Documentation/connector/connector.txt
測試用例: 內核模塊 Documentation/connector/cn_test.c
用戶態程序 Documentation/connector/ucon.c
由於 內核 2.6.14 的 netlink 代碼只允許選擇一個小於或等於最大組號的組,對於連接器,最大的組號爲CN_NETLINK_USERS + 0xf, 即16,因此如果想使用更大的組號,必須修改CN_NETLINK_USERS 到該大值。增加的 0xf 個號碼供非內核態用戶使用。
因此內核文檔中的example程序不能直接運行,
//修改 cn_test.c // static struct cb_id cn_test_id = { 0x123, 0x456 }; static struct cb_id cn_test_id = { 0x7, 0x7 }; //修改 ucon.c //l_local.nl_groups = 0x123; /* bitmask of requested groups */ l_local.nl_groups = 0x7; /* bitmask of requested groups */ #if 1 { int on = 0x7; /* Additional group number */ setsockopt(s, 270, 1, &on, sizeof(on)); } #endif
[注:內核模塊編譯準備:]
1、安裝內核源代碼包:
內核版本:kernel-2.6.25.10-86.fc9
下載 kernel-2.6.25.10-86.fc9.src.rpm
# rpm –Uvh kernel-2.6.25.10-86.fc9.src.rpm # cd /usr/src/redhat/SPECS # rpmbuild -bp --target $(uname -m) kernel.spec # cd /usr/src/ # ln -s ./redhat/BUILD/kernel-2.6.25/linux-2.6.25.i686/ linux-2.6.25.i686
準備編譯內核:
# cd /usr/src/linux-2.6.25.i686 # make mrproper # make oldconfig # make modules_prepare //修改 /usr/src/linux-2.6.25.i686/Makefile EXTRAVERSION = .10-86.fc9.i686
cn_test.c 模塊的Makefile文件:
TARGET=cn_test KDIR=/usr/src/linux-2.6.25.i686 PWD=$(shell pwd) obj-m+=$(TARGET).o default: make -C $(KDIR) M=$(PWD) modules