如何在C中从IPv6套接字读取HTTP标头?

问题描述 投票:0回答:1

我必须读取 IPv6 scoket、获取 TCP/UDP 并读取 HTTP 标头才能获取从主机发送的 URL。我使用 Netfilter 内核 API 读取数据包,但数据打印错误。如何在 C 中获取作为请求发送的正确 http 数据/URL?

这是我尝试过的代码段。

static int sc_get_http_info(struct sk_buff *skb)
{
    struct ipv6hdr *ip6h = ipv6_hdr(skb);
    struct tcphdr *tcph = (void *)ip6h + sizeof(struct ipv6hdr);
    unsigned char *data = (void *)tcph  + tcph->doff * 4;
    unsigned int  datalen = (skb)->len - sizeof(struct ipv6hdr) - (tcph->doff * 4);
    printk ("data is %s ", data);
}

我假设数据字符串指针应该返回http数据,以便我可以在进一步的代码中使用HTTP数据包中的URL,但它返回

这是我在到达内核时得到的输出。有时,我得到的数据为 0 作为输出。我知道 IPv6 数据包中可以有扩展标头。如果存在这样的标头,如何遍历所有这些扩展标头并指向 HTTP 标头。

对于 IPv4,我遵循了此代码并且它有效。

     static int sc_get_https_info(struct sk_buff *skb)
    {
        struct iphdr *  iph = ip_hdr(skb);
        struct tcphdr * tcph = (void *)iph + iph->ihl * 4;
        unsigned char * data = (void *)tcph + tcph->doff * 4;
        unsigned int    dlen = (skb)->len - (iph->ihl * 4) - (tcph->doff * 4);
}

任何帮助都会有用并值得赞赏。

谢谢你。

c http ipv6 netfilter
1个回答
0
投票

您能给我记录 IPv4 数据包的 HTTP 标头的完整代码吗? 因为它对我不起作用,所以我在日志中收到空值或随机值。

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.