Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/60.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 原始套接字和NF_INET_POST_路由_C_Linux_Sockets_Linux Kernel_Netfilter - Fatal编程技术网

C 原始套接字和NF_INET_POST_路由

C 原始套接字和NF_INET_POST_路由,c,linux,sockets,linux-kernel,netfilter,C,Linux,Sockets,Linux Kernel,Netfilter,是否有办法在NF\u INET\u POST\u ROUTING中知道数据包是否通过原始套接字生成: #include <sys/socket.h> #include <netinet/in.h> raw_socket = socket(AF_INET, SOCK_RAW, int protocol); #包括 #包括 原始套接字=套接字(AF_INET、SOCK_raw、int协议); 非常感谢您的帮助 是的,您可以使用struct socket的字段 F.e.:

是否有办法在
NF\u INET\u POST\u ROUTING
中知道数据包是否通过原始套接字生成:

#include <sys/socket.h>
#include <netinet/in.h>
raw_socket = socket(AF_INET, SOCK_RAW, int protocol); 
#包括
#包括
原始套接字=套接字(AF_INET、SOCK_raw、int协议);
非常感谢您的帮助

是的,您可以使用
struct socket
的字段

F.e.:

请记住,转发的数据包也可能出现在
NF\u INET\u POST\u路由
钩子中。

是的,您可以使用
结构套接字
的字段

F.e.:

请记住,转发的数据包也可能出现在
NF\u INET\u POST\u路由
挂钩中

static unsigned int nfh_handler(...) {
    struct iphdr *ip_header = ip_hdr(skb);
    if(ip_header->protocol == IPPROTO_TCP) {
        struct tcphdr *tcp_header = tcp_hdr(skb);
        if(skb->sk && skb->sk->sk_socket &&
            skb->sk->sk_socket->type == SOCK_RAW)
            printk(KERN_INFO "SOCK_RAW -> src port:%d, dst port:%d\n",
                   ntohs(tcp_header->source), ntohs(tcp_header->dest));
    }
    // ...    
    // return
}