PcapPlusPlus  21.11
RawSocketDevice.h
Go to the documentation of this file.
1 #ifndef PCAPPP_RAW_SOCKET_DEVICE
2 #define PCAPPP_RAW_SOCKET_DEVICE
3 
5 
6 #include "IpAddress.h"
7 #include "Device.h"
8 
13 namespace pcpp
14 {
40  class RawSocketDevice : public IDevice
41  {
42  public:
43 
48  {
57  };
58 
59  /*
60  * A c'tor for this class. This c'tor doesn't create the raw socket, but rather initializes internal structures. The actual
61  * raw socket creation is done in the open() method. Each raw socket is bound to a network interface which means
62  * 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 address
64  * (both are supported in raw sockets)
65  */
66  RawSocketDevice(const IPAddress& interfaceIP);
67 
72 
98  RecvPacketResult receivePacket(RawPacket& rawPacket, bool blocking = true, int timeout = -1);
99 
109  int receivePackets(RawPacketVector& packetVec, int timeout, int& failedRecv);
110 
120  bool sendPacket(const RawPacket* rawPacket);
121 
131  int sendPackets(const RawPacketVector& packetVec);
132 
133  // overridden methods
134 
139  virtual bool open();
140 
144  virtual void close();
145 
146  private:
147 
148  enum SocketFamily
149  {
150  Ethernet = 0,
151  IPv4 = 1,
152  IPv6 = 2
153  };
154 
155  SocketFamily m_SockFamily;
156  void* m_Socket;
157  IPAddress m_InterfaceIP;
158 
159  RecvPacketResult getError(int& errorCode) const;
160 
161  };
162 }
163 
164 #endif // PCAPPP_RAW_SOCKET_DEVICE
The main namespace for the PcapPlusPlus lib.
virtual void close()
Definition: RawSocketDevice.h:50
virtual bool open()
Definition: RawSocketDevice.h:56
Definition: RawSocketDevice.h:54
Definition: PointerVector.h:24
Definition: RawPacket.h:252
Definition: Device.h:24
RecvPacketResult receivePacket(RawPacket &rawPacket, bool blocking=true, int timeout=-1)
RecvPacketResult
Definition: RawSocketDevice.h:47
Definition: RawSocketDevice.h:40
bool sendPacket(const RawPacket *rawPacket)
Definition: RawSocketDevice.h:52
int sendPackets(const RawPacketVector &packetVec)
Definition: IpAddress.h:278
int receivePackets(RawPacketVector &packetVec, int timeout, int &failedRecv)