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
pcapReader::buffer_t
std::vector< uint8_t > buffer_t
Definition: pcap_reader.hpp:49
pcapReader::PcapDevice::PcapDevice
PcapDevice(ROSaicNodeBase *node, buffer_t &buffer)
Constructor for PcapDevice.
Definition: pcap_reader.cpp:53
pcapReader::PcapDevice::m_errBuff
char m_errBuff[BUFFSIZE]
Definition: pcap_reader.hpp:115
pcapReader::READ_PARSE_FAILED
@ READ_PARSE_FAILED
Unable to parse data, parsing error.
Definition: pcap_reader.hpp:61
pcapReader::PcapDevice::disconnect
void disconnect()
Close connected file.
Definition: pcap_reader.cpp:78
pcapReader::PcapDevice::m_lastPkt
buffer_t m_lastPkt
Definition: pcap_reader.hpp:117
pcapReader::PcapDevice::isConnected
bool isConnected() const
Check if file is open and healthy.
Definition: pcap_reader.cpp:88
ROSaicNodeBase
This class is the base class for abstraction.
Definition: typedefs.hpp:174
pcapReader::PcapDevice::~PcapDevice
~PcapDevice()
Destructor for PcapDevice.
Definition: pcap_reader.cpp:58
pcapReader
Definition: pcap_reader.hpp:47
pcapReader::ReadResult
ReadResult
Read operation status.
Definition: pcap_reader.hpp:52
pcapReader::PcapDevice::m_pktFilter
bpf_program m_pktFilter
Definition: pcap_reader.hpp:114
pcapReader::READ_SUCCESS
@ READ_SUCCESS
Data read successfully.
Definition: pcap_reader.hpp:55
pcapReader::READ_INTERRUPTED
@ READ_INTERRUPTED
Definition: pcap_reader.hpp:58
typedefs.hpp
pcapReader::READ_ERROR
@ READ_ERROR
Definition: pcap_reader.hpp:59
pcapReader::PcapDevice::read
ReadResult read()
Attempt to read a packet and store data to buffer.
Definition: pcap_reader.cpp:90
pcapReader::PcapDevice::m_dataBuff
buffer_t & m_dataBuff
Reference to raw data buffer to write to.
Definition: pcap_reader.hpp:111
pcapReader::PcapDevice::m_deviceName
char * m_deviceName
Definition: pcap_reader.hpp:116
pcapReader::PcapDevice::node_
ROSaicNodeBase * node_
Pointer to the node.
Definition: pcap_reader.hpp:109
pcapReader::READ_TIMEOUT
@ READ_TIMEOUT
Definition: pcap_reader.hpp:57
pcapReader::READ_INSUFFICIENT_DATA
@ READ_INSUFFICIENT_DATA
Definition: pcap_reader.hpp:56
pcapReader::PcapDevice::m_device
pcap_t * m_device
File handle to pcap file.
Definition: pcap_reader.hpp:113
pcapReader::PcapDevice::connect
bool connect(const char *device)
Try to open a pcap file.
Definition: pcap_reader.cpp:60
pcapReader::PcapDevice
Class for handling a pcap file.
Definition: pcap_reader.hpp:69
pcapReader::PcapDevice::BUFFSIZE
static const size_t BUFFSIZE
Definition: pcap_reader.hpp:72


septentrio_gnss_driver
Author(s): Tibor Dome
autogenerated on Fri Mar 10 2023 04:02:30