PcapPlusPlus  19.12
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
pcpp::RawSocketDevice::RecvError
Definition: RawSocketDevice.h:56
pcpp::RawSocketDevice::RecvPacketResult
RecvPacketResult
Definition: RawSocketDevice.h:47
pcpp::RawSocketDevice::sendPacket
bool sendPacket(const RawPacket *rawPacket)
pcpp::RawSocketDevice::~RawSocketDevice
~RawSocketDevice()
pcpp::IPAddress
Definition: IpAddress.h:28
pcpp::RawSocketDevice::RecvWouldBlock
Definition: RawSocketDevice.h:54
pcpp::RawSocketDevice::open
virtual bool open()
Device.h
pcpp::RawSocketDevice::receivePacket
RecvPacketResult receivePacket(RawPacket &rawPacket, bool blocking=true, int timeout=-1)
IpAddress.h
pcpp::RawSocketDevice::RecvTimeout
Definition: RawSocketDevice.h:52
pcpp
The main namespace for the PcapPlusPlus lib.
pcpp::RawSocketDevice::close
virtual void close()
pcpp::RawSocketDevice::receivePackets
int receivePackets(RawPacketVector &packetVec, int timeout, int &failedRecv)
pcpp::RawSocketDevice
Definition: RawSocketDevice.h:40
pcpp::RawSocketDevice::RecvSuccess
Definition: RawSocketDevice.h:50
pcpp::PointerVector
Definition: PointerVector.h:24
pcpp::RawSocketDevice::sendPackets
int sendPackets(const RawPacketVector &packetVec)
pcpp::IDevice
Definition: Device.h:24
pcpp::RawPacket
Definition: RawPacket.h:219