pcapfile.h

Go to the documentation of this file.
00001 /*
00002  * pcapfile.h
00003  *
00004  * Ethernet capture (PCAP) file declaration
00005  *
00006  * Portable Tools Library
00007  *
00008  * Copyright (C) 2011 Vox Lucida Pty. Ltd.
00009  *
00010  * The contents of this file are subject to the Mozilla Public License
00011  * Version 1.0 (the "License"); you may not use this file except in
00012  * compliance with the License. You may obtain a copy of the License at
00013  * http://www.mozilla.org/MPL/
00014  *
00015  * Software distributed under the License is distributed on an "AS IS"
00016  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
00017  * the License for the specific language governing rights and limitations
00018  * under the License.
00019  *
00020  * The Original Code is Portable Tools Library.
00021  *
00022  * The Initial Developer of the Original Code is Vox Lucida
00023  *
00024  * All Rights Reserved.
00025  *
00026  * Contributor(s): ______________________________________.
00027  *
00028  * $Revision: 27285 $
00029  * $Author: rjongbloed $
00030  * $Date: 2012-03-22 20:44:50 -0500 (Thu, 22 Mar 2012) $
00031  */
00032 
00033 #ifndef PTLIB_PCAPFILE_H
00034 #define PTLIB_PCAPFILE_H
00035 
00036 #ifdef P_USE_PRAGMA
00037 #pragma interface
00038 #endif
00039 
00040 #include <rtp/rtp.h>
00041 #include <opal/mediafmt.h>
00042 #include <ptlib/sockets.h>
00043 
00044 
00047 class OpalPCAPFile : public PFile
00048 {
00049     PCLASSINFO(OpalPCAPFile, PFile);
00050   public:
00051     OpalPCAPFile();
00052 
00053     bool Open(const PFilePath & filename);
00054     bool Restart();
00055 
00056     void PrintOn(ostream & strm) const;
00057 
00058     bool ReadRawPacket(PBYTEArray & payload);
00059     int GetDataLink(PBYTEArray & payload);
00060     int GetIP(PBYTEArray & payload);
00061     int GetUDP(PBYTEArray & payload);
00062     int GetRTP(RTP_DataFrame & rtp);
00063 
00064     const PTime & GetPacketTime() const { return m_packetTime; }
00065     const PIPSocket::Address & GetSrcIP() const { return m_packetSrcIP; }
00066     const PIPSocket::Address & GetDstIP() const { return m_packetDstIP; }
00067     unsigned IsFragmentated() const { return m_fragmentated; }
00068     WORD GetSrcPort() const { return m_packetSrcPort; }
00069     WORD GetDstPort() const { return m_packetDstPort; }
00070 
00071     void SetFilterSrcIP(
00072       const PIPSocket::Address & ip
00073     ) { m_filterSrcIP = ip; }
00074     const PIPSocket::Address & GetFilterSrcIP() const { return m_filterSrcIP; }
00075 
00076     void SetFilterDstIP(
00077       const PIPSocket::Address & ip
00078     ) { m_filterDstIP = ip; }
00079     const PIPSocket::Address & GetFilterDstIP() const { return m_filterDstIP; }
00080 
00081     void SetFilterSrcPort(
00082       WORD port
00083     ) { m_filterSrcPort = port; }
00084     WORD GetFilterSrcPort() const { return m_filterSrcPort; }
00085 
00086     void SetFilterDstPort(
00087       WORD port
00088     ) { m_filterDstPort = port; }
00089     WORD GetFilterDstPort() const { return m_filterDstPort; }
00090 
00091 
00092     struct DiscoveredRTPInfo {
00093       DiscoveredRTPInfo();
00094 
00095       PIPSocketAddressAndPort     m_addr[2];
00096       RTP_DataFrame::PayloadTypes m_payload[2];
00097       bool                        m_found[2];
00098 
00099       DWORD m_ssrc[2];
00100       WORD  m_seq[2];
00101       DWORD m_ts[2];
00102 
00103       unsigned m_ssrc_matches[2];
00104       unsigned m_seq_matches[2];
00105       unsigned m_ts_matches[2];
00106 
00107       RTP_DataFrame m_firstFrame[2];
00108 
00109       PString m_type[2];
00110       PString m_format[2];
00111 
00112       size_t m_index[2];
00113     };
00114     class DiscoveredRTPMap : public PObject, public std::map<std::string, DiscoveredRTPInfo>
00115     {
00116         PCLASSINFO(DiscoveredRTPMap, PObject);
00117       public:
00118         void PrintOn(ostream & strm) const;
00119     };
00120 
00121     bool DiscoverRTP(DiscoveredRTPMap & discoveredRTPMap);
00122 
00123     void SetFilters(
00124       const DiscoveredRTPInfo & rtp,
00125       int dir
00126     );
00127     bool SetFilters(
00128       const DiscoveredRTPMap & rtp,
00129       size_t index
00130     );
00131 
00132     bool SetPayloadMap(
00133       RTP_DataFrame::PayloadTypes pt,
00134       const OpalMediaFormat & format
00135     );
00136 
00137     OpalMediaFormat GetMediaFormat(const RTP_DataFrame & rtp) const;
00138 
00139   protected:
00140     PINDEX GetNetworkLayerHeaderSize();
00141 
00142     struct FileHeader { 
00143       DWORD magic_number;   /* magic number */
00144       WORD  version_major;  /* major version number */
00145       WORD  version_minor;  /* minor version number */
00146       DWORD thiszone;       /* GMT to local correction */
00147       DWORD sigfigs;        /* accuracy of timestamps */
00148       DWORD snaplen;        /* max length of captured packets, in octets */
00149       DWORD network;        /* data link type */
00150     };
00151 
00152     struct RecordHeader { 
00153       DWORD ts_sec;         /* timestamp seconds */
00154       DWORD ts_usec;        /* timestamp microseconds */
00155       DWORD incl_len;       /* number of octets of packet saved in file */
00156       DWORD orig_len;       /* actual length of packet */
00157     };
00158 
00159 
00160     FileHeader m_fileHeader;
00161     bool       m_otherEndian;
00162     PBYTEArray m_rawPacket;
00163     PTime      m_packetTime;
00164 
00165     PIPSocket::Address m_filterSrcIP;
00166     PIPSocket::Address m_filterDstIP;
00167     PIPSocket::Address m_packetSrcIP;
00168     PIPSocket::Address m_packetDstIP;
00169 
00170     PBYTEArray m_fragments;
00171     bool       m_fragmentated;
00172     unsigned   m_fragmentProto;
00173 
00174     WORD m_filterSrcPort;
00175     WORD m_filterDstPort;
00176     WORD m_packetSrcPort;
00177     WORD m_packetDstPort;
00178 
00179     std::map<RTP_DataFrame::PayloadTypes, OpalMediaFormat> m_payloadType2mediaFormat;
00180 };
00181 
00182 
00183 #endif // PTLIB_PCAPFILE_H
00184 
00185 
00186 // End Of File ///////////////////////////////////////////////////////////////

Generated on 14 Aug 2013 for OPAL by  doxygen 1.4.7