2016-12-21 113 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