我开始编写一个应用程序,它将从现有的 .pcap 文件中读取 RTP/H.264 视频数据包,我需要读取数据包大小。我尝试使用packet->len 或 header->len,但它从不显示正确的数据包字节数(我正在使用wireshark来验证数据包大小 - 在 Length 列下)。怎么做?这是我的代码的一部分:
while (packet = pcap_next(handle,&header)) {
u_char *pkt_ptr = (u_char *)packet;
struct ip *ip_hdr = (struct ip *)pkt_ptr; //point to an IP header structure
struct pcap_pkthdr *pkt_hdr =(struct pcap_pkthdr *)packet;
unsigned int packet_length = pkt_hdr->len;
unsigned int ip_length = ntohs(ip_hdr->ip_len);
printf("Packet # %i IP Header length: %d bytes, Packet length: %d bytes\n",pkt_counter,ip_length,packet_length);
Packet # 0 IP Header length: 180 bytes, Packet length: 104857664 bytes
Packet # 1 IP Header length: 52 bytes, Packet length: 104857600 bytes
Packet # 2 IP Header length: 100 bytes, Packet length: 104857600 bytes
Packet # 3 IP Header length: 100 bytes, Packet length: 104857664 bytes
Packet # 4 IP Header length: 52 bytes, Packet length: 104857600 bytes
Packet # 5 IP Header length: 100 bytes, Packet length: 104857600 bytes
我尝试的另一个选项是使用:pkt_ptr-> 我得到:
read_pcapfile.c:67:43:错误:请求成员“len”不是结构或联合