PcapPlusPlus  24.09
RawSocketDevice.h
Go to the documentation of this file.
1 #pragma once
2 
4 
5 #include "IpAddress.h"
6 #include "Device.h"
7 
12 namespace pcpp
13 {
40  class RawSocketDevice : public IDevice
41  {
42  public:
47  {
56  RecvError = 3
57  };
58 
59  /*
60  * A c'tor for this class. This c'tor doesn't create the raw socket, but rather initializes internal structures.
61  * The actual raw socket creation is done in the open() method. Each raw socket is bound to a network interface
62  * which means packets will be received and sent from only from this network interface only
63  * @param[in] interfaceIP The network interface IP to bind the raw socket to. It can be either an IPv4 or IPv6
64  * address (both are supported in raw sockets)
65  */
66  explicit RawSocketDevice(const IPAddress& interfaceIP);
67 
72 
99  RecvPacketResult receivePacket(RawPacket& rawPacket, bool blocking = true, double timeout = -1);
100 
111  int receivePackets(RawPacketVector& packetVec, double timeout, int& failedRecv);
112 
122  bool sendPacket(const RawPacket* rawPacket);
123 
133  int sendPackets(const RawPacketVector& packetVec);
134 
135  // overridden methods
136 
141  bool open() override;
142 
146  void close() override;
147 
148  private:
149  enum SocketFamily
150  {
151  Ethernet = 0,
152  IPv4 = 1,
153  IPv6 = 2
154  };
155 
156  SocketFamily m_SockFamily;
157  void* m_Socket;
158  IPAddress m_InterfaceIP;
159 
160  RecvPacketResult getError(int& errorCode) const;
161  };
162 } // namespace pcpp
Definition: Device.h:24
Definition: IpAddress.h:358
Definition: PointerVector.h:29
Definition: RawPacket.h:269
Definition: RawSocketDevice.h:41
RecvPacketResult
Definition: RawSocketDevice.h:47
@ RecvTimeout
Definition: RawSocketDevice.h:51
@ RecvWouldBlock
Definition: RawSocketDevice.h:54
@ RecvSuccess
Definition: RawSocketDevice.h:49
@ RecvError
Definition: RawSocketDevice.h:56
int receivePackets(RawPacketVector &packetVec, double timeout, int &failedRecv)
int sendPackets(const RawPacketVector &packetVec)
bool sendPacket(const RawPacket *rawPacket)
RecvPacketResult receivePacket(RawPacket &rawPacket, bool blocking=true, double timeout=-1)
void close() override
bool open() override
The main namespace for the PcapPlusPlus lib.