pcap_reader.hpp
Go to the documentation of this file.
1 // *****************************************************************************
2 //
3 // © Copyright 2020, Septentrio NV/SA.
4 // All rights reserved.
5 //
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions are met:
8 // 1. Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // 2. Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // 3. Neither the name of the copyright holder nor the names of its
14 // contributors may be used to endorse or promote products derived
15 // from this software without specific prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 // POSSIBILITY OF SUCH DAMAGE.
28 //
29 // *****************************************************************************
30 
31 #ifndef PCAP_READER_H
32 #define PCAP_READER_H
33 
34 #include <cstdint>
35 #include <pcap/pcap.h>
37 #include <vector>
38 
47 namespace pcapReader {
48 
49  using buffer_t = std::vector<uint8_t>;
50 
53  {
59  READ_ERROR = -1,
62 
63  };
64 
69  class PcapDevice
70  {
71  public:
72  static const size_t BUFFSIZE = 100;
73 
78  explicit PcapDevice(ROSaicNodeBase* node, buffer_t& buffer);
79 
85  bool connect(const char* device);
86 
90  void disconnect();
91 
96  bool isConnected() const;
97 
102  ReadResult read();
103 
105  ~PcapDevice();
106 
107  private:
113  pcap_t* m_device{nullptr};
114  bpf_program m_pktFilter{};
118  };
119 } // namespace pcapReader
120 
121 #endif // PCAP_READER_H
ReadResult read()
Attempt to read a packet and store data to buffer.
Definition: pcap_reader.cpp:90
Unable to parse data, parsing error.
Definition: pcap_reader.hpp:61
std::vector< uint8_t > buffer_t
Definition: pcap_reader.hpp:49
~PcapDevice()
Destructor for PcapDevice.
Definition: pcap_reader.cpp:58
void disconnect()
Close connected file.
Definition: pcap_reader.cpp:78
bool isConnected() const
Check if file is open and healthy.
Definition: pcap_reader.cpp:88
bool connect(const char *device)
Try to open a pcap file.
Definition: pcap_reader.cpp:60
Data read successfully.
Definition: pcap_reader.hpp:55
static const size_t BUFFSIZE
Definition: pcap_reader.hpp:72
char m_errBuff[BUFFSIZE]
ROSaicNodeBase * node_
Pointer to the node.
Class for handling a pcap file.
Definition: pcap_reader.hpp:69
ReadResult
Read operation status.
Definition: pcap_reader.hpp:52
buffer_t & m_dataBuff
Reference to raw data buffer to write to.
This class is the base class for abstraction.
Definition: typedefs.hpp:174
PcapDevice(ROSaicNodeBase *node, buffer_t &buffer)
Constructor for PcapDevice.
Definition: pcap_reader.cpp:53
pcap_t * m_device
File handle to pcap file.


septentrio_gnss_driver
Author(s): Tibor Dome
autogenerated on Sat Mar 11 2023 03:12:55