sniffex.c は、libpcapに基づいて、パケット情報をスニッフィングして表示するプログラムです。TCPフラグの値(urg、ack、psh、rst、syn、fin)を出力するように変更するにはどうすればよいですか?助けてください..
5873 次
1 に答える
6
sniff_tcpが使用されているこのコードを確認する場合は、 必要なフラグを含むこの構造体のth_flagsメンバーを必ず出力してください。
/* TCP header */
struct sniff_tcp {
u_short th_sport; /* source port */
u_short th_dport; /* destination port */
tcp_seq th_seq; /* sequence number */
tcp_seq th_ack; /* acknowledgement number */
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 */
};
一般的に、あなたはこのようなものを持っているでしょう(少し醜い、あなたはそれをより良くすることができます):
//this is already there in the code:
printf(" Src port: %d\n", ntohs(tcp->th_sport));
printf(" Dst port: %d\n", ntohs(tcp->th_dport))
//you add:
if (tcp->th_flags & TH_ECE){
printf(" Flag: TH_ECE");
}
if (tcp->th_flags & TH_RST){
printf(" Flag: TH_RST");
}
于 2010-01-15T14:31:25.457 に答える