Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 在内核3.10上使用netpoll_C_Linux_Udp_Kernel - Fatal编程技术网

C 在内核3.10上使用netpoll

C 在内核3.10上使用netpoll,c,linux,udp,kernel,C,Linux,Udp,Kernel,我尝试在内核3.10中发送udp数据包,如下所示: UDP数据包应该从192.168.56.2发送到192.168.56.1(端口514) 我检查了192.168.56.2上的tcpdump和192.168.56.1上的wireshark(+syslog ng on cygwin),但没有看到数据包 有人知道怎么了吗 #include <linux/module.h> #include <linux/kernel.h> #include <linux/init.h

我尝试在内核3.10中发送udp数据包,如下所示:

UDP数据包应该从192.168.56.2发送到192.168.56.1(端口514) 我检查了192.168.56.2上的tcpdump和192.168.56.1上的wireshark(+syslog ng on cygwin),但没有看到数据包

有人知道怎么了吗

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/netpoll.h>

static struct netpoll* np = NULL;
static struct netpoll np_t;

//see https://stackoverflow.com/questions/10499865/sending-udp-packets-from-the-linux-kernel
void init_netpoll(void)
{
    np_t.name = "LRNG";
    strlcpy(np_t.dev_name, "eth0", IFNAMSIZ);
    np_t.local_ip.ip = htonl((unsigned long int)0xc0a83802); //192.168.56.2
    np_t.local_ip.in.s_addr = htonl((unsigned long int)0xc0a83802); //192.168.56.2
    np_t.remote_ip.ip = htonl((unsigned long int)0xc0a83801); //192.168.56.1
    np_t.remote_ip.in.s_addr = htonl((unsigned long int)0xc0a83801); //192.168.56.1
    np_t.ipv6 = 0;//no IPv6
    np_t.local_port = 6666;
    np_t.remote_port = 514;
    memset(np_t.remote_mac, 0xff, ETH_ALEN);
    netpoll_print_options(&np_t);
    netpoll_setup(&np_t);
    np = &np_t;
}

void clean_netpoll(void)
{
  //nothing
}

void sendUdp(const char* buf)
{
    int len = strlen(buf);
    netpoll_send_udp(np,buf,len);
}


static int __init initmod(void)
{
        printk(KERN_INFO "Hello world :)\n");

        init_netpoll();
        sendUdp("[55] testestestestestestestestest");
        sendUdp("<55>Mar 17 21:57:57 frodo sshd[701]: blub");


        //0 = module loaded
        return 0;
}

static void __exit cleanmod(void)
{
        printk(KERN_INFO "Goodbye world :(\n");
}



//Makros
module_init(initmod);
module_exit(cleanmod);
#包括
#包括
#包括
#包括
静态结构netpoll*np=NULL;
静态结构netpoll np\u t;
//看https://stackoverflow.com/questions/10499865/sending-udp-packets-from-the-linux-kernel
void init_netpoll(void)
{
np_t.name=“LRNG”;
strlcpy(np_t.dev_name,“eth0”,IFNAMSIZ);
np_t.local_ip.ip=htonl((无符号长整数)0xc0a83802);/192.168.56.2
np_t.local_ip.in.s_addr=htonl((无符号长整数)0xc0a83802);/192.168.56.2
np_t.remote_ip.ip=htonl((无符号长整数)0xc0a83801);//192.168.56.1
np_t.remote_ip.in.s_addr=htonl((无符号长整数)0xc0a83801);//192.168.56.1
np_t.ipv6=0;//没有ipv6
np_t.local_port=6666;
np_t.远程_端口=514;
memset(np_t.remote_mac,0xff,ETH_ALEN);
netpoll_打印选项(&np_t);
netpoll_设置(&np_t);
np=&np\t;
}
void clean_netpoll(void)
{
//没什么
}
void senddp(常量字符*buf)
{
int len=strlen(buf);
netpoll_send_udp(np、buf、len);
}
静态int\uu init initmod(void)
{
printk(KERN_INFO“Hello world:)\n”);
init_netpoll();
sendUdp(“[55]测试”);
sendUdp(“Mar 17 21:57:57 frodo sshd[701]:blub”);
//0=已加载模块
返回0;
}
静态无效\uuu退出cleanmod(无效)
{
printk(KERN_INFO“再见世界”(\n”);
}
//马克罗斯
模块_init(initmod);
模块_出口(cleanmod);

您应该打开相应的端口,以便在目标中侦听。您可以使用netcat来完成此操作(在插入模块之前在终端中键入此项)


您可以查看手册页以了解更多选项。

您应该打开相应的端口以便在目标中侦听。您可以使用netcat来执行此操作(在插入模块之前在终端中键入此项)


您可以查看手册页以了解更多选项。

因为您使用了
np\t.local\u ip
而您的意思是
np\t.remote\u ip
?sry,这只是一个输入错误。在帖子中修复了它,因为您使用了
np\t.local\u ip
而您的意思是
np\t.remote\u ip
?sry,这只是一个输入错误。在帖子中修复了它
 nc -u -l 514  // u is for udp and -l for listening on particular port