【问题标题】:How to check a IP-Header or TCP/UDP header is in a connection?如何检查 IP 标头或 TCP/UDP 标头是否在连接中?
【发布时间】:2012-01-13 01:00:02
【问题描述】:

我有一个防火墙来检测所有连接。 当我从 A 连接到 B 时,我们会收到很多 A 和 B 之间发送的数据包。如果我们从 B 连接到 A,我们也会收到相同的 A->B。

我不知道如何检查每个数据包是属于 A 创建的连接还是 B 创建的连接。

我已经抓到了IP头,TCP/UDP头,但是不知道是什么字段可以查。

【问题讨论】:

    标签: tcp header udp ip


    【解决方案1】:

    序列号字段是你需要的。

    struct tcphdr {
        unsigned short  th_sport;   /* source port */
        unsigned short  th_dport;   /* destination port */
        tcp_seq th_seq;         /* sequence number */
        tcp_seq th_ack;         /* acknowledgement number */
    ...
    };
    
    数据包 A -> B A [th_seq=1] -> B B [th_seq=2, th_ack=1] -> A A [th_seq=3, th_ack=2] -> B

    【讨论】:

      猜你喜欢
      • 2021-12-25
      • 2019-06-21
      • 2017-01-05
      • 2020-03-29
      • 1970-01-01
      • 2013-07-26
      • 2011-07-16
      • 2011-07-22
      • 1970-01-01
      相关资源
      最近更新 更多