【发布时间】:2010-02-22 07:03:41
【问题描述】:
我有一个尝试打印 IP 标头的片段偏移量的小函数。
ParseIpHeader(unsigned char *packet, int len)
{
struct ethhdr *ethernet_header;
struct iphdr *ip_header;
/* First Check if the packet contains an IP header using
the Ethernet header */
ethernet_header = (struct ethhdr *)packet;
if(ntohs(ethernet_header->h_proto) == ETH_P_IP)
{
/* The IP header is after the Ethernet header */
if(len >= (sizeof(struct ethhdr) + sizeof(struct iphdr)))
{
ip_header = (struct iphdr*)(packet + sizeof(struct ethhdr));
/* print the Source and Destination IP address */
//printf("Dest IP address: %s\n", inet_ntoa(ip_header->daddr));
//printf("Source IP address: %s\n", inet_ntoa(ip_header->saddr));
printf("protocol %d\n", ip_header->protocol);
printf("Fragment off is %d\n", ntohs(ip_header->frag_off));
}
}
我的数据包是 TCP(ip_header->protocol 总是 6。问题是 frag_off 一直是 16384。我发送了很多数据,为什么 frag_off 总是恒定的?
谢谢。
【问题讨论】:
-
另外——也许你会澄清你计划用它的代码/用例实现的最终目标——也许我可以扩展答案。
-
我正在使用 recvfrom 从网络中获取数据。 recvfrom 的最大缓冲区为 65K。所以在下一个数据包中收到了一些数据,我想合并它们
标签: c network-programming network-protocols