我需要監聽網口上的基于TCP/UDP之上的自定義協議的訊息,對這些訊息進行過濾得到其中一部分并保存為檔案,所以需要分析TCP/UDP的payload。dumpcap可以抓到pcap_t格式的包,但是怎么從中得到具體的TCP/UDP payload?
有人說(https://stackoverflow.com/questions/26699631/what-structure-pcap-t-have):
pcap_t is to be treated as an opaque handle. You are not supposed to access any of its members. Once created, you only pass it to other pcap functions.
也有人說:
struct pcap {
int fd;
int snapshot;
int linktype;
int tzoff; /* timezone offset */
int offset; /* offset for proper alignment */
struct pcap_sf sf;
struct pcap_md md;
/*
* Read buffer.
*/
int bufsize;
u_char *buffer;
u_char *bp;
int cc;
/*
* Place holder for pcap_next().
*/
u_char *pkt;
/*
* Placeholder for filter code if bpf not in kernel.
*/
struct bpf_program fcode;
char errbuf[PCAP_ERRBUF_SIZE];
};對這個struct,Payload是在buffer指向的記憶體里嗎?對應的內容是以太網幀還是其它格式?
如果不是,還有其它什么辦法可以獲取完整的TCP/UDP payload?
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/261928.html
標籤:應用程序開發區
