pcapfile.h
Go to the documentation of this file.
/*
* pcapfile.h
*
* Ethernet capture (PCAP) file declaration
*
* Portable Tools Library
*
* Copyright (C) 2011 Vox Lucida Pty. Ltd.
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Portable Tools Library.
*
* The Initial Developer of the Original Code is Vox Lucida
*
* All Rights Reserved.
*
* Contributor(s): ______________________________________.
*
* $Revision: 27285 $
* $Author: rjongbloed $
* $Date: 2012-03-22 20:44:50 -0500 (Thu, 22 Mar 2012) $
*/
#ifndef PTLIB_PCAPFILE_H
#define PTLIB_PCAPFILE_H
#ifdef P_USE_PRAGMA
#pragma interface
#endif
#include <rtp/rtp.h>
#include <opal/mediafmt.h>
#include <ptlib/sockets.h>
class OpalPCAPFile : public PFile
{
PCLASSINFO(OpalPCAPFile, PFile);
public:
OpalPCAPFile();
bool Open(const PFilePath & filename);
bool Restart();
void PrintOn(ostream & strm) const;
bool ReadRawPacket(PBYTEArray & payload);
int GetDataLink(PBYTEArray & payload);
int GetIP(PBYTEArray & payload);
int GetUDP(PBYTEArray & payload);
int GetRTP(RTP_DataFrame & rtp);
const PTime & GetPacketTime() const { return m_packetTime; }
const PIPSocket::Address & GetSrcIP() const { return m_packetSrcIP; }
const PIPSocket::Address & GetDstIP() const { return m_packetDstIP; }
unsigned IsFragmentated() const { return m_fragmentated; }
WORD GetSrcPort() const { return m_packetSrcPort; }
WORD GetDstPort() const { return m_packetDstPort; }
void SetFilterSrcIP(
const PIPSocket::Address & ip
) { m_filterSrcIP = ip; }
const PIPSocket::Address & GetFilterSrcIP() const { return m_filterSrcIP; }
void SetFilterDstIP(
const PIPSocket::Address & ip
) { m_filterDstIP = ip; }
const PIPSocket::Address & GetFilterDstIP() const { return m_filterDstIP; }
void SetFilterSrcPort(
WORD port
) { m_filterSrcPort = port; }
WORD GetFilterSrcPort() const { return m_filterSrcPort; }
void SetFilterDstPort(
WORD port
) { m_filterDstPort = port; }
WORD GetFilterDstPort() const { return m_filterDstPort; }
struct DiscoveredRTPInfo {
DiscoveredRTPInfo();
PIPSocketAddressAndPort m_addr[2];
RTP_DataFrame::PayloadTypes m_payload[2];
bool m_found[2];
DWORD m_ssrc[2];
WORD m_seq[2];
DWORD m_ts[2];
unsigned m_ssrc_matches[2];
unsigned m_seq_matches[2];
unsigned m_ts_matches[2];
RTP_DataFrame m_firstFrame[2];
PString m_type[2];
PString m_format[2];
size_t m_index[2];
};
class DiscoveredRTPMap : public PObject, public std::map<std::string, DiscoveredRTPInfo>
{
PCLASSINFO(DiscoveredRTPMap, PObject);
public:
void PrintOn(ostream & strm) const;
};
bool DiscoverRTP(DiscoveredRTPMap & discoveredRTPMap);
void SetFilters(
const DiscoveredRTPInfo & rtp,
int dir
);
bool SetFilters(
const DiscoveredRTPMap & rtp,
size_t index
);
bool SetPayloadMap(
RTP_DataFrame::PayloadTypes pt,
const OpalMediaFormat & format
);
OpalMediaFormat GetMediaFormat(const RTP_DataFrame & rtp) const;
protected:
PINDEX GetNetworkLayerHeaderSize();
struct FileHeader {
DWORD magic_number; /* magic number */
WORD version_major; /* major version number */
WORD version_minor; /* minor version number */
DWORD thiszone; /* GMT to local correction */
DWORD sigfigs; /* accuracy of timestamps */
DWORD snaplen; /* max length of captured packets, in octets */
DWORD network; /* data link type */
};
struct RecordHeader {
DWORD ts_sec; /* timestamp seconds */
DWORD ts_usec; /* timestamp microseconds */
DWORD incl_len; /* number of octets of packet saved in file */
DWORD orig_len; /* actual length of packet */
};
FileHeader m_fileHeader;
bool m_otherEndian;
PBYTEArray m_rawPacket;
PTime m_packetTime;
PIPSocket::Address m_filterSrcIP;
PIPSocket::Address m_filterDstIP;
PIPSocket::Address m_packetSrcIP;
PIPSocket::Address m_packetDstIP;
PBYTEArray m_fragments;
bool m_fragmentated;
unsigned m_fragmentProto;
WORD m_filterSrcPort;
WORD m_filterDstPort;
WORD m_packetSrcPort;
WORD m_packetDstPort;
std::map<RTP_DataFrame::PayloadTypes, OpalMediaFormat> m_payloadType2mediaFormat;
};
#endif // PTLIB_PCAPFILE_H
// End Of File ///////////////////////////////////////////////////////////////
OpalPCAPFile::DiscoveredRTPInfo::m_ssrc
DWORD m_ssrc[2]
Definition: pcapfile.h:99
OpalPCAPFile::GetUDP
int GetUDP(PBYTEArray &payload)
OpalPCAPFile::DiscoveredRTPInfo::m_addr
PIPSocketAddressAndPort m_addr[2]
Definition: pcapfile.h:95
OpalPCAPFile::FileHeader::version_minor
WORD version_minor
Definition: pcapfile.h:145
OpalPCAPFile::RecordHeader::ts_sec
DWORD ts_sec
Definition: pcapfile.h:153
OpalPCAPFile::m_filterDstPort
WORD m_filterDstPort
Definition: pcapfile.h:175
OpalPCAPFile::RecordHeader::orig_len
DWORD orig_len
Definition: pcapfile.h:156
OpalPCAPFile::DiscoveredRTPInfo::m_firstFrame
RTP_DataFrame m_firstFrame[2]
Definition: pcapfile.h:107
OpalPCAPFile::GetRTP
int GetRTP(RTP_DataFrame &rtp)
OpalPCAPFile::Open
bool Open(const PFilePath &filename)
OpalPCAPFile::GetIP
int GetIP(PBYTEArray &payload)
OpalPCAPFile::SetFilters
void SetFilters(const DiscoveredRTPInfo &rtp, int dir)
OpalPCAPFile::m_rawPacket
PBYTEArray m_rawPacket
Definition: pcapfile.h:162
OpalPCAPFile::FileHeader::thiszone
DWORD thiszone
Definition: pcapfile.h:146
OpalPCAPFile::m_packetDstPort
WORD m_packetDstPort
Definition: pcapfile.h:177
OpalPCAPFile::DiscoveredRTPInfo::m_ts
DWORD m_ts[2]
Definition: pcapfile.h:101
OpalPCAPFile::GetNetworkLayerHeaderSize
PINDEX GetNetworkLayerHeaderSize()
OpalPCAPFile::FileHeader
Definition: pcapfile.h:142
OpalPCAPFile::GetDataLink
int GetDataLink(PBYTEArray &payload)
OpalPCAPFile::DiscoveredRTPInfo::m_format
PString m_format[2]
Definition: pcapfile.h:110
OpalPCAPFile::GetFilterSrcPort
WORD GetFilterSrcPort() const
Definition: pcapfile.h:84
OpalPCAPFile::ReadRawPacket
bool ReadRawPacket(PBYTEArray &payload)
OpalPCAPFile::m_fragments
PBYTEArray m_fragments
Definition: pcapfile.h:170
OpalPCAPFile::m_packetDstIP
PIPSocket::Address m_packetDstIP
Definition: pcapfile.h:168
OpalPCAPFile::m_filterSrcIP
PIPSocket::Address m_filterSrcIP
Definition: pcapfile.h:165
RTP_DataFrame::PayloadTypes
PayloadTypes
Definition: rtp.h:86
OpalPCAPFile::m_payloadType2mediaFormat
std::map< RTP_DataFrame::PayloadTypes, OpalMediaFormat > m_payloadType2mediaFormat
Definition: pcapfile.h:179
OpalPCAPFile::Restart
bool Restart()
OpalPCAPFile::OpalPCAPFile
OpalPCAPFile()
OpalPCAPFile::GetSrcPort
WORD GetSrcPort() const
Definition: pcapfile.h:68
OpalPCAPFile::m_fileHeader
FileHeader m_fileHeader
Definition: pcapfile.h:160
OpalPCAPFile::m_packetTime
PTime m_packetTime
Definition: pcapfile.h:163
OpalPCAPFile::GetDstPort
WORD GetDstPort() const
Definition: pcapfile.h:69
OpalPCAPFile::SetPayloadMap
bool SetPayloadMap(RTP_DataFrame::PayloadTypes pt, const OpalMediaFormat &format)
OpalPCAPFile::FileHeader::network
DWORD network
Definition: pcapfile.h:149
OpalPCAPFile::FileHeader::snaplen
DWORD snaplen
Definition: pcapfile.h:148
OpalPCAPFile::SetFilterSrcIP
void SetFilterSrcIP(const PIPSocket::Address &ip)
Definition: pcapfile.h:71
OpalPCAPFile::m_otherEndian
bool m_otherEndian
Definition: pcapfile.h:161
OpalPCAPFile::GetSrcIP
const PIPSocket::Address & GetSrcIP() const
Definition: pcapfile.h:65
RTP_DataFrame
Definition: rtp.h:71
OpalMediaFormat
Definition: mediafmt.h:724
OpalPCAPFile::DiscoveredRTPInfo::m_ts_matches
unsigned m_ts_matches[2]
Definition: pcapfile.h:105
OpalPCAPFile::DiscoveredRTPInfo::m_type
PString m_type[2]
Definition: pcapfile.h:109
OpalPCAPFile::FileHeader::version_major
WORD version_major
Definition: pcapfile.h:144
OpalPCAPFile::GetPacketTime
const PTime & GetPacketTime() const
Definition: pcapfile.h:64
OpalPCAPFile::DiscoveredRTPMap::PrintOn
void PrintOn(ostream &strm) const
OpalPCAPFile::PrintOn
void PrintOn(ostream &strm) const
OpalPCAPFile::IsFragmentated
unsigned IsFragmentated() const
Definition: pcapfile.h:67
OpalPCAPFile::SetFilterSrcPort
void SetFilterSrcPort(WORD port)
Definition: pcapfile.h:81
mediafmt.h
OpalPCAPFile::GetMediaFormat
OpalMediaFormat GetMediaFormat(const RTP_DataFrame &rtp) const
OpalPCAPFile::DiscoveredRTPInfo::m_ssrc_matches
unsigned m_ssrc_matches[2]
Definition: pcapfile.h:103
OpalPCAPFile::FileHeader::magic_number
DWORD magic_number
Definition: pcapfile.h:143
OpalPCAPFile::m_fragmentProto
unsigned m_fragmentProto
Definition: pcapfile.h:172
OpalPCAPFile::GetFilterDstIP
const PIPSocket::Address & GetFilterDstIP() const
Definition: pcapfile.h:79
OpalPCAPFile::DiscoveredRTPInfo::m_seq_matches
unsigned m_seq_matches[2]
Definition: pcapfile.h:104
OpalPCAPFile::m_packetSrcIP
PIPSocket::Address m_packetSrcIP
Definition: pcapfile.h:167
OpalPCAPFile::FileHeader::sigfigs
DWORD sigfigs
Definition: pcapfile.h:147
OpalPCAPFile::GetDstIP
const PIPSocket::Address & GetDstIP() const
Definition: pcapfile.h:66
OpalPCAPFile::RecordHeader
Definition: pcapfile.h:152
OpalPCAPFile::DiscoveredRTPInfo
Definition: pcapfile.h:92
OpalPCAPFile::DiscoverRTP
bool DiscoverRTP(DiscoveredRTPMap &discoveredRTPMap)
OpalPCAPFile::DiscoveredRTPInfo::m_payload
RTP_DataFrame::PayloadTypes m_payload[2]
Definition: pcapfile.h:96
OpalPCAPFile::SetFilterDstPort
void SetFilterDstPort(WORD port)
Definition: pcapfile.h:86
OpalPCAPFile::m_fragmentated
bool m_fragmentated
Definition: pcapfile.h:171
OpalPCAPFile::RecordHeader::ts_usec
DWORD ts_usec
Definition: pcapfile.h:154
OpalPCAPFile::GetFilterDstPort
WORD GetFilterDstPort() const
Definition: pcapfile.h:89
OpalPCAPFile
Definition: pcapfile.h:47
OpalPCAPFile::DiscoveredRTPInfo::m_index
size_t m_index[2]
Definition: pcapfile.h:112
OpalPCAPFile::DiscoveredRTPMap
Definition: pcapfile.h:114
OpalPCAPFile::DiscoveredRTPInfo::m_seq
WORD m_seq[2]
Definition: pcapfile.h:100
rtp.h
OpalPCAPFile::DiscoveredRTPInfo::DiscoveredRTPInfo
DiscoveredRTPInfo()
OpalPCAPFile::m_filterSrcPort
WORD m_filterSrcPort
Definition: pcapfile.h:174
OpalPCAPFile::RecordHeader::incl_len
DWORD incl_len
Definition: pcapfile.h:155
OpalPCAPFile::m_packetSrcPort
WORD m_packetSrcPort
Definition: pcapfile.h:176
OpalPCAPFile::DiscoveredRTPInfo::m_found
bool m_found[2]
Definition: pcapfile.h:97
OpalPCAPFile::SetFilterDstIP
void SetFilterDstIP(const PIPSocket::Address &ip)
Definition: pcapfile.h:76
OpalPCAPFile::m_filterDstIP
PIPSocket::Address m_filterDstIP
Definition: pcapfile.h:166
OpalPCAPFile::GetFilterSrcIP
const PIPSocket::Address & GetFilterSrcIP() const
Definition: pcapfile.h:74