【问题标题】:Linux Kernel Module program to obtain domain name from IPLinux Kernel Module程序从IP获取域名
【发布时间】:2014-07-08 10:20:02
【问题描述】:

我需要从传出数据包中获取目标 IP 的域名。我使用netfilter钩子成功捕获并获取了目标IP数据包,如下所示。

unsigned int hook_func_out(unsigned int hooknum, struct sk_buff * skb, const struct net_device *in, const struct net_device *out, int (*okfn)(struct sk_buff*)) 
{

    ofs = 20;   // Set theoffset to skip over the IP header.

    {   
            struct iphdr *ip_header = (struct iphdr *)skb_network_header(skb);  
            struct udphdr *udp_header;  
            struct tcphdr * tcp_header;

        //Ican obtain the destination IP address of the packet 
        //like this
        unsigned int dest_ip = (unsigned int)ip_header->daddr;

        //or like this          
        char pkt_tbuf[16];          
        snprintf(pkt_tbuf, 16, "%pI4", &ip_header->daddr);

        //here I need to obtain the domain name of the obtained destination address
    }
}

但是,我不知道如何使用该 IP 来获取所获得 IP 的域名。

我尝试了许多来源 (https://www.google.com/search?client=ubuntu&channel=fs&q=linux+kernel+programming+domain+name+from+IP+&ie=utf-8&oe=utf-8),但确实找到了有关该主题的任何相关信息,如果您的专家能提供任何示例代码/参考来执行此任务,我将不胜感激:)

谢谢

【问题讨论】:

  • 您可能需要进行反向 DNS 查找

标签: c linux kernel nslookup


【解决方案1】:

对于内核空间,您可以使用DNS Resolver Module 从内核空间查询DNS。 查看文档here

启用并编译模块

The module should be enabled by turning on the kernel configuration options:

CONFIG_DNS_RESOLVER - tristate "DNS Resolver support"

按照文档中的说明修改/etc/request-key.conf文件

包括 dns_resolver.h

 #include <linux/dns_resolver.h>

使用 dns_query 函数进行查询。使用 PTRCNAME 作为类型来执行反向 DNS 查找

int dns_query(const char *type, const char *name, size_t namelen,
       const char *options, char **_result, time_t *_expiry);

【讨论】:

  • 非常感谢先生..我会试试这个:)
猜你喜欢
  • 2020-09-03
  • 1970-01-01
  • 1970-01-01
  • 2011-01-28
  • 2014-08-02
  • 2013-04-27
  • 1970-01-01
  • 1970-01-01
  • 2022-01-02
相关资源
最近更新 更多