libpcap中的确认号
我正在尝试使用libpcap打印确认号。我知道我得到的确认号与我在pcap文件中看到的不同。我的问题是,在pcap文件中,数据包编号10、11和12具有不同的ack编号,当我打印它们时,它们都具有相同的编号。有人能告诉我如何打印确认号码吗 Pcap文件: 以下是输出: 总数:10 时间:358.312120 tcpACK:14817 确认序号:32784 总数:11 时间:358.313252 tcpACK:14817 确认序号:32784 数字:12 时间:358.313414 tcpACK:14817 确认序号:32784 以下是代码的一些部分:libpcap中的确认号,c,network-programming,libpcap,C,Network Programming,Libpcap,我正在尝试使用libpcap打印确认号。我知道我得到的确认号与我在pcap文件中看到的不同。我的问题是,在pcap文件中,数据包编号10、11和12具有不同的ack编号,当我打印它们时,它们都具有相同的编号。有人能告诉我如何打印确认号码吗 Pcap文件: 以下是输出: 总数:10 时间:358.312120 tcpACK:14817 确认序号:32784 总数:11 时间:358.313252 tcpACK:14817 确认序号:32784 数字:12 时间:358.313414 tcpACK
struct tcp_hdr {
u_short th_sport; // source port
u_short th_dport; // destination port
u_int32_t th_seq; // sequence number
u_int32_t th_ack; // acknowledgement number
u_int32_t ack_seq;
u_char th_offx2; // data offset, rsvd
#define TH_OFF(th) (((th)->th_offx2 & 0xf0) >> 4)
u_char th_flags;
#define TH_FIN 0x01
#define TH_SYN 0x02
#define TH_RST 0x04
#define TH_PUSH 0x08
#define TH_ACK 0x10
#define TH_URG 0x20
#define TH_ECE 0x40
#define TH_CWR 0x80
#define TH_FLAGS
(TH_FIN|TH_SYN|TH_RST|TH_ACK|TH_URG|TH_ECE|TH_CWR)
u_short th_win; // window
u_short th_sum; // checksum
u_short th_urp; // urgent pointer
};
if (tcp->th_flags & TH_ACK)
{
struct timeval time= header->ts;
int tcpack = ntohs(tcp->th_ack);
int seq = ntohs(tcp->th_seq);
int ack_seq=ntohs(tcp->ack_seq);
printf("num: %d \n", pcount ); //print packet number
printf("Timest: %d.%06d \n",((int)time.tv_sec % 1000),(int)time.tv_usec); //print packet timestamp
printf("tcpACK: %d \n", tcpack );
printf("ack_seq: %d \n\n", ack_seq );
}
首先,这个声明是不正确的:
u_int32_t ack_seq;
确认后,您有偏移量(4位)、保留位(3位)和标志(9位)。见:
其次,当SEQ和ACK的长度为4字节时,您将使用转换宏来表示短int。你应该使用ntohl。第三,不要使用int,因为它是有符号的,使用unsigned int并将其打印为unsigned it
unsigned int tcpack = ntohl(tcp->th_ack);
unsigned int seq = ntohl(tcp->th_seq);
使用无符号int或uint32\u t
printf("tcpACK: %u \n", tcpack );
printf("tcpACK: %X \n", tcpack );
printf("seq: %u \n\n", seq );
printf("seq: %X \n\n", seq );