File tree Expand file tree Collapse file tree 9 files changed +52
-11
lines changed Expand file tree Collapse file tree 9 files changed +52
-11
lines changed Original file line number Diff line number Diff line change @@ -19,15 +19,11 @@ namespace pcpp
19
19
class IDevice
20
20
{
21
21
protected:
22
- bool m_DeviceOpened;
23
-
24
22
// c'tor should not be public
25
- IDevice () : m_DeviceOpened(false )
26
- {}
23
+ IDevice () = default ;
27
24
28
25
public:
29
- virtual ~IDevice ()
30
- {}
26
+ virtual ~IDevice () = default ;
31
27
32
28
// / Open the device
33
29
// / @return True if device was opened successfully, false otherwise
@@ -37,10 +33,7 @@ namespace pcpp
37
33
virtual void close () = 0;
38
34
39
35
// / @return True if the file is opened, false otherwise
40
- inline bool isOpened ()
41
- {
42
- return m_DeviceOpened;
43
- }
36
+ virtual bool isOpened () const = 0;
44
37
};
45
38
46
39
// / @class IFilterableDevice
Original file line number Diff line number Diff line change @@ -731,6 +731,11 @@ namespace pcpp
731
731
// / Close the DpdkDevice. When device is closed it's not possible work with it
732
732
void close () override ;
733
733
734
+ bool isOpened () const override
735
+ {
736
+ return m_DeviceOpened;
737
+ }
738
+
734
739
private:
735
740
struct DpdkCoreConfiguration
736
741
{
@@ -769,6 +774,8 @@ namespace pcpp
769
774
uint64_t convertRssHfToDpdkRssHf (uint64_t rssHF) const ;
770
775
uint64_t convertDpdkRssHfToRssHf (uint64_t dpdkRssHF) const ;
771
776
777
+ bool m_DeviceOpened = false ;
778
+
772
779
std::string m_DeviceName;
773
780
DpdkPMDType m_PMDType;
774
781
std::string m_PMDName;
Original file line number Diff line number Diff line change @@ -524,7 +524,14 @@ namespace pcpp
524
524
// / Stops asynchronous packet capture if it is running.
525
525
void close ();
526
526
527
+ bool isOpened () const override
528
+ {
529
+ return m_DeviceOpened;
530
+ }
531
+
527
532
private:
533
+ bool m_DeviceOpened = false ;
534
+
528
535
struct rte_kni * m_Device;
529
536
struct rte_mempool * m_MBufMempool;
530
537
struct KniDeviceInfo
Original file line number Diff line number Diff line change @@ -39,6 +39,7 @@ namespace pcpp
39
39
class IFileDevice : public IPcapDevice
40
40
{
41
41
protected:
42
+ bool m_DeviceOpened = false ;
42
43
std::string m_FileName;
43
44
44
45
explicit IFileDevice (const std::string& fileName);
@@ -53,6 +54,11 @@ namespace pcpp
53
54
// / Close the file
54
55
void close () override ;
55
56
57
+ bool isOpened () const override
58
+ {
59
+ return m_DeviceOpened;
60
+ }
61
+
56
62
// / @brief Get the statistics for this device.
57
63
// /
58
64
// / The PcapStats structure will hold the following:
Original file line number Diff line number Diff line change @@ -120,6 +120,8 @@ namespace pcpp
120
120
std::thread m_WorkerThread;
121
121
};
122
122
123
+ bool m_DeviceOpened = false ;
124
+
123
125
// This is a second descriptor for the same device. It is needed because of a bug
124
126
// that occurs in libpcap on Linux (on Windows using WinPcap/Npcap it works well):
125
127
// It's impossible to capture packets sent by the same descriptor
@@ -653,6 +655,11 @@ namespace pcpp
653
655
654
656
void close () override ;
655
657
658
+ bool isOpened () const override
659
+ {
660
+ return m_DeviceOpened;
661
+ }
662
+
656
663
// / Clones the current device class
657
664
// / @return Pointer to the copied class
658
665
virtual PcapLiveDevice* clone () const ;
Original file line number Diff line number Diff line change @@ -59,6 +59,8 @@ namespace pcpp
59
59
bool m_Ready = false ;
60
60
};
61
61
62
+ bool m_DeviceOpened = false ;
63
+
62
64
std::vector<pfring*> m_PfRingDescriptors;
63
65
std::string m_DeviceName;
64
66
int m_InterfaceIndex;
@@ -308,6 +310,11 @@ namespace pcpp
308
310
// / Closes all RX channels currently opened in device
309
311
void close ();
310
312
313
+ bool isOpened () const override
314
+ {
315
+ return m_DeviceOpened;
316
+ }
317
+
311
318
using IFilterableDevice::setFilter;
312
319
313
320
// / Sets a BPF filter to the device
Original file line number Diff line number Diff line change @@ -124,6 +124,11 @@ namespace pcpp
124
124
// / Close the raw socket
125
125
void close () override ;
126
126
127
+ bool isOpened () const override
128
+ {
129
+ return m_DeviceOpened;
130
+ }
131
+
127
132
private:
128
133
enum SocketFamily
129
134
{
@@ -132,6 +137,8 @@ namespace pcpp
132
137
IPv6 = 2
133
138
};
134
139
140
+ bool m_DeviceOpened = false ;
141
+
135
142
SocketFamily m_SockFamily;
136
143
void * m_Socket;
137
144
IPAddress m_InterfaceIP;
Original file line number Diff line number Diff line change @@ -179,6 +179,11 @@ namespace pcpp
179
179
// / Close the device. This method closes the AF_XDP socket and frees the UMEM that was allocated for it.
180
180
void close () override ;
181
181
182
+ bool isOpened () const override
183
+ {
184
+ return m_DeviceOpened;
185
+ }
186
+
182
187
// / Start receiving packets. In order to use this method the device should be open. Note that this method is
183
188
// / blocking and will return if:
184
189
// / - stopReceivePackets() was called from within the user callback
@@ -285,6 +290,8 @@ namespace pcpp
285
290
uint64_t txCompletedPackets;
286
291
};
287
292
293
+ bool m_DeviceOpened = false ;
294
+
288
295
std::string m_InterfaceName;
289
296
XdpDeviceConfiguration* m_Config;
290
297
bool m_ReceivingPackets;
Original file line number Diff line number Diff line change @@ -136,7 +136,7 @@ namespace pcpp
136
136
bool IPcapDevice::setFilter (std::string filterAsString)
137
137
{
138
138
PCPP_LOG_DEBUG (" Filter to be set: '" << filterAsString << " '" );
139
- if (!m_DeviceOpened )
139
+ if (!isOpened () )
140
140
{
141
141
PCPP_LOG_ERROR (" Device not Opened!! cannot set filter" );
142
142
return false ;
You can’t perform that action at this time.
0 commit comments