OPAL Version 3.10.4

- Main Page
- Related Pages
- Namespaces
- Data Structures
- Files

- File List
- Globals

pcapfile.h
Go to the documentation of this file.
1 /*
2 * pcapfile.h
3 *
4 * Ethernet capture (PCAP) file declaration
5 *
6 * Portable Tools Library
7 *
8 * Copyright (C) 2011 Vox Lucida Pty. Ltd.
9 *
10 * The contents of this file are subject to the Mozilla Public License
11 * Version 1.0 (the "License"); you may not use this file except in
12 * compliance with the License. You may obtain a copy of the License at
13 * http://www.mozilla.org/MPL/
14 *
15 * Software distributed under the License is distributed on an "AS IS"
16 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17 * the License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * The Original Code is Portable Tools Library.
21 *
22 * The Initial Developer of the Original Code is Vox Lucida
23 *
24 * All Rights Reserved.
25 *
26 * Contributor(s): ______________________________________.
27 *
28 * $Revision: 25534 $
29 * $Author: rjongbloed $
30 * $Date: 2011-04-08 04:02:23 -0500 (Fri, 08 Apr 2011) $
31 */
32
33 #ifndef PTLIB_PCAPFILE_H
34 #define PTLIB_PCAPFILE_H
35
36 #ifdef P_USE_PRAGMA
37 #pragma interface
38 #endif
39
40 #include <rtp/rtp.h>
41 #include <opal/mediafmt.h>
42
43
46 class OpalPCAPFile : public PFile
47 {
48 PCLASSINFO(OpalPCAPFile, PFile);
49 public:
50 OpalPCAPFile();
51
52 bool Open(const PFilePath & filename);
53 bool Restart();
54
55 void PrintOn(ostream & strm) const;
56
57 bool ReadRawPacket(PBYTEArray & payload);
58 int GetDataLink(PBYTEArray & payload);
59 int GetIP(PBYTEArray & payload);
60 int GetUDP(PBYTEArray & payload);
61 int GetRTP(RTP_DataFrame & rtp);
62
63 const PTime & GetPacketTime() const { return m_packetTime; }
64 const PIPSocket::Address & GetSrcIP() const { return m_packetSrcIP; }
65 const PIPSocket::Address & GetDstIP() const { return m_packetDstIP; }
66 unsigned IsFragmentated() const { return m_fragmentated; }
67 WORD GetSrcPort() const { return m_packetSrcPort; }
68 WORD GetDstPort() const { return m_packetDstPort; }
69
70 void SetFilterSrcIP(
71 const PIPSocket::Address & ip
72 ) { m_filterSrcIP = ip; }
73
74 void SetFilterDstIP(
75 const PIPSocket::Address & ip
76 ) { m_filterDstIP = ip; }
77
78 void SetFilterSrcPort(
79 WORD port
80 ) { m_filterSrcPort = port; }
81
82 void SetFilterDstPort(
83 WORD port
84 ) { m_filterDstPort = port; }
85
86
87 struct DiscoveredRTPInfo {
88 DiscoveredRTPInfo();
89
90 PIPSocketAddressAndPort m_addr[2];
91 RTP_DataFrame::PayloadTypes m_payload[2];
92 bool m_found[2];
93
94 DWORD m_ssrc[2];
95 WORD m_seq[2];
96 DWORD m_ts[2];
97
98 unsigned m_ssrc_matches[2];
99 unsigned m_seq_matches[2];
100 unsigned m_ts_matches[2];
101
102 RTP_DataFrame m_firstFrame[2];
103
104 PString m_type[2];
105 PString m_format[2];
106
107 size_t m_index[2];
108 };
109 class DiscoveredRTPMap : public PObject, public std::map<std::string, DiscoveredRTPInfo>
110 {
111 PCLASSINFO(DiscoveredRTPMap, PObject);
112 public:
113 void PrintOn(ostream & strm) const;
114 };
115
116 bool DiscoverRTP(DiscoveredRTPMap & discoveredRTPMap);
117
118 void SetFilters(
119 const DiscoveredRTPInfo & rtp,
120 int dir
121 );
122 bool SetFilters(
123 const DiscoveredRTPMap & rtp,
124 size_t index
125 );
126
127 bool SetPayloadMap(
128 RTP_DataFrame::PayloadTypes pt,
129 const OpalMediaFormat & format
130 );
131
132 OpalMediaFormat GetMediaFormat(const RTP_DataFrame & rtp) const;
133
134 protected:
135 PINDEX GetNetworkLayerHeaderSize();
136
137 struct FileHeader {
138 DWORD magic_number; /* magic number */
139 WORD version_major; /* major version number */
140 WORD version_minor; /* minor version number */
141 DWORD thiszone; /* GMT to local correction */
142 DWORD sigfigs; /* accuracy of timestamps */
143 DWORD snaplen; /* max length of captured packets, in octets */
144 DWORD network; /* data link type */
145 };
146
147 struct RecordHeader {
148 DWORD ts_sec; /* timestamp seconds */
149 DWORD ts_usec; /* timestamp microseconds */
150 DWORD incl_len; /* number of octets of packet saved in file */
151 DWORD orig_len; /* actual length of packet */
152 };
153
154
155 FileHeader m_fileHeader;
156 bool m_otherEndian;
157 PBYTEArray m_rawPacket;
158 PTime m_packetTime;
159
160 PIPSocket::Address m_filterSrcIP;
161 PIPSocket::Address m_filterDstIP;
162 PIPSocket::Address m_packetSrcIP;
163 PIPSocket::Address m_packetDstIP;
164
165 PBYTEArray m_fragments;
166 bool m_fragmentated;
167 unsigned m_fragmentProto;
168
169 WORD m_filterSrcPort;
170 WORD m_filterDstPort;
171 WORD m_packetSrcPort;
172 WORD m_packetDstPort;
173
174 std::map<RTP_DataFrame::PayloadTypes, OpalMediaFormat> m_payloadType2mediaFormat;
175 };
176
177
178 #endif // PTLIB_PCAPFILE_H
179
180
181 // End Of File ///////////////////////////////////////////////////////////////