libpromeki main
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
rawsocket.h
Go to the documentation of this file.
1
8#pragma once
9
11
13
37class RawSocket : public AbstractSocket {
38 PROMEKI_OBJECT(RawSocket, AbstractSocket)
39 public:
45
47 ~RawSocket() override;
48
56 void setInterface(const String &interfaceName) { _interface = interfaceName; }
57
59 const String &interface() const { return _interface; }
60
73 void setProtocol(uint16_t ethertype) { _protocol = ethertype; }
74
76 uint16_t protocol() const { return _protocol; }
77
88 Error open(OpenMode mode) override;
89
94 Error close() override;
95
97 bool isOpen() const override { return _fd >= 0; }
98
105 int64_t read(void *data, int64_t maxSize) override;
106
113 int64_t write(const void *data, int64_t maxSize) override;
114
121
122 private:
123 String _interface;
124 uint16_t _protocol = 0;
125};
126
Abstract base class for network sockets.
Definition abstractsocket.h:38
int _fd
Socket file descriptor.
Definition abstractsocket.h:203
Lightweight error code wrapper for the promeki library.
Definition error.h:39
OpenMode
Mode flags controlling how a device is opened.
Definition iodevice.h:33
Dynamic array container wrapping std::vector.
Definition list.h:40
Base object for promeki.
Definition objectbase.h:129
ObjectBase * parent() const
Returns the parent object, if one. nullptr if none.
Definition objectbase.h:258
Raw Ethernet frame socket.
Definition rawsocket.h:37
Error close() override
Closes the socket.
int64_t read(void *data, int64_t maxSize) override
Reads a raw Ethernet frame.
void setProtocol(uint16_t ethertype)
Sets the Ethernet protocol filter.
Definition rawsocket.h:73
void setInterface(const String &interfaceName)
Sets the network interface to bind to.
Definition rawsocket.h:56
bool isOpen() const override
Returns true if the socket is open.
Definition rawsocket.h:97
Error open(OpenMode mode) override
Opens the raw socket.
const String & interface() const
Returns the configured interface name.
Definition rawsocket.h:59
RawSocket(ObjectBase *parent=nullptr)
Constructs a RawSocket.
~RawSocket() override
Destructor.
int64_t write(const void *data, int64_t maxSize) override
Writes a raw Ethernet frame.
Error setPromiscuous(bool enable)
Enables or disables promiscuous mode.
uint16_t protocol() const
Returns the configured protocol filter.
Definition rawsocket.h:76
Encoding-aware string class with copy-on-write semantics.
Definition string.h:35
#define PROMEKI_NAMESPACE_BEGIN
Starts a promeki namespace block.
Definition namespace.h:14
#define PROMEKI_NAMESPACE_END
Ends a promeki namespace block.
Definition namespace.h:19