2016-12-21 110 views
-1

我想從pcap文件解析一些信息到我的項目。 我正在創建可以在SIP呼叫中發現錯誤的分析程序。我創建了可以保存這些信息的類(現在不是全部)。我使用Windows和Codeblocks C++,並安裝了windows的pcap庫。 實現此目的的最簡單方法是什麼?解析pcap文件以在C++中讀取消息

class Messege 
    { 
    private: 
     int number; 
     string cseq; 
     string method; 
     string callId; 
     string source; 
     string destination; 
     string request; 

    public: 
     //set 
     void setCseq (string newCseq){cseq=newCseq;}; 
     void setNumber (int newNumber){number=newNumber;}; 
     void setMethod (string newMethod){method=newMethod;}; 
     void setSource (string newSource){source=newSource;}; 
     void setDestination (string newDestination){destination = newDestination;}; 
     void setCallId (string newCallId){callId = newCallId;}; 
     void setRequest (string newRequest){request = newRequest;}; 

     //get 
     int getNumber(){return number;}; 
     string getCseq(){return cseq;}; 
     string getMethod(){return method;}; 
     string getSource(){return source;}; 
     string getDestination() {return destination;}; 
     string getCallId(){return callId;}; 
     string getRequest(){return request;}; 
    }; 
+1

我已投票結束爲「太寬泛」。或者,您可能會要求提供一個工具的建議 - 這將是「脫離主題」。 *您需要決定如何解析pcap文件。 –

回答

0

您可能想查看libpcap。您可以分析一個PCAP文件:

pcap_t *pcap = pcap_open_offline(pcap_filename, errbuf); 
int link_layer_type = pcap_datalink(pcap); 
pcap_loop(pcap, -1, pcap_handler, NULL); 
pcap_close(pcap); 

其中pcap_handler是你的回調函數:

typedef void (*pcap_handler)(u_char *user, const struct pcap_pkthdr *h, const u_char *bytes); 

查找細節here