PcapPlusPlus  Next
RawSocketDevice.h
Go to the documentation of this file.
1 #pragma once
2 
4 
5 #include "IpAddress.h"
6 #include "Device.h"
7 
10 namespace pcpp
11 {
37  class RawSocketDevice : public IDevice
38  {
39  public:
42  {
51  RecvError = 3
52  };
53 
59  explicit RawSocketDevice(const IPAddress& interfaceIP);
60 
63 
88  RecvPacketResult receivePacket(RawPacket& rawPacket, bool blocking = true, double timeout = -1);
89 
98  int receivePackets(RawPacketVector& packetVec, double timeout, int& failedRecv);
99 
107  bool sendPacket(const RawPacket* rawPacket);
108 
116  int sendPackets(const RawPacketVector& packetVec);
117 
118  // overridden methods
119 
122  bool open() override;
123 
125  void close() override;
126 
127  private:
128  enum SocketFamily
129  {
130  Ethernet = 0,
131  IPv4 = 1,
132  IPv6 = 2
133  };
134 
135  SocketFamily m_SockFamily;
136  void* m_Socket;
137  IPAddress m_InterfaceIP;
138 
139  RecvPacketResult getError(int& errorCode) const;
140  };
141 } // namespace pcpp
Definition: Device.h:20
Definition: IpAddress.h:276
Definition: PointerVector.h:50
Definition: RawPacket.h:269
Definition: RawSocketDevice.h:38
RecvPacketResult
An enum for reporting packet receive results.
Definition: RawSocketDevice.h:42
@ RecvTimeout
Receive timeout - timeout expired without any packets being captured.
Definition: RawSocketDevice.h:46
@ RecvWouldBlock
Definition: RawSocketDevice.h:49
@ RecvSuccess
Receive success.
Definition: RawSocketDevice.h:44
@ RecvError
Receive error, usually will be followed by an error log.
Definition: RawSocketDevice.h:51
int receivePackets(RawPacketVector &packetVec, double timeout, int &failedRecv)
~RawSocketDevice()
A d'tor for this class. It closes the raw socket if not previously closed by calling close()
int sendPackets(const RawPacketVector &packetVec)
bool sendPacket(const RawPacket *rawPacket)
RecvPacketResult receivePacket(RawPacket &rawPacket, bool blocking=true, double timeout=-1)
RawSocketDevice(const IPAddress &interfaceIP)
void close() override
Close the raw socket.
bool open() override
The main namespace for the PcapPlusPlus lib.