8
我想將來自使用netfilter捕獲的數據包的源IP地址&轉換爲char *。將來自struct iphdr *的源IP地址轉換爲使用Linux netfilter的字符串等效
在我的netfilter鉤子函數,我有:
sock_buff = skb; // argument 2 of hook function
// ip_header is struct iphdr*
ip_header = (struct iphdr *)skb_network_header(sock_buff);
// now how to convert ip_header->saddr & ip_header->daddr to char *
// ip_header->saddr & ip_header->daddr are of type __be32
感謝。
With inet_ntoa()? – 2012-02-15 16:10:33
@ ott--轉換必須在內核模塊中完成。我無法在包含inet_ntoa()函數的linux /文件夾中找到頭文件。我在linux/inet.h中找到了in_aton(),它完全相反,它將char *轉換爲__be32。 – Jake 2012-02-15 16:24:59
糟糕,內核。嘗試這個; 'printk(「ip-address是」NIPQUAD_FMT「\ n」,NIPQUAD(ip_header-> saddr));'。我無法從這裏訪問我的Linux主機,所以我無法確定宏定義的位置。它僅適用於ipv4。 – 2012-02-15 17:02:05