Repo-Init
 
Loading...
Searching...
No Matches
RawSocket.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <string>
4
5#include <linux/if_packet.h>
6
12 size_t sentBytes;
17};
18
23class RawSocket {
24 private:
26 bool _isReady{false};
28 bool _writeMode{false};
30 int _sockFd{-1};
32 std::string _iFace;
34 sockaddr_ll _addr{};
37
38 void init(int domain, int type, int protocol);
39
40 public:
46 explicit RawSocket(std::string iface, bool isWrite = false);
47
49 RawSocket(const RawSocket & /*unused*/) = delete;
50
52 RawSocket(RawSocket && /*unused*/) = delete;
53
55 RawSocket &operator=(RawSocket /*unused*/) = delete;
56
58 RawSocket &operator=(RawSocket && /*unused*/) = delete;
59
64 [[nodiscard]] const std::string &getInterfaceName() const { return _iFace; }
65
72 int writeData(const unsigned char *data, size_t dataLen);
73
80 int readData(unsigned char *data, size_t dataLen);
81
87 RawSocketStats getStats(bool resetInternalStats = false);
88
92 ~RawSocket();
93};
int _sockFd
Socket descriptor.
Definition RawSocket.hpp:30
RawSocket(std::string iface, bool isWrite=false)
Definition RawSocket.cpp:30
bool _writeMode
Mode indicator. True = Write, False = Read.
Definition RawSocket.hpp:28
RawSocket & operator=(RawSocket)=delete
Copy assignment operator.
RawSocketStats _stats
Internal structure for statistics.
Definition RawSocket.hpp:36
RawSocketStats getStats(bool resetInternalStats=false)
bool _isReady
Ready flag.
Definition RawSocket.hpp:26
RawSocket(RawSocket &&)=delete
Move constructor.
void init(int domain, int type, int protocol)
Definition RawSocket.cpp:17
const std::string & getInterfaceName() const
Definition RawSocket.hpp:64
RawSocket & operator=(RawSocket &&)=delete
Move assignment operator.
std::string _iFace
Currently used ethernet interface.
Definition RawSocket.hpp:32
int readData(unsigned char *data, size_t dataLen)
Definition RawSocket.cpp:80
int writeData(const unsigned char *data, size_t dataLen)
Definition RawSocket.cpp:63
sockaddr_ll _addr
Socket structure.
Definition RawSocket.hpp:34
RawSocket(const RawSocket &)=delete
Copy constructor.
size_t receivedBytes
Number of bytes read from socket.
Definition RawSocket.hpp:14
size_t sentBytes
Number of bytes written to socket.
Definition RawSocket.hpp:12
double processingTime
Total execution time in nanoseconds.
Definition RawSocket.hpp:16