我需要从传出数据包中获取目标 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)但确实找到了有关该主题的任何相关信息,如果您的专家能提供任何示例代码/参考来执行此任务,我们将不胜感激:)
谢谢