【问题标题】:Using netpoll on Kernel 3.10在内核 3.10 上使用 netpoll
【发布时间】:2013-12-24 06:14:30
【问题描述】:

我试图在内核 3.10 中发送一个 udp 数据包,遵循这个问题: Sending UDP packets from the Linux Kernel

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);

【问题讨论】:

  • 因为你使用了np_t.local_ip,你的意思是np_t.remote_ip
  • 抱歉,这只是一个错字。在帖子中修复它

标签: c linux udp kernel


【解决方案1】:

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

 nc -u -l 514  // u is for udp and -l for listening on particular port

您可以查看手册页以获取更多选项。

【讨论】:

    猜你喜欢
    • 2014-11-05
    • 2015-10-05
    • 1970-01-01
    • 2014-05-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-19
    • 2016-06-07
    相关资源
    最近更新 更多