我是內核模塊編程的新手,並嘗試使用'sys_socket'在我的內核模塊中創建原始套接字。我使用'sys_bind'和'sys_ioctl'(用於獲取接口號)將此套接字綁定到接口。!編譯內核模塊
雖然編譯我的模塊,我得到以下錯誤:
make -C /lib/modules/3.13.0-68-generic/build M=/root/Kernel_Module modules
make[1]: Entering directory `/usr/src/linux-headers-3.13.0-68-generic'
CC [M] /root/Kernel_Module/kernel_module.o
Building modules, stage 2.
MODPOST 1 modules
WARNING: "sys_ioctl" [/root/Kernel_Module/kernel_module.ko] undefined!
WARNING: "sys_bind" [/root/Kernel_Module/kernel_module.ko] undefined!
WARNING: "sys_socket" [/root/Kernel_Module/kernel_module.ko] undefined!
CC /root/Kernel_Module/kernel_module.mod.o
LD [M] /root/Kernel_Module/kernel_module.ko
make[1]: Leaving directory `/usr/src/linux-headers-3.13.0-68-generic'
我怎樣才能解決這個問題?
的代碼如下指定:
struct sockaddr_ll socketBindAddr;
struct ifreq ifreq;
int socketFd = 0;
socketFd = sys_socket (AF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
if (socketFd < 0)
{
printk (KERN_CRIT "Failed to open data socket!!\r\n");
return OFC_FAILURE;
}
memset (&ifreq, 0, sizeof(ifreq));
strcpy (ifreq.ifr_name, gOfcGlobals.aDataIfName);
if (sys_ioctl (socketFd, SIOCGIFINDEX, (unsigned long) &ifreq) < 0)
{
printk (KERN_CRIT "Ioctl failed to get IfIndex!!\r\n");
return OFC_FAILURE;
}
memset (&socketBindAddr, 0, sizeof(socketBindAddr));
socketBindAddr.sll_family = AF_PACKET;
socketBindAddr.sll_protocol = htons(ETH_P_ALL);
if (sys_bind (socketFd, (struct sockaddr *) &socketBindAddr,
sizeof(socketBindAddr)) < 0)
{
printk (KERN_CRIT "Failed to bind socket\r\n");
return OFC_FAILURE;
}
簡而言之:Syscalls用於**用戶空間程序**,不用於*內核模塊*。一些系統調用有類似於內核使用。我不知道'ioctl','bind'和'socket'的in-kernel類似物。 – Tsyvarev